Cotton code
22 lines · 1.1 KB · RustRaw
use super::*;/// RULE: A sealed picture opens with its own key and must hash to what the message named.#[test]fn a_sealed_file_opens_with_its_key_and_hash() {    let plain = b"\xff\xd8 a synthetic jpeg".to_vec();    let sealed = seal_file(&plain).unwrap();    assert!(sealed.bytes.starts_with(b"cf1"));    assert!(!sealed.bytes.windows(9).any(|w| w == b"synthetic"), "no plain bytes in the sealed file");    assert_eq!(open_file(&sealed.key, &sealed.bytes, &sealed.sha256), Some(plain.clone()));    assert_eq!(open_file(&[7u8; 32], &sealed.bytes, &sealed.sha256), None, "another key opens nothing");    assert_eq!(open_file(&sealed.key, &sealed.bytes, &sha256_hex(b"other")), None, "a file the message did not name is refused");}/// RULE: The same key and nonce seal to the same bytes: the vector.#[test]fn the_file_vector() {    let sealed = seal_file_with(&[1u8; 32], &[2u8; 12], b"abc").unwrap();    assert_eq!(sealed.len(), 3 + 12 + 3 + 16);    assert_eq!(&sealed[..15], b"cf1\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02");    assert_eq!(open_file(&[1u8; 32], &sealed, &sha256_hex(b"abc")).as_deref(), Some(&b"abc"[..]));}