MCPcopy Create free account
hub / github.com/error311/FileRise / getMasterKeyOrNull

Method getMasterKeyOrNull

src/FileRise/Support/CryptoAtRest.php:112–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

110 }
111
112 public static function getMasterKeyOrNull(): ?string
113 {
114 if (!self::isAvailable()) {
115 return null;
116 }
117 if (self::$cachedKey !== null) {
118 return self::$cachedKey;
119 }
120
121 $env = getenv('FR_ENCRYPTION_MASTER_KEY');
122 if (is_string($env) && $env !== '') {
123 $k = self::parseKeyString($env);
124 if ($k !== null) {
125 self::$cachedKey = $k;
126 return $k;
127 }
128 }
129
130 $kf = self::keyFilePath();
131 if (is_file($kf)) {
132 $bin = @file_get_contents($kf);
133 if (is_string($bin) && strlen($bin) === SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES) {
134 self::$cachedKey = $bin;
135 return $bin;
136 }
137 }
138
139 return null;
140 }
141
142 public static function requireMasterKey(): string
143 {

Callers 2

masterKeyIsConfiguredMethod · 0.95
requireMasterKeyMethod · 0.95

Calls 3

isAvailableMethod · 0.95
parseKeyStringMethod · 0.95
keyFilePathMethod · 0.95

Tested by

no test coverage detected