blob: 12953f730748c17258b8e15440aad13e8b2138eb [file] [log] [blame]
David Zeuthenab3e5652019-10-28 13:32:48 -04001/*
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
David Zeuthenab3e5652019-10-28 13:32:48 -040023#include <binder/Status.h>
24
25namespace android {
26namespace security {
27namespace identity {
28
29using ::std::optional;
30using ::std::string;
31using ::std::vector;
32
33using ::android::binder::Status;
David Zeuthenab3e5652019-10-28 13:32:48 -040034
David Zeuthena6f9fba2020-02-11 22:08:27 -050035// Converts a HAL status to a credstore service-specific error with code
36// ICredentialStore::ERROR_GENERIC.
37Status halStatusToGenericError(const Status& halStatus);
38
39// Converts a HAL status to a credstore service-specific error of a given value
40Status halStatusToError(const Status& halStatus, int credStoreError);
David Zeuthenab3e5652019-10-28 13:32:48 -040041
42// Helper function to atomically write |data| into file at |path|.
43//
44// Returns true on success, false on error.
45//
46bool 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//
52optional<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_