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,25 +15,15 @@
|
||||
|
||||
namespace wvoec_mock {
|
||||
|
||||
bool KeyControlBlock::Validate() {
|
||||
valid_ = false;
|
||||
if ((0x6b63746c != verification_) && // kctl.
|
||||
(0x6b633039 != verification_)) { // kc09.
|
||||
LOGE("KCB: BAD verification string: %08X (not %08X or %08X)",
|
||||
verification_, 0x6b63746c, 0x6b633039);
|
||||
return false;
|
||||
}
|
||||
#define FOURCC(c1, c2, c3, c4) \
|
||||
(c1 << 24 | c2 << 16 | c3 << 8 | c4)
|
||||
|
||||
if (refresh_) {
|
||||
if (control_bits_ & kControlObserveDataPath) {
|
||||
LOGW("KCB: data_path_type set for refresh.");
|
||||
}
|
||||
if (control_bits_ & kControlObserveHDCP) {
|
||||
LOGW("KCB: HDCP setting set for refresh.");
|
||||
}
|
||||
if (control_bits_ & kControlObserveCGMS) {
|
||||
LOGW("KCB: CGMS setting set for refresh.");
|
||||
}
|
||||
bool KeyControlBlock::Validate() {
|
||||
if ((FOURCC('k', 'c', 't', 'l') != verification_) && // original verification
|
||||
(FOURCC('k', 'c', '0', '9') != verification_)) { // add in version 9 api.
|
||||
LOGE("KCB: BAD verification string: %08X (not %08X or %08X)", verification_,
|
||||
0x6b63746c, 0x6b633039);
|
||||
return false;
|
||||
}
|
||||
valid_ = true;
|
||||
return valid_;
|
||||
@@ -50,11 +40,12 @@ uint32_t KeyControlBlock::ExtractField(const std::vector<uint8_t>& str, int idx)
|
||||
return t;
|
||||
}
|
||||
|
||||
bool KeyControlBlock::SetFromString(const std::vector<uint8_t>& key_control_string) {
|
||||
KeyControlBlock::KeyControlBlock(
|
||||
const std::vector<uint8_t>& key_control_string) {
|
||||
if (key_control_string.size() < wvcdm::KEY_CONTROL_SIZE) {
|
||||
LOGE("KCB: BAD Size: %d (not %d)",key_control_string.size(),
|
||||
wvcdm::KEY_CONTROL_SIZE);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
verification_ = ExtractField(key_control_string, 0);
|
||||
@@ -62,73 +53,56 @@ bool KeyControlBlock::SetFromString(const std::vector<uint8_t>& key_control_stri
|
||||
nonce_ = ExtractField(key_control_string, 2);
|
||||
control_bits_ = ExtractField(key_control_string, 3);
|
||||
|
||||
return Validate();
|
||||
LOGD("KCB:");
|
||||
LOGD(" valid: %d", valid());
|
||||
LOGD(" duration: %d", duration());
|
||||
LOGD(" nonce: %08X", nonce());
|
||||
LOGD(" magic: %08X", verification());
|
||||
LOGD(" bits: %08X", control_bits());
|
||||
switch (control_bits() & kControlReplayMask) {
|
||||
case kControlNonceRequired:
|
||||
LOGD(" bits kControlReplay kControlNonceRequired.");
|
||||
break;
|
||||
case kControlNonceOrEntry:
|
||||
LOGD(" bits kControlReplay kControlNonceOrEntry.");
|
||||
break;
|
||||
default:
|
||||
LOGD(" bits kControlReplay unset.");
|
||||
break;
|
||||
}
|
||||
LOGD(" bits kControlKDCPVersion 0x%02x.",
|
||||
(control_bits() & kControlHDCPVersionMask) >> kControlHDCPVersionShift);
|
||||
LOGD(" bit kControlAllowEncrypt %s.",
|
||||
(control_bits() & kControlAllowEncrypt) ? "set" : "unset");
|
||||
LOGD(" bit kControlAllowDecrypt %s.",
|
||||
(control_bits() & kControlAllowDecrypt) ? "set" : "unset");
|
||||
LOGD(" bit kControlAllowSign %s.",
|
||||
(control_bits() & kControlAllowSign) ? "set" : "unset");
|
||||
LOGD(" bit kControlAllowVerify %s.",
|
||||
(control_bits() & kControlAllowVerify) ? "set" : "unset");
|
||||
LOGD(" bit kControlObserveDataPath %s.",
|
||||
(control_bits() & kControlObserveDataPath) ? "set" : "unset");
|
||||
LOGD(" bit kControlObserveHDCP %s.",
|
||||
(control_bits() & kControlObserveHDCP) ? "set" : "unset");
|
||||
LOGD(" bit kControlObserveCGMS %s.",
|
||||
(control_bits() & kControlObserveCGMS) ? "set" : "unset");
|
||||
LOGD(" bit kControlDataPathSecure %s.",
|
||||
(control_bits() & kControlDataPathSecure) ? "set" : "unset");
|
||||
LOGD(" bit kControlNonceEnabled %s.",
|
||||
(control_bits() & kControlNonceEnabled) ? "set" : "unset");
|
||||
LOGD(" bit kControlHDCPRequired %s.",
|
||||
(control_bits() & kControlHDCPRequired) ? "set" : "unset");
|
||||
uint32_t cgms_bits = control_bits() & 0x3;
|
||||
const char* cgms_values[4] = {"free", "BAD", "once", "never"};
|
||||
LOGD(" CGMS = %s", cgms_values[cgms_bits]);
|
||||
Validate();
|
||||
}
|
||||
|
||||
Key::Key(KeyType ktype, const std::vector<uint8_t>& key_string,
|
||||
const KeyControlBlock& control) :
|
||||
valid_(true), type_(ktype),
|
||||
value_(key_string), has_control_(true),
|
||||
control_(control) {
|
||||
}
|
||||
|
||||
bool Key::setValue(const char* key_string, size_t key_string_length) {
|
||||
valid_ = false;
|
||||
if (!key_string || key_string_length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
value_.assign(key_string, key_string + key_string_length);
|
||||
|
||||
if (isValidType() && has_control_) {
|
||||
valid_ = true;
|
||||
}
|
||||
return valid_;
|
||||
}
|
||||
|
||||
bool Key::setType(KeyType ktype) {
|
||||
valid_ = false;
|
||||
type_ = ktype;
|
||||
if (value_.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isValidType() && has_control_) {
|
||||
valid_ = true;
|
||||
}
|
||||
return valid_;
|
||||
}
|
||||
|
||||
bool Key::setControl(const KeyControlBlock& control) {
|
||||
valid_ = false;
|
||||
if (!control.valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
control_ = control;
|
||||
has_control_ = true;
|
||||
|
||||
if (isValidType() && !value_.empty()) {
|
||||
valid_ = true;
|
||||
}
|
||||
return valid_;
|
||||
}
|
||||
|
||||
bool Key::UpdateDuration(const KeyControlBlock& control) {
|
||||
valid_ = false;
|
||||
if (!control.valid() || !has_control_) {
|
||||
LOGE("UpdateDuration: control block not valid.");
|
||||
return false;
|
||||
}
|
||||
Key::Key(const std::vector<uint8_t>& key_string, const KeyControlBlock& control)
|
||||
: value_(key_string), control_(control) {}
|
||||
|
||||
void Key::UpdateDuration(const KeyControlBlock& control) {
|
||||
control_.set_duration(control.duration());
|
||||
|
||||
if (isValidType() && !value_.empty()) {
|
||||
valid_ = true;
|
||||
} else {
|
||||
LOGE("UpdateDuration: value or type bad.");
|
||||
}
|
||||
return valid_;
|
||||
}
|
||||
|
||||
}; // namespace wvoec_eng
|
||||
|
||||
Reference in New Issue
Block a user