7 #ifndef PACKAGER_MEDIA_BASE_AES_CRYPTOR_H_
8 #define PACKAGER_MEDIA_BASE_AES_CRYPTOR_H_
13 #include "packager/base/macros.h"
14 #include "packager/base/memory/scoped_ptr.h"
15 #include "packager/media/base/fourccs.h"
18 typedef struct aes_key_st AES_KEY;
38 explicit AesCryptor(ConstantIvFlag constant_iv_flag);
44 const std::vector<uint8_t>&
iv) = 0;
51 bool Crypt(
const std::vector<uint8_t>& text,
52 std::vector<uint8_t>* crypt_text);
53 bool Crypt(
const std::string& text, std::string* crypt_text);
55 bool Crypt(
const uint8_t* text,
size_t text_size, uint8_t* crypt_text) {
56 size_t crypt_text_size = text_size;
57 return Crypt(text, text_size, crypt_text, &crypt_text_size);
59 bool Crypt(
const uint8_t* text,
62 size_t* crypt_text_size) {
63 if (constant_iv_flag_ == kUseConstantIv)
66 num_crypt_bytes_ += text_size;
67 return CryptInternal(text, text_size, crypt_text, crypt_text_size);
73 bool SetIv(
const std::vector<uint8_t>& iv);
81 const std::vector<uint8_t>&
iv()
const {
return iv_; }
91 std::vector<uint8_t>* iv);
94 const AES_KEY* aes_key()
const {
return aes_key_.get(); }
95 AES_KEY* mutable_aes_key() {
return aes_key_.get(); }
108 virtual bool CryptInternal(
const uint8_t* text,
111 size_t* crypt_text_size) = 0;
114 virtual void SetIvInternal() = 0;
119 virtual size_t NumPaddingBytes(
size_t size)
const;
122 scoped_ptr<AES_KEY> aes_key_;
126 const ConstantIvFlag constant_iv_flag_;
129 std::vector<uint8_t> iv_;
132 size_t num_crypt_bytes_;
140 #endif // PACKAGER_MEDIA_BASE_AES_CRYPTOR_H_