Shaka Packager SDK
raw_key_source.h
1 // Copyright 2016 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_BASE_RAW_KEY_SOURCE_H_
8 #define PACKAGER_MEDIA_BASE_RAW_KEY_SOURCE_H_
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include "packager/media/base/key_source.h"
15 #include "packager/media/public/crypto_params.h"
16 
17 namespace shaka {
18 namespace media {
19 
20 // Common SystemID defined by EME, which requires Key System implementations
21 // supporting ISO Common Encryption to support this SystemID and format.
22 // https://goo.gl/kUv2Xd
23 const uint8_t kCommonSystemId[] = {0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2,
24  0x4d, 0x02, 0xac, 0xe3, 0x3c, 0x1e,
25  0x52, 0xe2, 0xfb, 0x4b};
26 
27 // Unofficial fairplay system id extracted from
28 // https://forums.developer.apple.com/thread/6185.
29 const uint8_t kFairplaySystemId[] = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
30  0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
31  0xC7, 0x43, 0x9A, 0x47};
32 
34 class RawKeySource : public KeySource {
35  public:
36  ~RawKeySource() override;
37 
40  Status FetchKeys(EmeInitDataType init_data_type,
41  const std::vector<uint8_t>& init_data) override;
42  Status GetKey(const std::string& stream_label, EncryptionKey* key) override;
43  Status GetKey(const std::vector<uint8_t>& key_id,
44  EncryptionKey* key) override;
45  Status GetCryptoPeriodKey(uint32_t crypto_period_index,
46  const std::string& stream_label,
47  EncryptionKey* key) override;
49 
53  static std::unique_ptr<RawKeySource> Create(const RawKeyParams& raw_key);
54 
55  protected:
56  // Allow default constructor for mock key sources.
57  RawKeySource();
58 
59  private:
60  typedef std::map<std::string, std::unique_ptr<EncryptionKey>>
61  EncryptionKeyMap;
62  explicit RawKeySource(EncryptionKeyMap&& encryption_key_map);
63  RawKeySource(const RawKeySource&) = delete;
64  RawKeySource& operator=(const RawKeySource&) = delete;
65 
66  EncryptionKeyMap encryption_key_map_;
67 };
68 
69 } // namespace media
70 } // namespace shaka
71 
72 #endif // PACKAGER_MEDIA_BASE_RAW_KEY_SOURCE_H_
Status GetCryptoPeriodKey(uint32_t crypto_period_index, const std::string &stream_label, EncryptionKey *key) override
All the methods that are virtual are virtual for mocking.
Raw key encryption/decryption parameters, i.e. with key parameters provided.
Definition: crypto_params.h:99
A key source that uses raw keys for encryption.
static std::unique_ptr< RawKeySource > Create(const RawKeyParams &raw_key)
Status GetKey(const std::string &stream_label, EncryptionKey *key) override
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:45
Status FetchKeys(EmeInitDataType init_data_type, const std::vector< uint8_t > &init_data) override