|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types = 1); |
| 4 | + |
| 5 | +namespace OpenSslEncrypt; |
| 6 | + |
| 7 | +use function PHPStan\Testing\assertType; |
| 8 | + |
| 9 | +class Foo |
| 10 | +{ |
| 11 | + public function testStringCipher(string $cipher): void |
| 12 | + { |
| 13 | + openssl_encrypt('data', $cipher, random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 14 | + assertType('non-empty-string|null', $tag); |
| 15 | + } |
| 16 | + |
| 17 | + public function testUnknownCipher(): void |
| 18 | + { |
| 19 | + openssl_encrypt('data', 'aes-256-cde', random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 20 | + assertType('null', $tag); |
| 21 | + |
| 22 | + openssl_encrypt('data', 'abc-256-gcm', random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 23 | + assertType('null', $tag); |
| 24 | + |
| 25 | + openssl_encrypt('data', 'abc-256-ccm', random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 26 | + assertType('null', $tag); |
| 27 | + } |
| 28 | + |
| 29 | + public function testAeadCipher(): void |
| 30 | + { |
| 31 | + $cipher = 'aes-256-gcm'; |
| 32 | + openssl_encrypt('data', $cipher, random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 33 | + assertType('non-empty-string', $tag); |
| 34 | + |
| 35 | + $cipher = 'aes-256-ccm'; |
| 36 | + openssl_encrypt('data', $cipher, random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 37 | + assertType('non-empty-string', $tag); |
| 38 | + } |
| 39 | + |
| 40 | + public function testNonAeadCipher(): void |
| 41 | + { |
| 42 | + $cipher = 'aes-256-cbc'; |
| 43 | + openssl_encrypt('data', $cipher, random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 44 | + assertType('null', $tag); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @param 'aes-256-ctr'|'aes-256-gcm' $cipher |
| 49 | + */ |
| 50 | + public function testMixedAeadAndNonAeadCiphers(string $cipher): void |
| 51 | + { |
| 52 | + openssl_encrypt('data', $cipher, random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 53 | + assertType('non-empty-string|null', $tag); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @param 'aes-256-cbc'|'aes-256-ctr' $cipher |
| 58 | + */ |
| 59 | + public function testMixedTwoNonAeadCiphers(string $cipher): void |
| 60 | + { |
| 61 | + openssl_encrypt('data', $cipher, random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 62 | + assertType('null', $tag); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @param 'aes-256-gcm'|'aes-256-ccm' $cipher |
| 67 | + */ |
| 68 | + public function testMixedTwoAeadCiphers(string $cipher): void |
| 69 | + { |
| 70 | + openssl_encrypt('data', $cipher, random_bytes(32), OPENSSL_RAW_DATA, random_bytes(16), $tag); |
| 71 | + assertType('non-empty-string', $tag); |
| 72 | + } |
| 73 | +} |
0 commit comments