Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/keyring/PhabricatorKeyring.php
12241 views
1
<?php
2
3
final class PhabricatorKeyring extends Phobject {
4
5
private static $hasReadConfiguration;
6
private static $keyRing = array();
7
8
public static function addKey($spec) {
9
self::$keyRing[$spec['name']] = $spec;
10
}
11
12
public static function getKey($name, $type) {
13
self::readConfiguration();
14
15
if (empty(self::$keyRing[$name])) {
16
throw new Exception(
17
pht(
18
'No key "%s" exists in keyring.',
19
$name));
20
}
21
22
$spec = self::$keyRing[$name];
23
24
$material = base64_decode($spec['material.base64'], true);
25
return new PhutilOpaqueEnvelope($material);
26
}
27
28
public static function getDefaultKeyName($type) {
29
self::readConfiguration();
30
31
foreach (self::$keyRing as $name => $key) {
32
if (!empty($key['default'])) {
33
return $name;
34
}
35
}
36
37
return null;
38
}
39
40
private static function readConfiguration() {
41
if (self::$hasReadConfiguration) {
42
return true;
43
}
44
45
self::$hasReadConfiguration = true;
46
47
foreach (PhabricatorEnv::getEnvConfig('keyring') as $spec) {
48
self::addKey($spec);
49
}
50
}
51
52
}
53
54