1 /* 2 * Copyright 2016 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 17 #ifndef SECURE_STORAGE_H_ 18 #define SECURE_STORAGE_H_ 19 20 #include <stddef.h> 21 #include <stdint.h> 22 23 namespace avb { 24 25 // Abstract interface for secure storage. 26 class SecureStorageInterface { 27 public: 28 SecureStorageInterface() = default; 29 virtual ~SecureStorageInterface() = default; 30 31 // SecureStorageInterface is neither copyable nor moveable 32 SecureStorageInterface(const SecureStorageInterface&) = delete; 33 SecureStorageInterface& operator=(const SecureStorageInterface&) = delete; 34 35 // Opens a file in secure storage named |filename|. 36 // 37 // Returns NO_ERROR on success, negative error code on failure. 38 virtual int open(const char* filename) = 0; 39 40 // Deletes a file in secure storage named |filename|. 41 // 42 // Returns NO_ERROR on success, negative error code on failure. 43 virtual int delete_file(const char* filename) = 0; 44 45 // Reads |size| bytes into |buf| from the file starting at offset |off|. The 46 // file must have been previously opened by open(). 47 // 48 // Returns number of bytes read on success, negative error code on failure. 49 virtual int read(uint64_t off, void* buf, size_t size) const = 0; 50 51 // Gets the size of the file in secure storage previously opened with open() 52 // and stores it in |size|. 53 // 54 // Returns NO_ERROR on success, negative error code on failure. 55 virtual int get_file_size(uint64_t* size) const = 0; 56 57 // Writes |size| bytes from |buf| into the file starting at offset |off|. 58 // The file must have been previously opened by open(). 59 // 60 // Returns number of bytes written on succes, negative error code on 61 // failure. 62 virtual int write(uint64_t off, const void* buf, size_t size) const = 0; 63 }; 64 65 } // namespace avb 66 67 #endif // SECURE_STORAGE_H_ 68