Shaka Packager SDK
request_signer.h
1 // Copyright 2014 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_REQUEST_SIGNER_H_
8 #define PACKAGER_MEDIA_BASE_REQUEST_SIGNER_H_
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include <packager/macros/classes.h>
15 
16 namespace shaka {
17 namespace media {
18 
19 class AesCbcEncryptor;
20 class RsaPrivateKey;
21 
24  public:
25  virtual ~RequestSigner();
26 
30  virtual bool GenerateSignature(const std::string& message,
31  std::string* signature) = 0;
32 
33  const std::string& signer_name() const { return signer_name_; }
34 
35  protected:
36  explicit RequestSigner(const std::string& signer_name);
37 
38  private:
39  std::string signer_name_;
40 
41  DISALLOW_COPY_AND_ASSIGN(RequestSigner);
42 };
43 
46  public:
47  ~AesRequestSigner() override;
48 
51  static AesRequestSigner* CreateSigner(const std::string& signer_name,
52  const std::vector<uint8_t>& aes_key,
53  const std::vector<uint8_t>& iv);
54 
56  bool GenerateSignature(const std::string& message,
57  std::string* signature) override;
58 
59  private:
60  AesRequestSigner(const std::string& signer_name,
61  std::unique_ptr<AesCbcEncryptor> encryptor);
62 
63  std::unique_ptr<AesCbcEncryptor> aes_cbc_encryptor_;
64 
65  DISALLOW_COPY_AND_ASSIGN(AesRequestSigner);
66 };
67 
70  public:
71  ~RsaRequestSigner() override;
72 
75  static RsaRequestSigner* CreateSigner(const std::string& signer_name,
76  const std::string& pkcs1_rsa_key);
77 
79  bool GenerateSignature(const std::string& message,
80  std::string* signature) override;
81 
82  private:
83  RsaRequestSigner(const std::string& signer_name,
84  std::unique_ptr<RsaPrivateKey> rsa_private_key);
85 
86  std::unique_ptr<RsaPrivateKey> rsa_private_key_;
87 
88  DISALLOW_COPY_AND_ASSIGN(RsaRequestSigner);
89 };
90 
91 } // namespace media
92 } // namespace shaka
93 
94 #endif // PACKAGER_MEDIA_BASE_REQUEST_SIGNER_H_
AesRequestSigner uses AES-CBC signing.
bool GenerateSignature(const std::string &message, std::string *signature) override
RequestSigner implementation override.
static AesRequestSigner * CreateSigner(const std::string &signer_name, const std::vector< uint8_t > &aes_key, const std::vector< uint8_t > &iv)
Abstract class used for signature generation.
virtual bool GenerateSignature(const std::string &message, std::string *signature)=0
RsaRequestSigner uses RSA-PSS signing.
bool GenerateSignature(const std::string &message, std::string *signature) override
RequestSigner implementation override.
static RsaRequestSigner * CreateSigner(const std::string &signer_name, const std::string &pkcs1_rsa_key)
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66