use uuid::Uuid;
use super::id::PassportId;
const RFC_EXAMPLE: &str = "017F22E2-79B0-7CC3-98C4-DC0C0C07398F";
const RFC_TIMESTAMP_MS: u64 = 1_645_557_742_000;
fn example() -> Uuid {
Uuid::parse_str(RFC_EXAMPLE).expect("the RFC's example parses")
}
#[test]
fn the_rfc_example_has_the_fields_the_rfc_lists() {
let id = example();
assert_eq!(id.get_version_num(), 7);
assert_eq!(id.as_bytes()[8] >> 6, 0b10, "the two variant bits");
assert_eq!(
id.get_timestamp().map(|t| t.to_unix()),
Some((RFC_TIMESTAMP_MS / 1000, 0))
);
let [a, b, c, d, e, f, ..] = *id.as_bytes();
assert_eq!(
u64::from_be_bytes([0, 0, a, b, c, d, e, f]),
RFC_TIMESTAMP_MS,
"the leading six bytes are a big-endian millisecond timestamp"
);
}
#[test]
fn the_carrier_serial_is_the_bytes_after_the_rfc_timestamp() {
let serial = PassportId(example()).default_carrier_serial();
assert_eq!(serial, "7cc398c4dc0c0c07398f");
assert_eq!(serial.len(), 20);
assert!(
!serial.contains("017f22e279b0"),
"the timestamp must not appear in a code printed on a product"
);
}