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