Source release 17.1.0
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
// Copyright 2022 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
/**
|
||||
The test file system for the Level 3 OEMCrypto sits on top of the host file
|
||||
system. A real production version may either use the host file system or it
|
||||
may write files directly to the file system.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
@@ -5,14 +15,17 @@
|
||||
|
||||
#include "level3_file_system_ce_test.h"
|
||||
|
||||
namespace wvoec3 {
|
||||
#include "test_host.h"
|
||||
|
||||
std::map<std::string, std::string> OEMCrypto_Level3CETestFileSystem::files_;
|
||||
namespace wvoec3 {
|
||||
|
||||
ssize_t OEMCrypto_Level3CETestFileSystem::Read(const char* filename,
|
||||
void* buffer, size_t size) {
|
||||
if (!Exists(filename)) return 0;
|
||||
std::string data = files_[std::string(filename)];
|
||||
if (!g_host) return 0;
|
||||
const std::string name(filename);
|
||||
if (!g_host->global_storage().exists(name)) return 0;
|
||||
std::string data;
|
||||
if (!g_host->global_storage().read(name, &data)) return 0;
|
||||
size_t bytes_read = std::min(size, data.size());
|
||||
memcpy(buffer, data.data(), bytes_read);
|
||||
return bytes_read;
|
||||
@@ -21,24 +34,31 @@ ssize_t OEMCrypto_Level3CETestFileSystem::Read(const char* filename,
|
||||
ssize_t OEMCrypto_Level3CETestFileSystem::Write(const char* filename,
|
||||
const void* buffer,
|
||||
size_t size) {
|
||||
if (!g_host) return 0;
|
||||
std::string data(static_cast<const char*>(buffer), size);
|
||||
files_[std::string(filename)] = data;
|
||||
const std::string name(filename);
|
||||
if (!g_host->global_storage().write(name, data)) return 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
bool OEMCrypto_Level3CETestFileSystem::Exists(const char* filename) {
|
||||
return files_.find(std::string(filename)) != files_.end();
|
||||
if (!g_host) return false;
|
||||
const std::string name(filename);
|
||||
return g_host->global_storage().exists(name);
|
||||
}
|
||||
|
||||
ssize_t OEMCrypto_Level3CETestFileSystem::FileSize(const char* filename) {
|
||||
if (!Exists(filename)) return -1;
|
||||
return files_[std::string(filename)].size();
|
||||
if (!g_host) return 0;
|
||||
const std::string name(filename);
|
||||
if (!g_host->global_storage().exists(name)) return 0;
|
||||
return static_cast<ssize_t>(g_host->global_storage().size(name));
|
||||
}
|
||||
|
||||
bool OEMCrypto_Level3CETestFileSystem::Remove(const char* filename) {
|
||||
if (!Exists(filename)) return false;
|
||||
files_.erase(std::string(filename));
|
||||
return true;
|
||||
if (!g_host) return false;
|
||||
const std::string name(filename);
|
||||
if (!g_host->global_storage().exists(name)) return false;
|
||||
return g_host->global_storage().remove(name);
|
||||
}
|
||||
|
||||
} // namespace wvoec3
|
||||
|
||||
Reference in New Issue
Block a user