Replace hardcoded parameters
This commit is contained in:
69
common/signer_public_key.cc
Normal file
69
common/signer_public_key.cc
Normal file
@@ -0,0 +1,69 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2019 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common/signer_public_key.h"
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "common/ec_key.h"
|
||||
#include "common/rsa_key.h"
|
||||
|
||||
namespace widevine {
|
||||
|
||||
// SignerPublicKeyImpl is a generic implementation of SignerPublicKey. The
|
||||
// initialization details are in the SignerPublicKey factory method.
|
||||
template <typename T>
|
||||
class SignerPublicKeyImpl : public SignerPublicKey {
|
||||
public:
|
||||
explicit SignerPublicKeyImpl(std::unique_ptr<T> signer_public_key)
|
||||
: signer_public_key_(std::move(signer_public_key)) {}
|
||||
~SignerPublicKeyImpl() override {}
|
||||
SignerPublicKeyImpl(const SignerPublicKeyImpl&) = delete;
|
||||
SignerPublicKeyImpl& operator=(const SignerPublicKeyImpl&) = delete;
|
||||
|
||||
bool VerifySignature(const std::string& message,
|
||||
const std::string& signature) const override {
|
||||
if (!signer_public_key_->VerifySignature(message, signature)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<T> signer_public_key_;
|
||||
};
|
||||
|
||||
std::unique_ptr<SignerPublicKey> SignerPublicKey::Create(
|
||||
const std::string& signer_public_key, DrmCertificate::Algorithm algorithm) {
|
||||
switch (algorithm) {
|
||||
case DrmCertificate::RSA: {
|
||||
std::unique_ptr<RsaPublicKey> public_key(
|
||||
RsaPublicKey::Create(signer_public_key));
|
||||
if (public_key == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return absl::make_unique<SignerPublicKeyImpl<RsaPublicKey>>(
|
||||
std::move(public_key));
|
||||
}
|
||||
// All supported ECC curves are specified here.
|
||||
case DrmCertificate::ECC_SECP256R1:
|
||||
case DrmCertificate::ECC_SECP384R1:
|
||||
case DrmCertificate::ECC_SECP521R1: {
|
||||
std::unique_ptr<ECPublicKey> public_key =
|
||||
ECPublicKey::Create(signer_public_key);
|
||||
if (public_key == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return absl::make_unique<SignerPublicKeyImpl<ECPublicKey>>(
|
||||
std::move(public_key));
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace widevine
|
||||
Reference in New Issue
Block a user