7 #include <packager/media/crypto/aes_encryptor_factory.h>
9 #include <packager/media/base/aes_encryptor.h>
10 #include <packager/media/base/aes_pattern_cryptor.h>
11 #include <packager/media/crypto/sample_aes_ec3_cryptor.h>
16 std::unique_ptr<AesCryptor> AesEncryptorFactory::CreateEncryptor(
17 FourCC protection_scheme,
18 uint8_t crypt_byte_block,
19 uint8_t skip_byte_block,
21 const std::vector<uint8_t>& key,
22 const std::vector<uint8_t>& iv) {
23 std::unique_ptr<AesCryptor> encryptor;
24 switch (protection_scheme) {
26 encryptor.reset(
new AesCtrEncryptor);
29 encryptor.reset(
new AesCbcEncryptor(kNoPadding));
32 encryptor.reset(
new AesPatternCryptor(
33 crypt_byte_block, skip_byte_block,
35 AesCryptor::kDontUseConstantIv,
36 std::unique_ptr<AesCryptor>(
new AesCtrEncryptor)));
39 encryptor.reset(
new AesPatternCryptor(
40 crypt_byte_block, skip_byte_block,
42 AesCryptor::kUseConstantIv,
43 std::unique_ptr<AesCryptor>(
new AesCbcEncryptor(kNoPadding))));
45 case kAppleSampleAesProtectionScheme:
46 if (crypt_byte_block == 0 && skip_byte_block == 0) {
47 if (codec == kCodecEAC3) {
48 encryptor.reset(
new SampleAesEc3Cryptor(
49 std::unique_ptr<AesCryptor>(
new AesCbcEncryptor(kNoPadding))));
52 new AesCbcEncryptor(kNoPadding, AesCryptor::kUseConstantIv));
55 encryptor.reset(
new AesPatternCryptor(
56 crypt_byte_block, skip_byte_block,
58 AesCryptor::kUseConstantIv,
59 std::unique_ptr<AesCryptor>(
new AesCbcEncryptor(kNoPadding))));
63 LOG(ERROR) <<
"Unsupported protection scheme.";
68 std::vector<uint8_t> random_iv;
70 LOG(ERROR) <<
"Failed to generate random iv.";
73 if (!encryptor->InitializeWithIv(key, random_iv))
76 if (!encryptor->InitializeWithIv(key, iv))
All the methods that are virtual are virtual for mocking.