| Conditions | 5 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | public function create(string $seed_bin = null):CryptoKeyInterface{ |
||
| 19 | |||
| 20 | if($seed_bin !== null && strlen($seed_bin) !== SODIUM_CRYPTO_SIGN_SEEDBYTES){ |
||
| 21 | throw new CryptoException('invalid seed length'); |
||
| 22 | } |
||
| 23 | |||
| 24 | $keypair = $seed_bin |
||
| 25 | ? sodium_crypto_sign_seed_keypair($seed_bin) |
||
| 26 | : sodium_crypto_sign_keypair(); |
||
| 27 | |||
| 28 | $this->keypair = $keypair; |
||
| 29 | $this->secret = sodium_crypto_sign_secretkey($keypair); |
||
| 30 | $this->public = sodium_crypto_sign_publickey($keypair); |
||
| 31 | |||
| 32 | sodium_memzero($keypair); |
||
| 33 | |||
| 34 | if($seed_bin !== null){ |
||
| 35 | sodium_memzero($seed_bin); |
||
| 36 | } |
||
| 37 | |||
| 38 | return $this; |
||
| 39 | } |
||
| 42 |