/******************************************************************************* * * Copyright 2013 Google Inc. All Rights Reserved. * * mock implementation of OEMCrypto APIs * ******************************************************************************/ #include #include "l3crypto_key_mock.h" #include "wv_cdm_constants.h" namespace wvoec_obfs { bool KeyControlBlock::Validate() { valid_ = false; if (0x6b63746c != verification_) { return false; } // TODO(gmorgan): validate control bits valid_ = true; return valid_; } uint32_t KeyControlBlock::ExtractField(const std::vector& str, int idx) { int bidx = idx * 4; uint32_t t = static_cast(str[bidx]) << 24; t |= static_cast(str[bidx+1]) << 16; t |= static_cast(str[bidx+2]) << 8; t |= static_cast(str[bidx+3]); return t; } bool KeyControlBlock::SetFromString(const std::vector& key_control_string) { if (key_control_string.size() < wvcdm::KEY_CONTROL_SIZE) { return false; } verification_ = ExtractField(key_control_string, 0); duration_ = ExtractField(key_control_string, 1); nonce_ = ExtractField(key_control_string, 2); control_bits_ = ExtractField(key_control_string, 0); return Validate(); } Key::Key(KeyType ktype, const std::vector& 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_; } }; // namespace wvoec_eng