acvp_parser/
lib.rs

1use std::fmt;
2
3pub type AcvpResult<T> = std::result::Result<T, AcvpError>;
4
5#[derive(Debug, Clone)]
6pub struct AcvpError {
7    pub code: i32,
8    pub message: String,
9}
10
11impl fmt::Display for AcvpError {
12    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13        write!(f, "{} ({})", &self.message, &self.code)
14    }
15}
16
17pub mod blkcipher;
18pub mod drbg;
19pub mod hash;
20pub mod msgauth;
21pub mod parser;
22pub mod util;
23
24#[cfg(test)]
25#[test]
26fn test_init() {
27    use hash::SecureHash;
28
29    use crate::parser::{AcvpTest, TestCase, TestGroupData, TestResult};
30    let tgdata = TestGroupData {
31        algorithm: "sha1".to_string(),
32        test_type: util::TestType::AFT,
33        taglen: 0,
34        payload_len: 0,
35        ivmode: util::IVMode::Nil,
36        ivlen: 0,
37        direction: util::Direction::Nil,
38        drbgmode: drbg::DrbgMode::Nil,
39        prediction_resistance: false,
40        der_func: false,
41        reseed: false,
42        returned_bits_len: 0,
43    };
44
45    let mut t =
46        AcvpTest::<SecureHash>::new(r#"{ "tcId": 10, "msg": "abcdef" }"#, &tgdata).expect("Failed");
47    t.set_result(vec![0xa, 0xb, 0xc, 0xd, 0xe, 0xf])
48        .expect("Failed to set result");
49    println!("{}", t.pretty_result().expect("Failed dump"));
50}