aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / ed25519 / tests / hex.rs
| 1 | //! Hexadecimal display/serialization tests. |
| 2 | |
| 3 | use ed25519::Signature; |
| 4 | use hex_literal::hex; |
| 5 | use std::str::FromStr; |
| 6 | |
| 7 | /// Test 1 signature from RFC 8032 ยง 7.1 |
| 8 | /// <https://datatracker.ietf.org/doc/html/rfc8032#section-7.1> |
| 9 | const TEST_1_SIGNATURE: [u8; Signature::BYTE_SIZE] = hex!( |
| 10 | "e5564300c360ac729086e2cc806e828a |
| 11 | 84877f1eb8e5d974d873e06522490155 |
| 12 | 5fb8821590a33bacc61e39701cf9b46b |
| 13 | d25bf5f0595bbe24655141438e7a100b" |
| 14 | ); |
| 15 | |
| 16 | #[test] |
| 17 | fn display() { |
| 18 | let sig = Signature::from_bytes(&TEST_1_SIGNATURE); |
| 19 | assert_eq!(sig.to_string(), "E5564300C360AC729086E2CC806E828A84877F1EB8E5D974D873E065224901555FB8821590A33BACC61E39701CF9B46BD25BF5F0595BBE24655141438E7A100B") |
| 20 | } |
| 21 | |
| 22 | #[test] |
| 23 | fn lower_hex() { |
| 24 | let sig = Signature::from_bytes(&TEST_1_SIGNATURE); |
| 25 | assert_eq!(format!("{:x}", sig), "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b") |
| 26 | } |
| 27 | |
| 28 | #[test] |
| 29 | fn upper_hex() { |
| 30 | let sig = Signature::from_bytes(&TEST_1_SIGNATURE); |
| 31 | assert_eq!(format!("{:X}", sig), "E5564300C360AC729086E2CC806E828A84877F1EB8E5D974D873E065224901555FB8821590A33BACC61E39701CF9B46BD25BF5F0595BBE24655141438E7A100B") |
| 32 | } |
| 33 | |
| 34 | #[test] |
| 35 | fn from_str_lower() { |
| 36 | let sig = Signature::from_str("e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b").unwrap(); |
| 37 | assert_eq!(sig.to_bytes(), TEST_1_SIGNATURE); |
| 38 | } |
| 39 | |
| 40 | #[test] |
| 41 | fn from_str_upper() { |
| 42 | let sig = Signature::from_str("E5564300C360AC729086E2CC806E828A84877F1EB8E5D974D873E065224901555FB8821590A33BACC61E39701CF9B46BD25BF5F0595BBE24655141438E7A100B").unwrap(); |
| 43 | assert_eq!(sig.to_bytes(), TEST_1_SIGNATURE); |
| 44 | } |
| 45 | |
| 46 | #[test] |
| 47 | fn from_str_rejects_mixed_case() { |
| 48 | let result = Signature::from_str("E5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"); |
| 49 | assert!(result.is_err()); |
| 50 | } |