Shaka Packager SDK
decrypt_config.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
6 #define PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
7 
8 #include <cstdint>
9 #include <string>
10 #include <vector>
11 
12 #include <packager/macros/classes.h>
13 #include <packager/media/base/fourccs.h>
14 
15 namespace shaka {
16 namespace media {
17 
29  : clear_bytes(0), cipher_bytes(0) {}
30  SubsampleEntry(uint16_t clear_bytes, uint32_t cipher_bytes)
31  : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {}
32 
33  uint16_t clear_bytes;
34  uint32_t cipher_bytes;
35 };
36 
40  public:
42  static const size_t kDecryptionKeySize = 16;
43 
50  DecryptConfig(const std::vector<uint8_t>& key_id,
51  const std::vector<uint8_t>& iv,
52  const std::vector<SubsampleEntry>& subsamples);
53 
66  DecryptConfig(const std::vector<uint8_t>& key_id,
67  const std::vector<uint8_t>& iv,
68  const std::vector<SubsampleEntry>& subsamples,
69  FourCC protection_scheme,
70  uint8_t crypt_byte_block,
71  uint8_t skip_byte_block);
72 
73  ~DecryptConfig();
74 
79  void AddSubsample(uint16_t clear_bytes, uint32_t cipher_bytes) {
80  subsamples_.emplace_back(clear_bytes, cipher_bytes);
81  }
82 
84  size_t GetTotalSizeOfSubsamples() const;
85 
86  const std::vector<uint8_t>& key_id() const { return key_id_; }
87  const std::vector<uint8_t>& iv() const { return iv_; }
88  const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; }
89  FourCC protection_scheme() const { return protection_scheme_; }
90  uint8_t crypt_byte_block() const { return crypt_byte_block_; }
91  uint8_t skip_byte_block() const { return skip_byte_block_; }
92 
93  private:
94  const std::vector<uint8_t> key_id_;
95 
96  // Initialization vector.
97  const std::vector<uint8_t> iv_;
98 
99  // Subsample information. May be empty for some formats, meaning entire frame
100  // (less data ignored by data_offset_) is encrypted.
101  std::vector<SubsampleEntry> subsamples_;
102 
103  const FourCC protection_scheme_;
104  // For pattern-based protection schemes, like CENS and CBCS.
105  const uint8_t crypt_byte_block_;
106  const uint8_t skip_byte_block_;
107 
108  DISALLOW_COPY_AND_ASSIGN(DecryptConfig);
109 };
110 
111 } // namespace media
112 } // namespace shaka
113 
114 #endif // PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
DecryptConfig(const std::vector< uint8_t > &key_id, const std::vector< uint8_t > &iv, const std::vector< SubsampleEntry > &subsamples)
void AddSubsample(uint16_t clear_bytes, uint32_t cipher_bytes)
size_t GetTotalSizeOfSubsamples() const
static const size_t kDecryptionKeySize
Keys are always 128 bits.
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66