Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
namespace Aws\Crypto;
3
 
4
use Aws\Crypto\Cipher\CipherMethod;
5
use GuzzleHttp\Psr7\Stream;
6
 
7
/**
8
 * @internal
9
 */
10
abstract class AbstractCryptoClientV2
11
{
12
    public static $supportedCiphers = ['gcm'];
13
 
14
    public static $supportedKeyWraps = [
15
        KmsMaterialsProviderV2::WRAP_ALGORITHM_NAME
16
    ];
17
 
18
    public static $supportedSecurityProfiles = ['V2', 'V2_AND_LEGACY'];
19
 
20
    public static $legacySecurityProfiles = ['V2_AND_LEGACY'];
21
 
22
    /**
23
     * Returns if the passed cipher name is supported for encryption by the SDK.
24
     *
25
     * @param string $cipherName The name of a cipher to verify is registered.
26
     *
27
     * @return bool If the cipher passed is in our supported list.
28
     */
29
    public static function isSupportedCipher($cipherName)
30
    {
31
        return in_array($cipherName, self::$supportedCiphers, true);
32
    }
33
 
34
    /**
35
     * Returns an identifier recognizable by `openssl_*` functions, such as
36
     * `aes-256-gcm`
37
     *
38
     * @param string $cipherName Name of the cipher being used for encrypting
39
     *                           or decrypting.
40
     * @param int $keySize Size of the encryption key, in bits, that will be
41
     *                     used.
42
     *
43
     * @return string
44
     */
45
    abstract protected function getCipherOpenSslName($cipherName, $keySize);
46
 
47
    /**
48
     * Constructs a CipherMethod for the given name, initialized with the other
49
     * data passed for use in encrypting or decrypting.
50
     *
51
     * @param string $cipherName Name of the cipher to generate for encrypting.
52
     * @param string $iv Base Initialization Vector for the cipher.
53
     * @param int $keySize Size of the encryption key, in bits, that will be
54
     *                     used.
55
     *
56
     * @return CipherMethod
57
     *
58
     * @internal
59
     */
60
    abstract protected function buildCipherMethod($cipherName, $iv, $keySize);
61
 
62
    /**
63
     * Performs a reverse lookup to get the openssl_* cipher name from the
64
     * AESName passed in from the MetadataEnvelope.
65
     *
66
     * @param $aesName
67
     *
68
     * @return string
69
     *
70
     * @internal
71
     */
72
    abstract protected function getCipherFromAesName($aesName);
73
 
74
    /**
75
     * Dependency to provide an interface for building an encryption stream for
76
     * data given cipher details, metadata, and materials to do so.
77
     *
78
     * @param Stream $plaintext Plain-text data to be encrypted using the
79
     *                          materials, algorithm, and data provided.
80
     * @param array $options Options for use in encryption.
81
     * @param MaterialsProviderV2 $provider A provider to supply and encrypt
82
     *                                      materials used in encryption.
83
     * @param MetadataEnvelope $envelope A storage envelope for encryption
84
     *                                   metadata to be added to.
85
     *
86
     * @return AesStreamInterface
87
     *
88
     * @internal
89
     */
90
    abstract public function encrypt(
91
        Stream $plaintext,
92
        array $options,
93
        MaterialsProviderV2 $provider,
94
        MetadataEnvelope $envelope
95
    );
96
 
97
    /**
98
     * Dependency to provide an interface for building a decryption stream for
99
     * cipher text given metadata and materials to do so.
100
     *
101
     * @param string $cipherText Plain-text data to be decrypted using the
102
     *                           materials, algorithm, and data provided.
103
     * @param MaterialsProviderInterface $provider A provider to supply and encrypt
104
     *                                             materials used in encryption.
105
     * @param MetadataEnvelope $envelope A storage envelope for encryption
106
     *                                   metadata to be read from.
107
     * @param array $options Options used for decryption.
108
     *
109
     * @return AesStreamInterface
110
     *
111
     * @internal
112
     */
113
    abstract public function decrypt(
114
        $cipherText,
115
        MaterialsProviderInterfaceV2 $provider,
116
        MetadataEnvelope $envelope,
117
        array $options = []
118
    );
119
}