7 #ifndef PACKAGER_MEDIA_BASE_AES_CRYPTOR_H_
8 #define PACKAGER_MEDIA_BASE_AES_CRYPTOR_H_
14 #include <mbedtls/cipher.h>
16 #include <packager/macros/classes.h>
17 #include <packager/media/base/fourccs.h>
37 explicit AesCryptor(ConstantIvFlag constant_iv_flag);
43 const std::vector<uint8_t>&
iv) = 0;
45 virtual size_t RequiredOutputSize(
size_t plaintext_size) {
46 return plaintext_size;
54 bool Crypt(
const std::vector<uint8_t>& text,
55 std::vector<uint8_t>* crypt_text);
56 bool Crypt(
const std::string& text, std::string* crypt_text);
58 bool Crypt(
const uint8_t* text,
size_t text_size, uint8_t* crypt_text) {
59 size_t crypt_text_size = text_size;
60 return Crypt(text, text_size, crypt_text, &crypt_text_size);
62 bool Crypt(
const uint8_t* text,
65 size_t* crypt_text_size) {
66 if (constant_iv_flag_ == kUseConstantIv)
69 num_crypt_bytes_ += text_size;
70 return CryptInternal(text, text_size, crypt_text, crypt_text_size);
77 bool SetIv(
const std::vector<uint8_t>&
iv);
85 const std::vector<uint8_t>&
iv()
const {
return iv_; }
95 std::vector<uint8_t>*
iv);
104 mbedtls_cipher_context_t cipher_ctx_;
106 bool SetupCipher(
size_t key_size, CipherMode mode);
119 virtual bool CryptInternal(
const uint8_t* text,
122 size_t* crypt_text_size) = 0;
125 virtual void SetIvInternal() = 0;
130 virtual size_t NumPaddingBytes(
size_t size)
const;
134 const ConstantIvFlag constant_iv_flag_;
137 std::vector<uint8_t> iv_;
140 size_t num_crypt_bytes_;
All the methods that are virtual are virtual for mocking.