GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Crypto   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 70
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDefault() 0 7 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\CryptoBridge;
6
7
use Sop\CryptoTypes\AlgorithmIdentifier\Cipher\CipherAlgorithmIdentifier;
8
use Sop\CryptoTypes\AlgorithmIdentifier\Feature\SignatureAlgorithmIdentifier;
9
use Sop\CryptoTypes\Asymmetric\PrivateKeyInfo;
10
use Sop\CryptoTypes\Asymmetric\PublicKeyInfo;
11
use Sop\CryptoTypes\Signature\Signature;
12
13
/**
14
 * Base class for crypto engine implementations.
15
 */
16
abstract class Crypto
17
{
18
    /**
19
     * Sign data with given algorithm using given private key.
20
     *
21
     * @param string                       $data         Data to sign
22
     * @param PrivateKeyInfo               $privkey_info Private key
23
     * @param SignatureAlgorithmIdentifier $algo         Signature algorithm
24
     *
25
     * @return Signature
26
     */
27
    abstract public function sign(string $data, PrivateKeyInfo $privkey_info,
28
        SignatureAlgorithmIdentifier $algo): Signature;
29
30
    /**
31
     * Verify signature with given algorithm using given public key.
32
     *
33
     * @param string                       $data        Data to verify
34
     * @param Signature                    $signature   Signature
35
     * @param PublicKeyInfo                $pubkey_info Public key
36
     * @param SignatureAlgorithmIdentifier $algo        Signature algorithm
37
     *
38
     * @return bool True if signature matches
39
     */
40
    abstract public function verify(string $data, Signature $signature,
41
        PublicKeyInfo $pubkey_info, SignatureAlgorithmIdentifier $algo): bool;
42
43
    /**
44
     * Encrypt data with given algorithm using given key.
45
     *
46
     * Padding must be added by the caller. Initialization vector is
47
     * taken from the algorithm identifier if available.
48
     *
49
     * @param string                    $data Plaintext
50
     * @param string                    $key  Encryption key
51
     * @param CipherAlgorithmIdentifier $algo Encryption algorithm
52
     *
53
     * @return string Ciphertext
54
     */
55
    abstract public function encrypt(string $data, string $key,
56
        CipherAlgorithmIdentifier $algo): string;
57
58
    /**
59
     * Decrypt data with given algorithm using given key.
60
     *
61
     * Possible padding is not removed and must be handled by the caller.
62
     * Initialization vector is taken from the algorithm identifier if
63
     * available.
64
     *
65
     * @param string                    $data Ciphertext
66
     * @param string                    $key  Encryption key
67
     * @param CipherAlgorithmIdentifier $algo Encryption algorithm
68
     *
69
     * @return string Plaintext
70
     */
71
    abstract public function decrypt(string $data, string $key,
72
        CipherAlgorithmIdentifier $algo): string;
73
74
    /**
75
     * Get default supported crypto implementation.
76
     *
77
     * @return self
78
     */
79 1
    public static function getDefault(): self
80
    {
81 1
        if (defined('OPENSSL_VERSION_NUMBER')) {
82 1
            return new Crypto\OpenSSLCrypto();
83
        }
84
        // @codeCoverageIgnoreStart
85
        throw new \RuntimeException('No crypto implementation available.');
86
        // @codeCoverageIgnoreEnd
87
    }
88
}
89