Shaka Packager SDK
Loading...
Searching...
No Matches
cpix_key_source.h
1// Copyright 2026 Google LLC. 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_CPIX_KEY_SOURCE_H_
8#define PACKAGER_MEDIA_BASE_CPIX_KEY_SOURCE_H_
9
10#include <cstdint>
11#include <memory>
12#include <string>
13#include <vector>
14
15#include <packager/crypto_params.h>
16#include <packager/media/base/key_source.h>
17
18namespace shaka {
19namespace media {
20
23 public:
24 virtual ~CpixFetcher() = default;
25
31 virtual Status Fetch(const std::string& url,
32 const std::string& request_body,
33 const std::vector<std::string>& headers,
34 std::string* response) = 0;
35};
36
42class CpixKeySource : public KeySource {
43 public:
44 ~CpixKeySource() override;
45
48 Status FetchKeys(EmeInitDataType init_data_type,
49 const std::vector<uint8_t>& init_data) override;
50 Status GetKey(const std::string& stream_label, EncryptionKey* key) override;
51 Status GetKey(const std::vector<uint8_t>& key_id,
52 EncryptionKey* key) override;
53 Status GetCryptoPeriodKey(uint32_t crypto_period_index,
54 int32_t crypto_period_duration_in_seconds,
55 const std::string& stream_label,
56 EncryptionKey* key) override;
58
64 static std::unique_ptr<CpixKeySource> Create(
65 const CpixEncryptionParams& cpix_params);
66
69 static std::unique_ptr<CpixKeySource> CreateWithFetcher(
70 const CpixEncryptionParams& cpix_params,
71 CpixFetcher* fetcher);
72
78 static std::unique_ptr<CpixKeySource> CreateForDecryption(
79 const CpixEncryptionParams& cpix_params);
80
81 private:
82 static std::unique_ptr<CpixKeySource> CreateInternal(
83 const CpixEncryptionParams& cpix_params,
84 CpixFetcher* fetcher,
85 bool for_decryption);
86
87 explicit CpixKeySource(EncryptionKeyMap&& encryption_key_map);
88 CpixKeySource(const CpixKeySource&) = delete;
89 CpixKeySource& operator=(const CpixKeySource&) = delete;
90
91 EncryptionKeyMap encryption_key_map_;
92};
93
94} // namespace media
95} // namespace shaka
96
97#endif // PACKAGER_MEDIA_BASE_CPIX_KEY_SOURCE_H_
Fetches CPIX documents over HTTP(S). Replaceable for testing.
virtual Status Fetch(const std::string &url, const std::string &request_body, const std::vector< std::string > &headers, std::string *response)=0
Status FetchKeys(EmeInitDataType init_data_type, const std::vector< uint8_t > &init_data) override
static std::unique_ptr< CpixKeySource > CreateForDecryption(const CpixEncryptionParams &cpix_params)
static std::unique_ptr< CpixKeySource > CreateWithFetcher(const CpixEncryptionParams &cpix_params, CpixFetcher *fetcher)
static std::unique_ptr< CpixKeySource > Create(const CpixEncryptionParams &cpix_params)
Status GetCryptoPeriodKey(uint32_t crypto_period_index, int32_t crypto_period_duration_in_seconds, const std::string &stream_label, EncryptionKey *key) override
Status GetKey(const std::string &stream_label, EncryptionKey *key) override
KeySource is responsible for encryption key acquisition.
Definition key_source.h:56
All the methods that are virtual are virtual for mocking.