// Copyright 2013 Google Inc. All Rights Reserved. // // Mock implementation of OEMCrypto APIs // #include "oemcrypto_engine_mock.h" #include #include #include #include #include #include #include #include "keys.h" #include "log.h" #include "oemcrypto_key_mock.h" #include "oemcrypto_rsa_key_shared.h" #include "string_conversions.h" #include "wv_cdm_constants.h" namespace wvoec_mock { // Note: The class CryptoEngine is configured at compile time by compiling in // different device property files. The methods in this file are generic to // all configurations. See the files oemcrypto_engine_device_properties*.cpp // for methods that are configured for specific configurations. CryptoEngine::CryptoEngine(wvcdm::FileSystem* file_system) : root_of_trust_(config_provisioning_method()), file_system_(file_system), usage_table_(this, file_system) { ERR_load_crypto_strings(); } CryptoEngine::~CryptoEngine() { wvcdm::AutoLock lock(session_table_lock_); ActiveSessions::iterator it; for (it = sessions_.begin(); it != sessions_.end(); ++it) { delete it->second; } sessions_.clear(); } void CryptoEngine::Terminate() {} SessionId CryptoEngine::CreateSession() { wvcdm::AutoLock lock(session_table_lock_); static int unique_id = 1; SessionId sid = (SessionId)++unique_id; SessionContext* sctx = new SessionContext(this, sid, root_of_trust_.SharedRsaKey()); sessions_[sid] = sctx; return sid; } bool CryptoEngine::DestroySession(SessionId sid) { SessionContext* sctx = FindSession(sid); wvcdm::AutoLock lock(session_table_lock_); if (sctx) { sessions_.erase(sid); delete sctx; return true; } else { return false; } } SessionContext* CryptoEngine::FindSession(SessionId sid) { wvcdm::AutoLock lock(session_table_lock_); ActiveSessions::iterator it = sessions_.find(sid); if (it != sessions_.end()) { return it->second; } return NULL; } } // namespace wvoec_mock