Janis Danisevskis | 212c68b | 2021-01-14 22:29:28 -0800 | [diff] [blame] | 1 | // 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 | |
| 17 | use 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. |
| 23 | pub 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 { |
Charisee | 03e0084 | 2023-01-25 01:41:23 +0000 | [diff] [blame] | 32 | 0 => Ok(buffer[0..size].to_vec()), |
Janis Danisevskis | 212c68b | 2021-01-14 22:29:28 -0800 | [diff] [blame] | 33 | status => Err(status), |
| 34 | } |
| 35 | } |