1 // Copyright 2023 Google LLC
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 //! Unit tests
16
17 use crate::cbor::AsCborValue;
18 use alloc::vec;
19
20 #[test]
test_init_req_round_trip()21 fn test_init_req_round_trip() {
22 let want = crate::InitRequest {
23 peer_pub_key: vec![1, 2, 3],
24 peer_id: vec![2, 3, 4],
25 peer_nonce: vec![4, 5, 6],
26 peer_version: 1,
27 };
28 let data = want.clone().into_vec().unwrap();
29 let got = crate::InitRequest::from_slice(&data).unwrap();
30 assert_eq!(got, want);
31 }
32
33 #[test]
test_init_rsp_round_trip()34 fn test_init_rsp_round_trip() {
35 let want = crate::PerformOpResponse {
36 error_code: crate::ErrorCode::Ok,
37 rsp: Some(crate::PerformOpRsp::Init(crate::InitResponse {
38 ret: crate::KeInitResult {
39 session_init_info: crate::SessionInitiationInfo {
40 ke_key: crate::Key {
41 pub_key: Some(vec![10, 11]),
42 arc_from_pbk: Some(vec![12, 13]),
43 },
44 identity: vec![9],
45 nonce: vec![8, 7, 6],
46 version: 1,
47 },
48 session_info: crate::SessionInfo {
49 shared_keys: [vec![1], vec![2]],
50 session_id: vec![3, 4, 5],
51 session_id_signature: vec![5, 6, 7],
52 },
53 },
54 })),
55 };
56 let data = want.clone().into_vec().unwrap();
57 let got = crate::PerformOpResponse::from_slice(&data).unwrap();
58 assert_eq!(got, want);
59 }
60