Remove product literal strings in "pht()", part 5
[phabricator.git] / src / applications / files / keyring / PhabricatorKeyring.php
blob1772c145c2fc2350fe77c5265c3a5ad7a676b7e9
1 <?php
3 final class PhabricatorKeyring extends Phobject {
5 private static $hasReadConfiguration;
6 private static $keyRing = array();
8 public static function addKey($spec) {
9 self::$keyRing[$spec['name']] = $spec;
12 public static function getKey($name, $type) {
13 self::readConfiguration();
15 if (empty(self::$keyRing[$name])) {
16 throw new Exception(
17 pht(
18 'No key "%s" exists in keyring.',
19 $name));
22 $spec = self::$keyRing[$name];
24 $material = base64_decode($spec['material.base64'], true);
25 return new PhutilOpaqueEnvelope($material);
28 public static function getDefaultKeyName($type) {
29 self::readConfiguration();
31 foreach (self::$keyRing as $name => $key) {
32 if (!empty($key['default'])) {
33 return $name;
37 return null;
40 private static function readConfiguration() {
41 if (self::$hasReadConfiguration) {
42 return true;
45 self::$hasReadConfiguration = true;
47 foreach (PhabricatorEnv::getEnvConfig('keyring') as $spec) {
48 self::addKey($spec);