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 <binder/Status.h>
24 
25 namespace android {
26 namespace security {
27 namespace identity {
28 
29 using ::std::optional;
30 using ::std::string;
31 using ::std::vector;
32 
33 using ::android::binder::Status;
34 
35 // Converts a HAL status to a credstore service-specific error with code
36 // ICredentialStore::ERROR_GENERIC.
37 Status halStatusToGenericError(const Status& halStatus);
38 
39 // Converts a HAL status to a credstore service-specific error of a given value
40 Status halStatusToError(const Status& halStatus, int credStoreError);
41 
42 // Helper function to atomically write |data| into file at |path|.
43 //
44 // Returns true on success, false on error.
45 //
46 bool fileSetContents(const string& path, const vector<uint8_t>& data);
47 
48 // Helper function which reads contents offile at |path| into |data|.
49 //
50 // Returns nothing on error, the content on success.
51 //
52 optional<vector<uint8_t>> fileGetContents(const string& path);
53 
54 }  // namespace identity
55 }  // namespace security
56 }  // namespace android
57 
58 #endif  // SYSTEM_SECURITY_IDENTITY_UTIL_H_
59