Refactor OEMCrypto mock and its unit tests
This is a copy of the Widevine CL: https://widevine-internal-review.googlesource.com/#/c/9708/ This CL refactors some of code in oemcrypto/mock and oemcrypto/test in preparation for adding usage table code. Change-Id: I7e58c8ecd6d92b3e177cb915733212fcad645485
This commit is contained in:
@@ -15,17 +15,6 @@
|
||||
|
||||
namespace wvoec_mock {
|
||||
|
||||
enum KeyType {
|
||||
KEYTYPE_UNKNOWN,
|
||||
KEYTYPE_PREPROV,
|
||||
KEYTYPE_ROOT,
|
||||
KEYTYPE_DEVICE,
|
||||
KEYTYPE_CONTENT,
|
||||
KEYTYPE_CONTENT_AUDIO,
|
||||
KEYTYPE_CONTENT_VIDEO,
|
||||
KEYTYPE_MAX
|
||||
};
|
||||
|
||||
const uint32_t kControlObserveDataPath = (1<<31);
|
||||
const uint32_t kControlObserveHDCP = (1<<30);
|
||||
const uint32_t kControlObserveCGMS = (1<<29);
|
||||
@@ -48,11 +37,9 @@ const uint32_t kControlCGMSCopyNever = (0x03);
|
||||
|
||||
class KeyControlBlock {
|
||||
public:
|
||||
KeyControlBlock() : valid_(false) {}
|
||||
KeyControlBlock(bool refresh) : valid_(false), refresh_(refresh) {}
|
||||
KeyControlBlock(const std::vector<uint8_t>& key_control_string);
|
||||
~KeyControlBlock() {}
|
||||
|
||||
bool SetFromString(const std::vector<uint8_t>& key_control_string);
|
||||
bool Validate();
|
||||
void Invalidate() { valid_ = false; }
|
||||
|
||||
@@ -68,57 +55,25 @@ class KeyControlBlock {
|
||||
uint32_t ExtractField(const std::vector<uint8_t>& str, int idx);
|
||||
|
||||
bool valid_;
|
||||
bool refresh_;
|
||||
uint32_t verification_;
|
||||
uint32_t duration_;
|
||||
uint32_t nonce_;
|
||||
uint32_t control_bits_;
|
||||
};
|
||||
|
||||
// AES-128 crypto key
|
||||
// AES-128 crypto key, or HMAC signing key.
|
||||
class Key {
|
||||
public:
|
||||
Key() : valid_(false), type_(KEYTYPE_UNKNOWN), has_control_(false) {}
|
||||
Key(const Key& key) : valid_(key.valid_), type_(key.type_),
|
||||
value_(key.value_),
|
||||
has_control_(key.has_control_),
|
||||
control_(key.control_) {}
|
||||
Key(KeyType type, const std::vector<uint8_t>& key_string,
|
||||
const KeyControlBlock& control);
|
||||
Key(const Key& key) : value_(key.value_), control_(key.control_) {}
|
||||
Key(const std::vector<uint8_t>& key_string, const KeyControlBlock& control);
|
||||
|
||||
virtual ~Key() {};
|
||||
|
||||
// Key is valid iff setValue(), setType(), and setControl() have been called
|
||||
bool setValue(const char* key_string, size_t key_string_length);
|
||||
bool setType(KeyType ktype);
|
||||
bool setControl(const KeyControlBlock& control);
|
||||
bool UpdateDuration(const KeyControlBlock& control);
|
||||
|
||||
KeyType keyType() { return type_; }
|
||||
void UpdateDuration(const KeyControlBlock& control);
|
||||
const std::vector<uint8_t>& value() const { return value_; }
|
||||
const KeyControlBlock& control() const { return control_; }
|
||||
|
||||
bool isDeviceKey() { return (KEYTYPE_DEVICE == type_); }
|
||||
bool isRootKey() { return (KEYTYPE_ROOT == type_); }
|
||||
bool isPreprovKey() { return (KEYTYPE_PREPROV == type_); }
|
||||
bool isContentKey() {
|
||||
bool ctypes = (KEYTYPE_CONTENT == type_) ||
|
||||
(KEYTYPE_CONTENT_AUDIO == type_) ||
|
||||
(KEYTYPE_CONTENT_VIDEO == type_);
|
||||
return ctypes;
|
||||
}
|
||||
bool isValidType() {
|
||||
return ((KEYTYPE_UNKNOWN < type_) && (KEYTYPE_MAX > type_));
|
||||
}
|
||||
bool isValid() { return valid_; }
|
||||
|
||||
void clear() { value_.clear(); valid_ = false; }
|
||||
|
||||
private:
|
||||
bool valid_;
|
||||
KeyType type_;
|
||||
std::vector<uint8_t> value_;
|
||||
bool has_control_;
|
||||
KeyControlBlock control_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user