Android-cuttlefish cvd tool
storage.h
Go to the documentation of this file.
1//
2// Copyright (C) 2023 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <any>
19#include <string>
20
22
23namespace cuttlefish {
24namespace secure_env {
25
27 uint32_t size;
28 uint8_t payload[0];
29
31 CF_EXPECT(size == sizeof(uint8_t), "Size of payload is not matched with uint8 size");
32 return *reinterpret_cast<uint8_t*>(payload);
33 }
34};
35
41 public:
42 void operator()(StorageData* ptr);
43};
44
46using ManagedStorageData = std::unique_ptr<StorageData, StorageDataDestroyer>;
47
54
58class Storage {
59 public:
60 virtual Result<bool> HasKey(const std::string& key) const = 0;
61 virtual Result<ManagedStorageData> Read(const std::string& key) const = 0;
62 virtual Result<void> Write(const std::string& key, const StorageData& data) = 0;
63 virtual bool Exists() const = 0;
64
65 virtual ~Storage() = default;
66};
67
68} // namespace secure_env
69} // namespace cuttlefish
Definition: expected.h:86
void operator()(StorageData *ptr)
Definition: storage.cpp:22
Definition: storage.h:58
virtual Result< bool > HasKey(const std::string &key) const =0
virtual Result< ManagedStorageData > Read(const std::string &key) const =0
virtual bool Exists() const =0
virtual Result< void > Write(const std::string &key, const StorageData &data)=0
#define CF_EXPECT(...)
Definition: result.h:414
char data[Size]
Definition: incremental_server.cpp:1
uint32_t size
Definition: io.h:2
std::unique_ptr< StorageData, StorageDataDestroyer > ManagedStorageData
Definition: storage.h:46
Result< ManagedStorageData > CreateStorageData(size_t size)
Definition: storage.cpp:26
Definition: alloc_utils.cpp:23
Definition: secure_env_windows_lib.cpp:35
Definition: storage.h:26
Result< uint8_t > asUint8()
Definition: storage.h:30
uint8_t payload[0]
Definition: storage.h:28
uint32_t size
Definition: storage.h:27