58 lines
2.1 KiB
C++
58 lines
2.1 KiB
C++
// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine License
|
|
// Agreement.
|
|
#ifndef WVCDM_CORE_CRYPTO_WRAPPED_KEY_H_
|
|
#define WVCDM_CORE_CRYPTO_WRAPPED_KEY_H_
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "wv_class_utils.h"
|
|
|
|
namespace wvcdm {
|
|
// Represents OEMCrypto's wrapped private DRM key. As of v16, it is
|
|
// possible for OEMCrypto to support ECC-based DRM certificates. The
|
|
// format of the wrapped key is vendor specific; however, the API
|
|
// requires that the CDM track whether the wrapped key is RSA or ECC.
|
|
class CryptoWrappedKey {
|
|
public:
|
|
enum Type : int32_t { kUninitialized = 0, kRsa = 1, kEcc = 2 };
|
|
CryptoWrappedKey() = default;
|
|
WVCDM_DEFAULT_COPY_AND_MOVE(CryptoWrappedKey);
|
|
CryptoWrappedKey(Type type, const std::string& key)
|
|
: type_(type), key_(key) {}
|
|
CryptoWrappedKey(Type type, std::string&& key)
|
|
: type_(type), key_(std::move(key)) {}
|
|
|
|
Type type() const { return type_; }
|
|
void set_type(Type type) { type_ = type; }
|
|
|
|
const std::string& key() const { return key_; }
|
|
// Mutable reference getter for passing to OMECrypto.
|
|
std::string& key() { return key_; }
|
|
void set_key(const std::string& key) { key_ = key; }
|
|
void set_key(std::string&& key) { key_ = std::move(key); }
|
|
|
|
void Clear() {
|
|
type_ = kUninitialized;
|
|
key_.clear();
|
|
}
|
|
// A valid key must have a known key type and have key data.
|
|
bool IsValid() const { return type_ != kUninitialized && !key_.empty(); }
|
|
// Equality operator is for testing only. Real keys may have
|
|
// different meta data but the same logical key.
|
|
bool IsEqualTo(const CryptoWrappedKey& other) const {
|
|
return type_ == other.type_ && key_ == other.key_;
|
|
}
|
|
WVCDM_DEFINE_EQ_OPERATORS(CryptoWrappedKey);
|
|
|
|
private:
|
|
// DRM key type of the wrapped key. For wrapped keys which the type
|
|
// of key is unknown, assume it to be RSA.
|
|
Type type_ = kUninitialized;
|
|
// Vendor-specific wrapped DRM key.
|
|
std::string key_;
|
|
}; // class CryptoWrappedKey
|
|
} // namespace wvcdm
|
|
#endif // WVCDM_CORE_CRYPTO_WRAPPED_KEY_H_
|