David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, 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 SYSTEM_SECURITY_IDENTITY_UTIL_H_ |
| 18 | #define SYSTEM_SECURITY_IDENTITY_UTIL_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <android/hardware/identity/1.0/IIdentityCredentialStore.h> |
| 24 | #include <android/hardware/identity/1.0/types.h> |
| 25 | #include <binder/Status.h> |
| 26 | |
| 27 | namespace android { |
| 28 | namespace security { |
| 29 | namespace identity { |
| 30 | |
| 31 | using ::std::optional; |
| 32 | using ::std::string; |
| 33 | using ::std::vector; |
| 34 | |
| 35 | using ::android::binder::Status; |
| 36 | using ::android::hardware::identity::V1_0::Result; |
| 37 | |
| 38 | Status halResultToGenericError(const Result& result); |
| 39 | |
| 40 | // Helper function to atomically write |data| into file at |path|. |
| 41 | // |
| 42 | // Returns true on success, false on error. |
| 43 | // |
| 44 | bool fileSetContents(const string& path, const vector<uint8_t>& data); |
| 45 | |
| 46 | // Helper function which reads contents offile at |path| into |data|. |
| 47 | // |
| 48 | // Returns nothing on error, the content on success. |
| 49 | // |
| 50 | optional<vector<uint8_t>> fileGetContents(const string& path); |
| 51 | |
| 52 | } // namespace identity |
| 53 | } // namespace security |
| 54 | } // namespace android |
| 55 | |
| 56 | #endif // SYSTEM_SECURITY_IDENTITY_UTIL_H_ |