| Conditions | 1 |
| Paths | 1 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 41 | public static function sign(string $digest, string $pemFile): string |
||
| 42 | { |
||
| 43 | $filename = function ($resource): string { |
||
| 44 | return stream_get_meta_data($resource)['uri']; |
||
| 45 | }; |
||
| 46 | |||
| 47 | fwrite($_ = tmpfile(), $digest); |
||
| 48 | |||
| 49 | static $smime = <<<'CMD' |
||
| 50 | openssl smime -sign -signer %signer% -engine gost -gost89 -binary -noattr -nocerts -outform DER -in %in% -out %out% |
||
| 51 | CMD; |
||
| 52 | shell_exec(interpolate($smime, [ |
||
| 53 | 'in' => $filename($_), |
||
| 54 | 'out' => $filename($__ = tmpfile()), |
||
| 55 | 'signer' => $pemFile, |
||
| 56 | ])); |
||
| 57 | |||
| 58 | $output = shell_exec('openssl asn1parse -inform DER -in ' . $filename($__)); |
||
| 59 | |||
| 60 | return hex2bin(trim(substr($output, -129))); |
||
| 61 | } |
||
| 62 | } |
||
| 63 |