| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\CryptoBridge; |
| 6 |
|
| 7 |
use function defined; |
| 8 |
use RuntimeException; |
| 9 |
use SpomkyLabs\Pki\CryptoBridge\Crypto\OpenSSLCrypto; |
| 10 |
use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Cipher\CipherAlgorithmIdentifier; |
| 11 |
use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Feature\SignatureAlgorithmIdentifier; |
| 12 |
use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PrivateKeyInfo; |
| 13 |
use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PublicKeyInfo; |
| 14 |
use SpomkyLabs\Pki\CryptoTypes\Signature\Signature; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
abstract class Crypto |
| 20 |
{ |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
abstract public function sign( |
| 29 |
string $data, |
| 30 |
PrivateKeyInfo $privkey_info, |
| 31 |
SignatureAlgorithmIdentifier $algo |
| 32 |
): Signature; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
abstract public function verify( |
| 45 |
string $data, |
| 46 |
Signature $signature, |
| 47 |
PublicKeyInfo $pubkey_info, |
| 48 |
SignatureAlgorithmIdentifier $algo |
| 49 |
): bool; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
abstract public function encrypt(string $data, string $key, CipherAlgorithmIdentifier $algo): string; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
abstract public function decrypt(string $data, string $key, CipherAlgorithmIdentifier $algo): string; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public static function getDefault(): self |
| 82 |
{ |
| 83 |
if (defined('OPENSSL_VERSION_NUMBER')) { |
| 84 |
return new OpenSSLCrypto(); |
| 85 |
} |
| 86 |
|
| 87 |
throw new RuntimeException('No crypto implementation available.'); |
| 88 |
|
| 89 |
} |
| 90 |
} |