1 /*
2  * Copyright (C) 2022 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 // Some targets may not have any tests enabled
18 #![allow(unused)]
19 
20 use super::*;
21 use ::test::assert;
22 use core::ffi::CStr;
23 use tipc::{Handle, TipcError};
24 
25 ::test::init!();
26 
open_hwwsk_session() -> Result<Handle, TipcError>27 fn open_hwwsk_session() -> Result<Handle, TipcError> {
28     let port = CStr::from_bytes_with_nul(HWWSK_PORT).expect("HWKEY_PORT was not null terminated");
29     Handle::connect(port)
30 }
31 
32 const KEY_SIZE: usize = 32;
33 
34 #[cfg(feature = "generic-arm-unittest")]
35 #[test]
test_hwwsk_generate_key()36 fn test_hwwsk_generate_key() {
37     let session = open_hwwsk_session().expect("could not open hwkey session");
38 
39     let buf = &mut [0u8; HWWSK_MAX_MSG_SIZE as usize];
40 
41     let key_res = generate_key(&session, buf, KEY_SIZE, KeyFlags::new().rollback_resistance());
42 
43     assert!(key_res.is_ok());
44 }
45 
46 #[cfg(feature = "generic-arm-unittest")]
47 #[test]
test_hwwsk_import_key()48 fn test_hwwsk_import_key() {
49     let session = open_hwwsk_session().expect("could not open hwkey session");
50 
51     let buf = &mut [0u8; HWWSK_MAX_MSG_SIZE as usize];
52 
53     let key_res =
54         import_key(&session, buf, KEY_SIZE, KeyFlags::new().rollback_resistance(), &[0; KEY_SIZE]);
55 
56     assert!(key_res.is_ok());
57 }
58