7 #include <packager/media/base/request_signer.h>
9 #include <absl/log/check.h>
10 #include <absl/log/log.h>
11 #include <mbedtls/md.h>
13 #include <packager/media/base/aes_encryptor.h>
14 #include <packager/media/base/rsa_key.h>
19 RequestSigner::RequestSigner(
const std::string& signer_name)
20 : signer_name_(signer_name) {}
21 RequestSigner::~RequestSigner() {}
23 AesRequestSigner::AesRequestSigner(
const std::string& signer_name,
24 std::unique_ptr<AesCbcEncryptor> encryptor)
25 : RequestSigner(signer_name), aes_cbc_encryptor_(std::move(encryptor)) {
26 DCHECK(aes_cbc_encryptor_);
28 AesRequestSigner::~AesRequestSigner() {}
31 const std::string& signer_name,
32 const std::vector<uint8_t>& aes_key,
33 const std::vector<uint8_t>& iv) {
34 std::unique_ptr<AesCbcEncryptor> encryptor(
36 if (!encryptor->InitializeWithIv(aes_key, iv))
41 bool AesRequestSigner::GenerateSignature(
const std::string& message,
42 std::string* signature) {
43 const mbedtls_md_info_t* md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1);
46 std::string hash(mbedtls_md_get_size(md_info), 0);
48 mbedtls_md(md_info,
reinterpret_cast<const uint8_t*
>(message.data()),
49 message.size(),
reinterpret_cast<uint8_t*
>(hash.data())));
51 return aes_cbc_encryptor_->Crypt(hash, signature);
54 RsaRequestSigner::RsaRequestSigner(
55 const std::string& signer_name,
56 std::unique_ptr<RsaPrivateKey> rsa_private_key)
57 :
RequestSigner(signer_name), rsa_private_key_(std::move(rsa_private_key)) {
58 DCHECK(rsa_private_key_);
60 RsaRequestSigner::~RsaRequestSigner() {}
63 const std::string& signer_name,
64 const std::string& pkcs1_rsa_key) {
65 std::unique_ptr<RsaPrivateKey> rsa_private_key(
73 std::string* signature) {
74 return rsa_private_key_->GenerateSignature(message, signature);
All the methods that are virtual are virtual for mocking.