blob: 8f6a09e5c39ca363175190939818c76f7b785e86 [file] [log] [blame]
Janis Danisevskis212c68b2021-01-14 22:29:28 -08001// Copyright 2020, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Rust binding for getting the attestation application id.
16
17use keystore2_aaid_bindgen::{
18 aaid_keystore_attestation_id, KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE,
19};
20
21/// Returns the attestation application id for the given uid or an error code
22/// corresponding to ::android::status_t.
23pub fn get_aaid(uid: u32) -> Result<Vec<u8>, u32> {
24 let mut buffer = [0u8; KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE];
25 let mut size = KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE;
26 // Safety:
27 // aaid_keystore_attestation_id expects a buffer of exactly
28 // KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE bytes and returns the number of bytes written
29 // in the second pointer argument.
30 let status = unsafe { aaid_keystore_attestation_id(uid, buffer.as_mut_ptr(), &mut size) };
31 match status {
Charisee03e00842023-01-25 01:41:23 +000032 0 => Ok(buffer[0..size].to_vec()),
Janis Danisevskis212c68b2021-01-14 22:29:28 -080033 status => Err(status),
34 }
35}