blob: 8d20550c107a4c2e11f287b8ecc421451633c94e [file] [log] [blame]
Janis Danisevskis18f27ad2016-06-01 13:57:40 -07001/*
2 * Copyright (C) 2016 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 KEYSTORE_KEYSTORE_ATTESTATION_ID_H_
18#define KEYSTORE_KEYSTORE_ATTESTATION_ID_H_
19
20#include <utils/Errors.h>
21#include <vector>
22
23namespace android {
24namespace security {
25
Janis Danisevskis011675d2016-09-01 11:41:29 +010026template <typename T> class StatusOr {
27 public:
28 StatusOr(const status_t error) : _status(error), _value() {}
29 StatusOr(const T& value) : _status(NO_ERROR), _value(value) {}
30 StatusOr(T&& value) : _status(NO_ERROR), _value(value) {}
31
32 operator const T&() const { return _value; }
33 operator T&() { return _value; }
34 operator T &&() && { return std::move(_value); }
35
36 bool isOk() const { return NO_ERROR == _status; }
37
38 ::android::status_t status() const { return _status; }
39
40 const T& value() const & { return _value; }
41 T& value() & { return _value; }
42 T&& value() && { return std::move(_value); }
43
44 private:
45 ::android::status_t _status;
46 T _value;
47};
48
Janis Danisevskis18f27ad2016-06-01 13:57:40 -070049/**
50 * Gathers the attestation id for the application determined by uid by querying the package manager
Janis Danisevskis011675d2016-09-01 11:41:29 +010051 * As of this writing uids can be shared in android, which is why the asn.1 encoded attestation
52 * application id may contain more than one package info followed by a set of digests of the
53 * packages signing certificates.
Janis Danisevskis18f27ad2016-06-01 13:57:40 -070054 *
Janis Danisevskis011675d2016-09-01 11:41:29 +010055 * @returns the asn.1 encoded attestation application id or an error code. Check the result with
56 * .isOk() before accessing.
Janis Danisevskis18f27ad2016-06-01 13:57:40 -070057 */
Janis Danisevskis011675d2016-09-01 11:41:29 +010058StatusOr<std::vector<uint8_t>> gather_attestation_application_id(uid_t uid);
Janis Danisevskis18f27ad2016-06-01 13:57:40 -070059
60} // namespace security
61} // namespace android
62#endif // KEYSTORE_KEYSTORE_ATTESTATION_ID_H_