MCPcopy Create free account
hub / github.com/RustCrypto/utils / generator

Function generator

wycheproof2blb/src/mac.rs:38–67  ·  view source on GitHub ↗
(data: &[u8], algorithm: &str, key_size: u32)

Source from the content-addressed store, hash-verified

36
37#[must_use]
38pub fn generator(data: &[u8], algorithm: &str, key_size: u32) -> Vec<TestInfo> {
39 let suite: TestSuite = serde_json::from_slice(data).unwrap();
40 assert_eq!(algorithm, suite.suite.algorithm);
41
42 let mut infos = vec![];
43 for g in &suite.test_groups {
44 for tc in &g.tests {
45 if key_size != 0 && g.key_size != key_size {
46 continue;
47 }
48 if tc.case.result != CaseResult::Valid {
49 // TODO: adapt HMAC tests for invalid cases
50 continue;
51 }
52 assert_eq!(tc.key.len() * 8, g.key_size as usize);
53 assert_eq!(g.tag_size % 8, 0);
54 infos.push(TestInfo {
55 data: vec![
56 tc.key.clone(),
57 tc.msg.clone(),
58 // `tc.tag` holds the MAC output truncated to `(g.tag_size / 8)` bytes
59 // (when this is smaller than MAC output size)
60 tc.tag.clone(),
61 ],
62 desc: description(&suite.suite, &tc.case),
63 });
64 }
65 }
66 infos
67}

Callers

nothing calls this directly

Calls 2

descriptionFunction · 0.85
unwrapMethod · 0.45

Tested by

no test coverage detected