Files
ce_cdm/cdm/test/level3_file_system_ce_test.cpp
John "Juce" Bruce 694cf6fb25 Source release 17.1.0
2022-07-07 17:14:31 -07:00

65 lines
2.1 KiB
C++

// 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>
#include <string>
#include "level3_file_system_ce_test.h"
#include "test_host.h"
namespace wvoec3 {
ssize_t OEMCrypto_Level3CETestFileSystem::Read(const char* filename,
void* buffer, size_t size) {
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;
}
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);
const std::string name(filename);
if (!g_host->global_storage().write(name, data)) return 0;
return size;
}
bool OEMCrypto_Level3CETestFileSystem::Exists(const char* filename) {
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 (!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 (!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