proto becomes bxcore, the one shared crate (M5b task 00)
Done the way the owner asked and the spike mapped: the crate and the manifests renamed, then what the build reported fixed. Layers: 138 "proto unresolved" errors across 169 files; cargo fmt reordering imports; six fixture paths built as strings in brokerd's and bxctl's tests, which the compiler cannot see, and comments naming crates/proto/; the crate-dependency check and its self-test. One more the spike did not reach: a `\nproto =` key inside a printf format in the self-test, which a word-boundary replacement skips because `n` and `p` are both word characters. make gate: gate: ok, 944 tests; no new entry in /tmp. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
//! SHA-256 vectors. Do not edit: these define the required behaviour.
|
||||
//!
|
||||
//! The lengths 55, 56, 63, 64 and 65 sit on either side of the padding boundaries of SHA-256,
|
||||
//! which is where implementations go wrong. Expected values come from `sha256sum`.
|
||||
|
||||
use bxcore::{Sha256, sha256};
|
||||
|
||||
const VECTORS: &[(usize, &str)] = &[
|
||||
(
|
||||
0,
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
),
|
||||
(
|
||||
1,
|
||||
"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb",
|
||||
),
|
||||
(
|
||||
55,
|
||||
"9f4390f8d30c2dd92ec9f095b65e2b9ae9b0a925a5258e241c9f1e910f734318",
|
||||
),
|
||||
(
|
||||
56,
|
||||
"b35439a4ac6f0948b6d6f9e3c6af0f5f590ce20f1bde7090ef7970686ec6738a",
|
||||
),
|
||||
(
|
||||
63,
|
||||
"7d3e74a05d7db15bce4ad9ec0658ea98e3f06eeecf16b4c6fff2da457ddc2f34",
|
||||
),
|
||||
(
|
||||
64,
|
||||
"ffe054fe7ae0cb6dc65c3af9b61d5209f439851db43d0ba5997337df154668eb",
|
||||
),
|
||||
(
|
||||
65,
|
||||
"635361c48bb9eab14198e76ea8ab7f1a41685d6ad62aa9146d301d4f17eb0ae0",
|
||||
),
|
||||
(
|
||||
119,
|
||||
"31eba51c313a5c08226adf18d4a359cfdfd8d2e816b13f4af952f7ea6584dcfb",
|
||||
),
|
||||
(
|
||||
127,
|
||||
"c57e9278af78fa3cab38667bef4ce29d783787a2f731d4e12200270f0c32320a",
|
||||
),
|
||||
(
|
||||
128,
|
||||
"6836cf13bac400e9105071cd6af47084dfacad4e5e302c94bfed24e013afb73e",
|
||||
),
|
||||
(
|
||||
1000,
|
||||
"41edece42d63e8d9bf515a9ba6932e1c20cbc9f5a5d134645adb5db1b9737ea3",
|
||||
),
|
||||
];
|
||||
|
||||
/// `n` bytes of the letter `a`.
|
||||
fn letters(n: usize) -> Vec<u8> {
|
||||
vec![b'a'; n]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abc() {
|
||||
let want = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
|
||||
assert_eq!(sha256(b"abc").unwrap().to_hex(), want);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lengths_around_the_padding_boundaries() {
|
||||
for (n, want) in VECTORS {
|
||||
assert_eq!(sha256(&letters(*n)).unwrap().to_hex(), *want, "{n} bytes");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn input_in_two_pieces_gives_the_same_hash() {
|
||||
for (n, want) in VECTORS {
|
||||
let data = letters(*n);
|
||||
for split in [0, 1, 55, 56, 63, 64, 65, *n / 2, *n] {
|
||||
let split = split.min(*n);
|
||||
let mut h = Sha256::new();
|
||||
h.update(&data[..split]).unwrap();
|
||||
h.update(&data[split..]).unwrap();
|
||||
assert_eq!(
|
||||
h.finish().unwrap().to_hex(),
|
||||
*want,
|
||||
"{n} bytes split at {split}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_million_letters() {
|
||||
let want = "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0";
|
||||
assert_eq!(sha256(&letters(1_000_000)).unwrap().to_hex(), want);
|
||||
let mut h = Sha256::default();
|
||||
for _ in 0..1000 {
|
||||
h.update(&letters(1000)).unwrap();
|
||||
}
|
||||
assert_eq!(h.finish().unwrap().to_hex(), want);
|
||||
}
|
||||
Reference in New Issue
Block a user