7 #include "packager/media/base/request_signer.h"
9 #include "packager/base/sha1.h"
10 #include "packager/base/strings/string_number_conversions.h"
11 #include "packager/media/base/aes_encryptor.h"
12 #include "packager/media/base/rsa_key.h"
14 namespace edash_packager {
17 RequestSigner::RequestSigner(
const std::string& signer_name)
18 : signer_name_(signer_name) {}
19 RequestSigner::~RequestSigner() {}
21 AesRequestSigner::AesRequestSigner(
const std::string& signer_name,
22 scoped_ptr<AesCbcEncryptor> encryptor)
23 : RequestSigner(signer_name), aes_cbc_encryptor_(encryptor.Pass()) {
24 DCHECK(aes_cbc_encryptor_);
26 AesRequestSigner::~AesRequestSigner() {}
29 const std::string& aes_key_hex,
30 const std::string& iv_hex) {
31 std::vector<uint8_t> aes_key;
32 if (!base::HexStringToBytes(aes_key_hex, &aes_key)) {
33 LOG(ERROR) <<
"Failed to convert hex string to bytes: " << aes_key_hex;
36 std::vector<uint8_t> iv;
37 if (!base::HexStringToBytes(iv_hex, &iv)) {
38 LOG(ERROR) <<
"Failed to convert hex string to bytes: " << iv_hex;
42 scoped_ptr<AesCbcEncryptor> encryptor(
44 if (!encryptor->InitializeWithIv(aes_key, iv))
50 std::string* signature) {
51 aes_cbc_encryptor_->Encrypt(base::SHA1HashString(message), signature);
55 RsaRequestSigner::RsaRequestSigner(
const std::string& signer_name,
56 scoped_ptr<RsaPrivateKey> rsa_private_key)
57 :
RequestSigner(signer_name), rsa_private_key_(rsa_private_key.Pass()) {
58 DCHECK(rsa_private_key_);
60 RsaRequestSigner::~RsaRequestSigner() {}
63 const std::string& signer_name,
64 const std::string& pkcs1_rsa_key) {
65 scoped_ptr<RsaPrivateKey> rsa_private_key(
73 std::string* signature) {
74 return rsa_private_key_->GenerateSignature(message, signature);