1*e1997b9aSAndroid Build Coastguard Worker /* 2*e1997b9aSAndroid Build Coastguard Worker * Copyright (c) 2019, The Android Open Source Project 3*e1997b9aSAndroid Build Coastguard Worker * 4*e1997b9aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*e1997b9aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*e1997b9aSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*e1997b9aSAndroid Build Coastguard Worker * 8*e1997b9aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*e1997b9aSAndroid Build Coastguard Worker * 10*e1997b9aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*e1997b9aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*e1997b9aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e1997b9aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*e1997b9aSAndroid Build Coastguard Worker * limitations under the License. 15*e1997b9aSAndroid Build Coastguard Worker */ 16*e1997b9aSAndroid Build Coastguard Worker 17*e1997b9aSAndroid Build Coastguard Worker #ifndef SYSTEM_SECURITY_IDENTITY_UTIL_H_ 18*e1997b9aSAndroid Build Coastguard Worker #define SYSTEM_SECURITY_IDENTITY_UTIL_H_ 19*e1997b9aSAndroid Build Coastguard Worker 20*e1997b9aSAndroid Build Coastguard Worker #include <string> 21*e1997b9aSAndroid Build Coastguard Worker #include <vector> 22*e1997b9aSAndroid Build Coastguard Worker 23*e1997b9aSAndroid Build Coastguard Worker #include <binder/Status.h> 24*e1997b9aSAndroid Build Coastguard Worker 25*e1997b9aSAndroid Build Coastguard Worker namespace android { 26*e1997b9aSAndroid Build Coastguard Worker namespace security { 27*e1997b9aSAndroid Build Coastguard Worker namespace identity { 28*e1997b9aSAndroid Build Coastguard Worker 29*e1997b9aSAndroid Build Coastguard Worker using ::std::optional; 30*e1997b9aSAndroid Build Coastguard Worker using ::std::string; 31*e1997b9aSAndroid Build Coastguard Worker using ::std::vector; 32*e1997b9aSAndroid Build Coastguard Worker 33*e1997b9aSAndroid Build Coastguard Worker using ::android::binder::Status; 34*e1997b9aSAndroid Build Coastguard Worker 35*e1997b9aSAndroid Build Coastguard Worker // Converts a HAL status to a credstore service-specific error with code 36*e1997b9aSAndroid Build Coastguard Worker // ICredentialStore::ERROR_GENERIC. 37*e1997b9aSAndroid Build Coastguard Worker Status halStatusToGenericError(const Status& halStatus); 38*e1997b9aSAndroid Build Coastguard Worker 39*e1997b9aSAndroid Build Coastguard Worker // Converts a HAL status to a credstore service-specific error of a given value 40*e1997b9aSAndroid Build Coastguard Worker Status halStatusToError(const Status& halStatus, int credStoreError); 41*e1997b9aSAndroid Build Coastguard Worker 42*e1997b9aSAndroid Build Coastguard Worker // Helper function to atomically write |data| into file at |path|. 43*e1997b9aSAndroid Build Coastguard Worker // 44*e1997b9aSAndroid Build Coastguard Worker // Returns true on success, false on error. 45*e1997b9aSAndroid Build Coastguard Worker // 46*e1997b9aSAndroid Build Coastguard Worker bool fileSetContents(const string& path, const vector<uint8_t>& data); 47*e1997b9aSAndroid Build Coastguard Worker 48*e1997b9aSAndroid Build Coastguard Worker // Helper function which reads contents offile at |path| into |data|. 49*e1997b9aSAndroid Build Coastguard Worker // 50*e1997b9aSAndroid Build Coastguard Worker // Returns nothing on error, the content on success. 51*e1997b9aSAndroid Build Coastguard Worker // 52*e1997b9aSAndroid Build Coastguard Worker optional<vector<uint8_t>> fileGetContents(const string& path); 53*e1997b9aSAndroid Build Coastguard Worker 54*e1997b9aSAndroid Build Coastguard Worker } // namespace identity 55*e1997b9aSAndroid Build Coastguard Worker } // namespace security 56*e1997b9aSAndroid Build Coastguard Worker } // namespace android 57*e1997b9aSAndroid Build Coastguard Worker 58*e1997b9aSAndroid Build Coastguard Worker #endif // SYSTEM_SECURITY_IDENTITY_UTIL_H_ 59