|
1 | 1 | use bouncycastle_core::errors::CoreError; |
2 | | -use bouncycastle_core::serializable_state::{LIB_VERSION}; |
3 | | -use bouncycastle_core::traits::{SerializableState}; |
| 2 | +use bouncycastle_core::serializable_state::LIB_VERSION; |
| 3 | +use bouncycastle_core::traits::SerializableState; |
4 | 4 |
|
5 | | -pub struct TestFrameworkSerializableState { } |
| 5 | +pub struct TestFrameworkSerializableState {} |
6 | 6 |
|
7 | 7 | impl TestFrameworkSerializableState { |
8 | 8 | pub fn new() -> Self { |
9 | | - Self { } |
| 9 | + Self {} |
10 | 10 | } |
11 | 11 |
|
12 | 12 | /// Test all the members of trait SerializableState. |
13 | | - /// |
| 13 | + /// |
14 | 14 | /// Expects ta be handed an instance of the object that has some in-progress state to be serialized. |
15 | 15 | pub fn test<const SERIALIZED_STATE_LEN: usize, S: SerializableState<SERIALIZED_STATE_LEN>>( |
16 | 16 | &self, |
17 | 17 | instance: &S, |
18 | 18 | ) { |
19 | 19 | // There's not a lot we can test here in the abstract, but we can test a few things to |
20 | 20 | // ensure that the SerializableState trait has been impl'd correctly. |
21 | | - |
| 21 | + |
22 | 22 | // You can serialize and then deserialize the state. |
23 | 23 | let serialized_state = instance.serialize_state(); |
24 | 24 | assert_eq!(serialized_state.len(), SERIALIZED_STATE_LEN); |
25 | | - |
| 25 | + |
26 | 26 | let _deserialized_state = S::from_serialized_state(serialized_state).unwrap(); |
27 | | - |
28 | | - |
| 27 | + |
29 | 28 | // The serialized state MUST include a prefix indicating the current version of the library. |
30 | 29 | assert_eq!(serialized_state[..3], LIB_VERSION); |
31 | | - |
32 | | - |
| 30 | + |
33 | 31 | // All implementations MUST reject a serialized state from lib ver 0.0.0 |
34 | 32 | // This doesn't really serve any purpose except testing that all impl's have properly |
35 | 33 | // used the helper functions. |
36 | 34 | let mut busted_serialized_state = serialized_state.clone(); |
37 | 35 | busted_serialized_state[..3].copy_from_slice(&[0, 0, 0]); |
38 | 36 | match S::from_serialized_state(busted_serialized_state) { |
39 | | - Err(CoreError::IncompatibleVersion) => { /* good */ }, |
40 | | - _ => { panic!("Expected IncompatibleVersion error") } |
| 37 | + Err(CoreError::IncompatibleVersion) => { /* good */ } |
| 38 | + _ => { |
| 39 | + panic!("Expected IncompatibleVersion error") |
| 40 | + } |
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
0 commit comments