David Zeuthen | 8b6973b | 2016-09-20 12:39:49 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person |
| 5 | * obtaining a copy of this software and associated documentation |
| 6 | * files (the "Software"), to deal in the Software without |
| 7 | * restriction, including without limitation the rights to use, copy, |
| 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 9 | * of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #ifndef FAKE_AVB_OPS_H_ |
| 26 | #define FAKE_AVB_OPS_H_ |
| 27 | |
| 28 | #include <base/files/file_util.h> |
| 29 | #include <string> |
| 30 | #include <vector> |
| 31 | |
| 32 | #include "libavb.h" |
| 33 | |
| 34 | struct FakeAvbOpsC; |
| 35 | typedef struct FakeAvbOpsC FakeAvbOpsC; |
| 36 | |
| 37 | class FakeAvbOps { |
| 38 | public: |
| 39 | FakeAvbOps(); |
| 40 | ~FakeAvbOps(); |
| 41 | |
| 42 | AvbOps* avb_ops() { return (AvbOps*)avb_ops_; } |
| 43 | |
| 44 | void set_partition_dir(const base::FilePath& partition_dir) { |
| 45 | partition_dir_ = partition_dir; |
| 46 | } |
| 47 | |
| 48 | void set_expected_public_key(const std::string& expected_public_key) { |
| 49 | expected_public_key_ = expected_public_key; |
| 50 | } |
| 51 | |
| 52 | void set_stored_rollback_indexes( |
| 53 | const std::vector<uint64_t>& stored_rollback_indexes) { |
| 54 | stored_rollback_indexes_ = stored_rollback_indexes; |
| 55 | } |
| 56 | |
| 57 | std::vector<uint64_t> get_stored_rollback_indexes() { |
| 58 | return stored_rollback_indexes_; |
| 59 | } |
| 60 | |
| 61 | void set_stored_is_device_unlocked(bool stored_is_device_unlocked) { |
| 62 | stored_is_device_unlocked_ = stored_is_device_unlocked; |
| 63 | } |
| 64 | |
| 65 | AvbIOResult read_from_partition(const char* partition, int64_t offset, |
| 66 | size_t num_bytes, void* buffer, |
| 67 | size_t* out_num_read); |
| 68 | |
| 69 | AvbIOResult write_to_partition(const char* partition, int64_t offset, |
| 70 | size_t num_bytes, const void* buffer); |
| 71 | |
David Zeuthen | 507752b | 2016-09-29 16:31:18 -0400 | [diff] [blame^] | 72 | AvbIOResult validate_vbmeta_public_key(AvbOps* ops, |
| 73 | const uint8_t* public_key_data, |
| 74 | size_t public_key_length, |
| 75 | bool* out_key_is_trusted); |
David Zeuthen | 8b6973b | 2016-09-20 12:39:49 -0400 | [diff] [blame] | 76 | |
David Zeuthen | 507752b | 2016-09-29 16:31:18 -0400 | [diff] [blame^] | 77 | AvbIOResult read_rollback_index(AvbOps* ops, size_t rollback_index_slot, |
| 78 | uint64_t* out_rollback_index); |
David Zeuthen | 8b6973b | 2016-09-20 12:39:49 -0400 | [diff] [blame] | 79 | |
David Zeuthen | 507752b | 2016-09-29 16:31:18 -0400 | [diff] [blame^] | 80 | AvbIOResult write_rollback_index(AvbOps* ops, size_t rollback_index_slot, |
| 81 | uint64_t rollback_index); |
David Zeuthen | 8b6973b | 2016-09-20 12:39:49 -0400 | [diff] [blame] | 82 | |
David Zeuthen | 507752b | 2016-09-29 16:31:18 -0400 | [diff] [blame^] | 83 | AvbIOResult read_is_device_unlocked(AvbOps* ops, |
| 84 | bool* out_is_device_unlocked); |
David Zeuthen | 8b6973b | 2016-09-20 12:39:49 -0400 | [diff] [blame] | 85 | |
David Zeuthen | 507752b | 2016-09-29 16:31:18 -0400 | [diff] [blame^] | 86 | AvbIOResult get_unique_guid_for_partition(AvbOps* ops, const char* partition, |
| 87 | char* guid_buf, |
| 88 | size_t guid_buf_size); |
David Zeuthen | 8b6973b | 2016-09-20 12:39:49 -0400 | [diff] [blame] | 89 | |
| 90 | private: |
| 91 | FakeAvbOpsC* avb_ops_; |
| 92 | |
| 93 | base::FilePath partition_dir_; |
| 94 | |
| 95 | std::string expected_public_key_; |
| 96 | |
| 97 | std::vector<uint64_t> stored_rollback_indexes_; |
| 98 | |
| 99 | bool stored_is_device_unlocked_; |
| 100 | }; |
| 101 | |
| 102 | #endif /* FAKE_AVB_OPS_H_ */ |