shaka-packager/media/base/request_signer.h

94 lines
2.8 KiB
C
Raw Normal View History

// Copyright 2014 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef MEDIA_BASE_REQUEST_SIGNER_H_
#define MEDIA_BASE_REQUEST_SIGNER_H_
#include <string>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
namespace edash_packager {
namespace media {
class AesCbcPkcs5Encryptor;
class RsaPrivateKey;
/// Abstract class used for signature generation.
class RequestSigner {
public:
virtual ~RequestSigner();
/// Generate signature for the input message.
/// @param signature should not be NULL.
/// @return true on success, false otherwise.
virtual bool GenerateSignature(const std::string& message,
std::string* signature) = 0;
const std::string& signer_name() const { return signer_name_; }
protected:
explicit RequestSigner(const std::string& signer_name);
private:
std::string signer_name_;
DISALLOW_COPY_AND_ASSIGN(RequestSigner);
};
/// AesRequestSigner uses AES-CBC signing.
class AesRequestSigner : public RequestSigner {
public:
virtual ~AesRequestSigner();
/// Create an AesSigner object from key and iv in hex.
/// @return The created AesRequestSigner object on success, NULL otherwise.
static AesRequestSigner* CreateSigner(const std::string& signer_name,
const std::string& aes_key_hex,
const std::string& iv_hex);
/// RequestSigner implementation override.
virtual bool GenerateSignature(const std::string& message,
std::string* signature) OVERRIDE;
private:
AesRequestSigner(const std::string& signer_name,
scoped_ptr<AesCbcPkcs5Encryptor> encryptor);
scoped_ptr<AesCbcPkcs5Encryptor> aes_cbc_encryptor_;
DISALLOW_COPY_AND_ASSIGN(AesRequestSigner);
};
/// RsaRequestSigner uses RSA-PSS signing.
class RsaRequestSigner : public RequestSigner {
public:
virtual ~RsaRequestSigner();
/// Create an RsaSigner object using a DER encoded PKCS#1 RSAPrivateKey.
/// @return The created RsaRequestSigner object on success, NULL otherwise.
static RsaRequestSigner* CreateSigner(const std::string& signer_name,
const std::string& pkcs1_rsa_key);
/// RequestSigner implementation override.
virtual bool GenerateSignature(const std::string& message,
std::string* signature) OVERRIDE;
private:
RsaRequestSigner(const std::string& signer_name,
scoped_ptr<RsaPrivateKey> rsa_private_key);
scoped_ptr<RsaPrivateKey> rsa_private_key_;
DISALLOW_COPY_AND_ASSIGN(RsaRequestSigner);
};
} // namespace media
} // namespace edash_packager
#endif // MEDIA_BASE_REQUEST_SIGNER_H_