| Conditions | 5 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | public function loadKey($type) |
||
| 27 | { |
||
| 28 | $path = $this->getKeyPath($type); |
||
| 29 | $encryptedKey = file_get_contents($path); |
||
| 30 | $key = call_user_func_array( |
||
| 31 | sprintf('openssl_pkey_get_%s', $type), |
||
| 32 | self::TYPE_PRIVATE == $type ? [$encryptedKey, $this->getPassPhrase()] : [$encryptedKey] |
||
| 33 | ); |
||
| 34 | if (!$key) { |
||
| 35 | $sslError = ''; |
||
| 36 | while ($msg = trim(openssl_error_string(), " \n\r\t\0\x0B\"")) { |
||
| 37 | if ('error:' === substr($msg, 0, 6)) { |
||
| 38 | $msg = substr($msg, 6); |
||
| 39 | } |
||
| 40 | $sslError .= "\n ".$msg; |
||
| 41 | } |
||
| 42 | |||
| 43 | throw new \RuntimeException( |
||
| 44 | sprintf('Failed to load %s key "%s": %s', $type, $path, $sslError) |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $key; |
||
| 49 | } |
||
| 51 |