@@ -46,9 +46,9 @@ |
||
46 | 46 | * |
47 | 47 | * @throws \chillerlan\Traits\Crypto\CryptoException |
48 | 48 | */ |
49 | - public function __construct(array $properties = null){ |
|
49 | + public function __construct(array $properties = null) { |
|
50 | 50 | |
51 | - if(!extension_loaded('sodium') || !function_exists('sodium_memzero')){ |
|
51 | + if (!extension_loaded('sodium') || !function_exists('sodium_memzero')) { |
|
52 | 52 | throw new CryptoException('sodium extension (PHP 7.2+) required!'); // @codeCoverageIgnore |
53 | 53 | } |
54 | 54 |
@@ -12,12 +12,12 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Traits\Crypto; |
14 | 14 | |
15 | -class BoxKeypair extends CryptoKeypair{ |
|
15 | +class BoxKeypair extends CryptoKeypair { |
|
16 | 16 | |
17 | 17 | /** @inheritdoc */ |
18 | 18 | public function create(string $seed_bin = null):CryptoKeyInterface{ |
19 | 19 | |
20 | - if($seed_bin !== null && strlen($seed_bin) !== SODIUM_CRYPTO_BOX_SEEDBYTES){ |
|
20 | + if ($seed_bin !== null && strlen($seed_bin) !== SODIUM_CRYPTO_BOX_SEEDBYTES) { |
|
21 | 21 | throw new CryptoException('invalid seed length'); |
22 | 22 | } |
23 | 23 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | sodium_memzero($keypair); |
33 | 33 | |
34 | - if($seed_bin !== null){ |
|
34 | + if ($seed_bin !== null) { |
|
35 | 35 | sodium_memzero($seed_bin); |
36 | 36 | } |
37 | 37 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function createFromSecret(string $secret_bin):CryptoKeyInterface{ |
48 | 48 | |
49 | - if(strlen($secret_bin) !== SODIUM_CRYPTO_BOX_SECRETKEYBYTES){ |
|
49 | + if (strlen($secret_bin) !== SODIUM_CRYPTO_BOX_SECRETKEYBYTES) { |
|
50 | 50 | throw new CryptoException('invalid secret key length'); |
51 | 51 | } |
52 | 52 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Traits\Crypto; |
14 | 14 | |
15 | -class SignedMessage extends CryptoBox{ |
|
15 | +class SignedMessage extends CryptoBox { |
|
16 | 16 | |
17 | 17 | public function create(string $message):CryptoBoxInterface{ |
18 | 18 | $this->checkKeypair(SODIUM_CRYPTO_SIGN_SECRETKEYBYTES); |
@@ -20,7 +20,7 @@ |
||
20 | 20 | * |
21 | 21 | * @method \chillerlan\Traits\Crypto\CryptoBoxInterface open(string $box_bin, string $nonce_bin) |
22 | 22 | */ |
23 | -interface CryptoBoxInterface{ |
|
23 | +interface CryptoBoxInterface { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @param string $message |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\Traits\TraitException; |
16 | 16 | |
17 | -class CryptoException extends TraitException{} |
|
17 | +class CryptoException extends TraitException {} |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | namespace chillerlan\Traits\Crypto; |
14 | 14 | |
15 | 15 | |
16 | -class Box extends CryptoBox{ |
|
16 | +class Box extends CryptoBox { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param string $message |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | sodium_memzero($keypair); |
35 | 35 | sodium_memzero($message); |
36 | 36 | |
37 | - if($nonce_bin !== null){ |
|
37 | + if ($nonce_bin !== null) { |
|
38 | 38 | sodium_memzero($nonce_bin); |
39 | 39 | } |
40 | 40 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | sodium_memzero($box_bin); |
53 | 53 | sodium_memzero($nonce_bin); |
54 | 54 | |
55 | - if($this->message === false){ |
|
55 | + if ($this->message === false) { |
|
56 | 56 | throw new CryptoException('invalid box'); |
57 | 57 | } |
58 | 58 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Traits\Crypto; |
14 | 14 | |
15 | -class SecretBox extends CryptoBox{ |
|
15 | +class SecretBox extends CryptoBox { |
|
16 | 16 | |
17 | 17 | public function create(string $message, string $nonce_bin = null):CryptoBoxInterface{ |
18 | 18 | $this->checkKeypair(SODIUM_CRYPTO_BOX_SECRETKEYBYTES); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | sodium_memzero($message); |
25 | 25 | |
26 | - if($nonce_bin !== null){ |
|
26 | + if ($nonce_bin !== null) { |
|
27 | 27 | sodium_memzero($nonce_bin); |
28 | 28 | } |
29 | 29 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | $this->message = sodium_crypto_secretbox_open($box_bin, $nonce_bin, $this->keypair->secret); |
37 | 37 | |
38 | - if($this->message === false){ |
|
38 | + if ($this->message === false) { |
|
39 | 39 | throw new CryptoException('invalid box'); |
40 | 40 | } |
41 | 41 |
@@ -12,17 +12,17 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Traits\Crypto; |
14 | 14 | |
15 | -trait MemzeroDestructorTrait{ |
|
15 | +trait MemzeroDestructorTrait { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @return void |
19 | 19 | */ |
20 | - public function __destruct(){ |
|
20 | + public function __destruct() { |
|
21 | 21 | |
22 | - foreach(array_keys(get_object_vars($this)) as $key){ |
|
22 | + foreach (array_keys(get_object_vars($this)) as $key) { |
|
23 | 23 | |
24 | - if(is_scalar($this->{$key})){ |
|
25 | - $this->{$key} = (string)$this->{$key}; |
|
24 | + if (is_scalar($this->{$key})) { |
|
25 | + $this->{$key} = (string) $this->{$key}; |
|
26 | 26 | |
27 | 27 | sodium_memzero($this->{$key}); |
28 | 28 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Traits\Crypto; |
14 | 14 | |
15 | -class SealedBox extends CryptoBox{ |
|
15 | +class SealedBox extends CryptoBox { |
|
16 | 16 | |
17 | 17 | public function create(string $message):CryptoBoxInterface{ |
18 | 18 | $this->checkKeypair(null, SODIUM_CRYPTO_BOX_PUBLICKEYBYTES); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | sodium_memzero($keypair); |
34 | 34 | sodium_memzero($box_bin); |
35 | 35 | |
36 | - if($this->message === false){ |
|
36 | + if ($this->message === false) { |
|
37 | 37 | throw new CryptoException('invalid box'); |
38 | 38 | } |
39 | 39 |