Cotton code
34 lines · 1.4 KB · RustRaw
use super::*;use crate::vault::recovery_code::mint_with;#[test]fn the_key_is_the_code_typed_any_way() {    let code = mint_with(&[7, 1, 9, 200, 33, 4, 5, 6, 7, 8, 9, 10, 11, 12]);    let key = BackupKey::from_code(&code).expect("a code");    assert_eq!(key.code(), code, "Show my recovery code shows the code the store keeps");    let spoken = code.to_lowercase().replace('-', " ");    assert_eq!(BackupKey::from_code(&spoken), Ok(key.clone()), "lower case and spaces");    assert_ne!(BackupKey::mint(), BackupKey::mint(), "two keys from the OS are two keys");    assert!(!format!("{key:?}").contains(&code[..4]), "the code never prints");}#[test]fn a_slip_is_caught_before_anything_is_tried() {    let code = mint_with(&[3; 14]);    let mut typo = code.clone();    let swapped = if typo.ends_with('0') { "1" } else { "0" };    typo.replace_range(typo.len() - 1.., swapped);    assert!(BackupKey::from_code(&typo).is_err());    assert!(BackupKey::from_code("ABCD").is_err());    assert!(BackupKey::from_code("").is_err());}#[test]fn the_check_names_a_key_without_opening_anything() {    let one = BackupKey::mint_with(&[1; 14]);    let two = BackupKey::mint_with(&[2; 14]);    assert_eq!(one.check().len(), 16);    assert_eq!(one.check(), BackupKey::mint_with(&[1; 14]).check());    assert_ne!(one.check(), two.check());    assert_ne!(*one.file_key(b"a"), *one.file_key(b"b"), "each file its own key");}