Removed unneeded usages of vec! macro
This commit is contained in:
parent
47b5510780
commit
2756b7fd7a
|
@ -449,11 +449,11 @@ mod test {
|
||||||
|
|
||||||
let compact = HeaderAndShortIds::from_block(&block, 42, 2, &[0, 1, 2]).unwrap();
|
let compact = HeaderAndShortIds::from_block(&block, 42, 2, &[0, 1, 2]).unwrap();
|
||||||
let idxs = compact.prefilled_txs.iter().map(|t| t.idx).collect::<Vec<_>>();
|
let idxs = compact.prefilled_txs.iter().map(|t| t.idx).collect::<Vec<_>>();
|
||||||
assert_eq!(idxs, vec![0, 0, 0]);
|
assert_eq!(idxs, [0, 0, 0]);
|
||||||
|
|
||||||
let compact = HeaderAndShortIds::from_block(&block, 42, 2, &[2]).unwrap();
|
let compact = HeaderAndShortIds::from_block(&block, 42, 2, &[2]).unwrap();
|
||||||
let idxs = compact.prefilled_txs.iter().map(|t| t.idx).collect::<Vec<_>>();
|
let idxs = compact.prefilled_txs.iter().map(|t| t.idx).collect::<Vec<_>>();
|
||||||
assert_eq!(idxs, vec![0, 1]);
|
assert_eq!(idxs, [0, 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -482,7 +482,7 @@ impl<'a, R: BufRead + ?Sized> BitStreamReader<'a, R> {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use bitcoin::bip158::BitStreamReader;
|
/// # use bitcoin::bip158::BitStreamReader;
|
||||||
/// # let data = vec![0xff];
|
/// # let data = [0xff];
|
||||||
/// # let mut input = data.as_slice();
|
/// # let mut input = data.as_slice();
|
||||||
/// let mut reader = BitStreamReader::new(&mut input); // input contains all 1's
|
/// let mut reader = BitStreamReader::new(&mut input); // input contains all 1's
|
||||||
/// let res = reader.read(1).expect("read failed");
|
/// let res = reader.read(1).expect("read failed");
|
||||||
|
|
|
@ -1795,7 +1795,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sighashtype_fromstr_display() {
|
fn sighashtype_fromstr_display() {
|
||||||
let sighashtypes = vec![
|
let sighashtypes = [
|
||||||
("SIGHASH_ALL", EcdsaSighashType::All),
|
("SIGHASH_ALL", EcdsaSighashType::All),
|
||||||
("SIGHASH_NONE", EcdsaSighashType::None),
|
("SIGHASH_NONE", EcdsaSighashType::None),
|
||||||
("SIGHASH_SINGLE", EcdsaSighashType::Single),
|
("SIGHASH_SINGLE", EcdsaSighashType::Single),
|
||||||
|
@ -1807,7 +1807,7 @@ mod tests {
|
||||||
assert_eq!(sht.to_string(), s);
|
assert_eq!(sht.to_string(), s);
|
||||||
assert_eq!(EcdsaSighashType::from_str(s).unwrap(), sht);
|
assert_eq!(EcdsaSighashType::from_str(s).unwrap(), sht);
|
||||||
}
|
}
|
||||||
let sht_mistakes = vec![
|
let sht_mistakes = [
|
||||||
"SIGHASH_ALL | SIGHASH_ANYONECANPAY",
|
"SIGHASH_ALL | SIGHASH_ANYONECANPAY",
|
||||||
"SIGHASH_NONE |SIGHASH_ANYONECANPAY",
|
"SIGHASH_NONE |SIGHASH_ANYONECANPAY",
|
||||||
"SIGHASH_SINGLE| SIGHASH_ANYONECANPAY",
|
"SIGHASH_SINGLE| SIGHASH_ANYONECANPAY",
|
||||||
|
|
|
@ -906,65 +906,62 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_int_test() {
|
fn serialize_int_test() {
|
||||||
// bool
|
// bool
|
||||||
assert_eq!(serialize(&false), vec![0u8]);
|
assert_eq!(serialize(&false), [0u8]);
|
||||||
assert_eq!(serialize(&true), vec![1u8]);
|
assert_eq!(serialize(&true), [1u8]);
|
||||||
// u8
|
// u8
|
||||||
assert_eq!(serialize(&1u8), vec![1u8]);
|
assert_eq!(serialize(&1u8), [1u8]);
|
||||||
assert_eq!(serialize(&0u8), vec![0u8]);
|
assert_eq!(serialize(&0u8), [0u8]);
|
||||||
assert_eq!(serialize(&255u8), vec![255u8]);
|
assert_eq!(serialize(&255u8), [255u8]);
|
||||||
// u16
|
// u16
|
||||||
assert_eq!(serialize(&1u16), vec![1u8, 0]);
|
assert_eq!(serialize(&1u16), [1u8, 0]);
|
||||||
assert_eq!(serialize(&256u16), vec![0u8, 1]);
|
assert_eq!(serialize(&256u16), [0u8, 1]);
|
||||||
assert_eq!(serialize(&5000u16), vec![136u8, 19]);
|
assert_eq!(serialize(&5000u16), [136u8, 19]);
|
||||||
// u32
|
// u32
|
||||||
assert_eq!(serialize(&1u32), vec![1u8, 0, 0, 0]);
|
assert_eq!(serialize(&1u32), [1u8, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&256u32), vec![0u8, 1, 0, 0]);
|
assert_eq!(serialize(&256u32), [0u8, 1, 0, 0]);
|
||||||
assert_eq!(serialize(&5000u32), vec![136u8, 19, 0, 0]);
|
assert_eq!(serialize(&5000u32), [136u8, 19, 0, 0]);
|
||||||
assert_eq!(serialize(&500000u32), vec![32u8, 161, 7, 0]);
|
assert_eq!(serialize(&500000u32), [32u8, 161, 7, 0]);
|
||||||
assert_eq!(serialize(&168430090u32), vec![10u8, 10, 10, 10]);
|
assert_eq!(serialize(&168430090u32), [10u8, 10, 10, 10]);
|
||||||
// i32
|
// i32
|
||||||
assert_eq!(serialize(&-1i32), vec![255u8, 255, 255, 255]);
|
assert_eq!(serialize(&-1i32), [255u8, 255, 255, 255]);
|
||||||
assert_eq!(serialize(&-256i32), vec![0u8, 255, 255, 255]);
|
assert_eq!(serialize(&-256i32), [0u8, 255, 255, 255]);
|
||||||
assert_eq!(serialize(&-5000i32), vec![120u8, 236, 255, 255]);
|
assert_eq!(serialize(&-5000i32), [120u8, 236, 255, 255]);
|
||||||
assert_eq!(serialize(&-500000i32), vec![224u8, 94, 248, 255]);
|
assert_eq!(serialize(&-500000i32), [224u8, 94, 248, 255]);
|
||||||
assert_eq!(serialize(&-168430090i32), vec![246u8, 245, 245, 245]);
|
assert_eq!(serialize(&-168430090i32), [246u8, 245, 245, 245]);
|
||||||
assert_eq!(serialize(&1i32), vec![1u8, 0, 0, 0]);
|
assert_eq!(serialize(&1i32), [1u8, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&256i32), vec![0u8, 1, 0, 0]);
|
assert_eq!(serialize(&256i32), [0u8, 1, 0, 0]);
|
||||||
assert_eq!(serialize(&5000i32), vec![136u8, 19, 0, 0]);
|
assert_eq!(serialize(&5000i32), [136u8, 19, 0, 0]);
|
||||||
assert_eq!(serialize(&500000i32), vec![32u8, 161, 7, 0]);
|
assert_eq!(serialize(&500000i32), [32u8, 161, 7, 0]);
|
||||||
assert_eq!(serialize(&168430090i32), vec![10u8, 10, 10, 10]);
|
assert_eq!(serialize(&168430090i32), [10u8, 10, 10, 10]);
|
||||||
// u64
|
// u64
|
||||||
assert_eq!(serialize(&1u64), vec![1u8, 0, 0, 0, 0, 0, 0, 0]);
|
assert_eq!(serialize(&1u64), [1u8, 0, 0, 0, 0, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&256u64), vec![0u8, 1, 0, 0, 0, 0, 0, 0]);
|
assert_eq!(serialize(&256u64), [0u8, 1, 0, 0, 0, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&5000u64), vec![136u8, 19, 0, 0, 0, 0, 0, 0]);
|
assert_eq!(serialize(&5000u64), [136u8, 19, 0, 0, 0, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&500000u64), vec![32u8, 161, 7, 0, 0, 0, 0, 0]);
|
assert_eq!(serialize(&500000u64), [32u8, 161, 7, 0, 0, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&723401728380766730u64), vec![10u8, 10, 10, 10, 10, 10, 10, 10]);
|
assert_eq!(serialize(&723401728380766730u64), [10u8, 10, 10, 10, 10, 10, 10, 10]);
|
||||||
// i64
|
// i64
|
||||||
assert_eq!(serialize(&-1i64), vec![255u8, 255, 255, 255, 255, 255, 255, 255]);
|
assert_eq!(serialize(&-1i64), [255u8, 255, 255, 255, 255, 255, 255, 255]);
|
||||||
assert_eq!(serialize(&-256i64), vec![0u8, 255, 255, 255, 255, 255, 255, 255]);
|
assert_eq!(serialize(&-256i64), [0u8, 255, 255, 255, 255, 255, 255, 255]);
|
||||||
assert_eq!(serialize(&-5000i64), vec![120u8, 236, 255, 255, 255, 255, 255, 255]);
|
assert_eq!(serialize(&-5000i64), [120u8, 236, 255, 255, 255, 255, 255, 255]);
|
||||||
assert_eq!(serialize(&-500000i64), vec![224u8, 94, 248, 255, 255, 255, 255, 255]);
|
assert_eq!(serialize(&-500000i64), [224u8, 94, 248, 255, 255, 255, 255, 255]);
|
||||||
assert_eq!(
|
assert_eq!(serialize(&-723401728380766730i64), [246u8, 245, 245, 245, 245, 245, 245, 245]);
|
||||||
serialize(&-723401728380766730i64),
|
assert_eq!(serialize(&1i64), [1u8, 0, 0, 0, 0, 0, 0, 0]);
|
||||||
vec![246u8, 245, 245, 245, 245, 245, 245, 245]
|
assert_eq!(serialize(&256i64), [0u8, 1, 0, 0, 0, 0, 0, 0]);
|
||||||
);
|
assert_eq!(serialize(&5000i64), [136u8, 19, 0, 0, 0, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&1i64), vec![1u8, 0, 0, 0, 0, 0, 0, 0]);
|
assert_eq!(serialize(&500000i64), [32u8, 161, 7, 0, 0, 0, 0, 0]);
|
||||||
assert_eq!(serialize(&256i64), vec![0u8, 1, 0, 0, 0, 0, 0, 0]);
|
assert_eq!(serialize(&723401728380766730i64), [10u8, 10, 10, 10, 10, 10, 10, 10]);
|
||||||
assert_eq!(serialize(&5000i64), vec![136u8, 19, 0, 0, 0, 0, 0, 0]);
|
|
||||||
assert_eq!(serialize(&500000i64), vec![32u8, 161, 7, 0, 0, 0, 0, 0]);
|
|
||||||
assert_eq!(serialize(&723401728380766730i64), vec![10u8, 10, 10, 10, 10, 10, 10, 10]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_varint_test() {
|
fn serialize_varint_test() {
|
||||||
assert_eq!(serialize(&VarInt(10)), vec![10u8]);
|
assert_eq!(serialize(&VarInt(10)), [10u8]);
|
||||||
assert_eq!(serialize(&VarInt(0xFC)), vec![0xFCu8]);
|
assert_eq!(serialize(&VarInt(0xFC)), [0xFCu8]);
|
||||||
assert_eq!(serialize(&VarInt(0xFD)), vec![0xFDu8, 0xFD, 0]);
|
assert_eq!(serialize(&VarInt(0xFD)), [0xFDu8, 0xFD, 0]);
|
||||||
assert_eq!(serialize(&VarInt(0xFFF)), vec![0xFDu8, 0xFF, 0xF]);
|
assert_eq!(serialize(&VarInt(0xFFF)), [0xFDu8, 0xFF, 0xF]);
|
||||||
assert_eq!(serialize(&VarInt(0xF0F0F0F)), vec![0xFEu8, 0xF, 0xF, 0xF, 0xF]);
|
assert_eq!(serialize(&VarInt(0xF0F0F0F)), [0xFEu8, 0xF, 0xF, 0xF, 0xF]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serialize(&VarInt(0xF0F0F0F0F0E0)),
|
serialize(&VarInt(0xF0F0F0F0F0E0)),
|
||||||
vec![0xFFu8, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0, 0]
|
[0xFFu8, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0, 0]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test_varint_encode(0xFF, &0x100000000_u64.to_le_bytes()).unwrap(),
|
test_varint_encode(0xFF, &0x100000000_u64.to_le_bytes()).unwrap(),
|
||||||
|
@ -1066,17 +1063,17 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_checkeddata_test() {
|
fn serialize_checkeddata_test() {
|
||||||
let cd = CheckedData::new(vec![1u8, 2, 3, 4, 5]);
|
let cd = CheckedData::new(vec![1u8, 2, 3, 4, 5]);
|
||||||
assert_eq!(serialize(&cd), vec![5, 0, 0, 0, 162, 107, 175, 90, 1, 2, 3, 4, 5]);
|
assert_eq!(serialize(&cd), [5, 0, 0, 0, 162, 107, 175, 90, 1, 2, 3, 4, 5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_vector_test() {
|
fn serialize_vector_test() {
|
||||||
assert_eq!(serialize(&vec![1u8, 2, 3]), vec![3u8, 1, 2, 3]);
|
assert_eq!(serialize(&vec![1u8, 2, 3]), [3u8, 1, 2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_strbuf_test() {
|
fn serialize_strbuf_test() {
|
||||||
assert_eq!(serialize(&"Andrew".to_string()), vec![6u8, 0x41, 0x6e, 0x64, 0x72, 0x65, 0x77]);
|
assert_eq!(serialize(&"Andrew".to_string()), [6u8, 0x41, 0x6e, 0x64, 0x72, 0x65, 0x77]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1682,7 +1682,7 @@ mod tests {
|
||||||
c.taproot_signature_hash(0, &empty_prevouts, None, None, TapSighashType::All),
|
c.taproot_signature_hash(0, &empty_prevouts, None, None, TapSighashType::All),
|
||||||
Err(TaprootError::PrevoutsSize(PrevoutsSizeError))
|
Err(TaprootError::PrevoutsSize(PrevoutsSizeError))
|
||||||
);
|
);
|
||||||
let two = vec![TxOut::NULL, TxOut::NULL];
|
let two = [TxOut::NULL, TxOut::NULL];
|
||||||
let too_many_prevouts = Prevouts::All(&two);
|
let too_many_prevouts = Prevouts::All(&two);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
c.taproot_signature_hash(0, &too_many_prevouts, None, None, TapSighashType::All),
|
c.taproot_signature_hash(0, &too_many_prevouts, None, None, TapSighashType::All),
|
||||||
|
@ -1967,7 +1967,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sighashtype_fromstr_display() {
|
fn sighashtype_fromstr_display() {
|
||||||
let sighashtypes = vec![
|
let sighashtypes = [
|
||||||
("SIGHASH_DEFAULT", TapSighashType::Default),
|
("SIGHASH_DEFAULT", TapSighashType::Default),
|
||||||
("SIGHASH_ALL", TapSighashType::All),
|
("SIGHASH_ALL", TapSighashType::All),
|
||||||
("SIGHASH_NONE", TapSighashType::None),
|
("SIGHASH_NONE", TapSighashType::None),
|
||||||
|
@ -1980,7 +1980,7 @@ mod tests {
|
||||||
assert_eq!(sht.to_string(), s);
|
assert_eq!(sht.to_string(), s);
|
||||||
assert_eq!(TapSighashType::from_str(s).unwrap(), sht);
|
assert_eq!(TapSighashType::from_str(s).unwrap(), sht);
|
||||||
}
|
}
|
||||||
let sht_mistakes = vec![
|
let sht_mistakes = [
|
||||||
"SIGHASH_ALL | SIGHASH_ANYONECANPAY",
|
"SIGHASH_ALL | SIGHASH_ANYONECANPAY",
|
||||||
"SIGHASH_NONE |SIGHASH_ANYONECANPAY",
|
"SIGHASH_NONE |SIGHASH_ANYONECANPAY",
|
||||||
"SIGHASH_SINGLE| SIGHASH_ANYONECANPAY",
|
"SIGHASH_SINGLE| SIGHASH_ANYONECANPAY",
|
||||||
|
|
|
@ -386,7 +386,7 @@ mod tests {
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn serde_roundtrip() {
|
fn serde_roundtrip() {
|
||||||
use Network::*;
|
use Network::*;
|
||||||
let tests = vec![
|
let tests = [
|
||||||
(Bitcoin, "bitcoin"),
|
(Bitcoin, "bitcoin"),
|
||||||
(Testnet, "testnet"),
|
(Testnet, "testnet"),
|
||||||
(Signet, "signet"),
|
(Signet, "signet"),
|
||||||
|
|
|
@ -318,7 +318,7 @@ mod test {
|
||||||
address: [0, 0, 0, 0, 0, 0xffff, 0x0a00, 0x0001],
|
address: [0, 0, 0, 0, 0, 0xffff, 0x0a00, 0x0001],
|
||||||
port: 8333
|
port: 8333
|
||||||
}),
|
}),
|
||||||
vec![
|
[
|
||||||
1u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x0a, 0, 0, 1,
|
1u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x0a, 0, 0, 1,
|
||||||
0x20, 0x8d
|
0x20, 0x8d
|
||||||
]
|
]
|
||||||
|
|
|
@ -573,7 +573,7 @@ mod test {
|
||||||
let cmptblock = deserialize(&hex!("00000030d923ad36ff2d955abab07f8a0a6e813bc6e066b973e780c5e36674cad5d1cd1f6e265f2a17a0d35cbe701fe9d06e2c6324cfe135f6233e8b767bfa3fb4479b71115dc562ffff7f2006000000000000000000000000010002000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0302ee00ffffffff0100f9029500000000015100000000")).unwrap();
|
let cmptblock = deserialize(&hex!("00000030d923ad36ff2d955abab07f8a0a6e813bc6e066b973e780c5e36674cad5d1cd1f6e265f2a17a0d35cbe701fe9d06e2c6324cfe135f6233e8b767bfa3fb4479b71115dc562ffff7f2006000000000000000000000000010002000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0302ee00ffffffff0100f9029500000000015100000000")).unwrap();
|
||||||
let blocktxn = deserialize(&hex!("2e93c0cff39ff605020072d96bc3a8d20b8447e294d08092351c8583e08d9b5a01020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0402dc0000ffffffff0200f90295000000001976a9142b4569203694fc997e13f2c0a1383b9e16c77a0d88ac0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000")).unwrap();
|
let blocktxn = deserialize(&hex!("2e93c0cff39ff605020072d96bc3a8d20b8447e294d08092351c8583e08d9b5a01020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0402dc0000ffffffff0200f90295000000001976a9142b4569203694fc997e13f2c0a1383b9e16c77a0d88ac0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000")).unwrap();
|
||||||
|
|
||||||
let msgs = vec![
|
let msgs = [
|
||||||
NetworkMessage::Version(version_msg),
|
NetworkMessage::Version(version_msg),
|
||||||
NetworkMessage::Verack,
|
NetworkMessage::Verack,
|
||||||
NetworkMessage::Addr(vec![(
|
NetworkMessage::Addr(vec![(
|
||||||
|
@ -685,7 +685,7 @@ mod test {
|
||||||
|
|
||||||
// Test serializing.
|
// Test serializing.
|
||||||
let cs = CommandString("Andrew".into());
|
let cs = CommandString("Andrew".into());
|
||||||
assert_eq!(serialize(&cs), vec![0x41u8, 0x6e, 0x64, 0x72, 0x65, 0x77, 0, 0, 0, 0, 0, 0]);
|
assert_eq!(serialize(&cs), [0x41u8, 0x6e, 0x64, 0x72, 0x65, 0x77, 0, 0, 0, 0, 0, 0]);
|
||||||
|
|
||||||
// Test deserializing
|
// Test deserializing
|
||||||
let cs: Result<CommandString, _> =
|
let cs: Result<CommandString, _> =
|
||||||
|
@ -703,7 +703,7 @@ mod test {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_verack_test() {
|
fn serialize_verack_test() {
|
||||||
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::Verack)),
|
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::Verack)),
|
||||||
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x61,
|
[0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x61,
|
||||||
0x63, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x63, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
||||||
}
|
}
|
||||||
|
@ -712,7 +712,7 @@ mod test {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_ping_test() {
|
fn serialize_ping_test() {
|
||||||
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::Ping(100))),
|
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::Ping(100))),
|
||||||
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x70, 0x69, 0x6e, 0x67,
|
[0xf9, 0xbe, 0xb4, 0xd9, 0x70, 0x69, 0x6e, 0x67,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
|
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
|
||||||
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
||||||
|
@ -722,7 +722,7 @@ mod test {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_mempool_test() {
|
fn serialize_mempool_test() {
|
||||||
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::MemPool)),
|
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::MemPool)),
|
||||||
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x6d, 0x65, 0x6d, 0x70,
|
[0xf9, 0xbe, 0xb4, 0xd9, 0x6d, 0x65, 0x6d, 0x70,
|
||||||
0x6f, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x6f, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
||||||
}
|
}
|
||||||
|
@ -731,7 +731,7 @@ mod test {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_getaddr_test() {
|
fn serialize_getaddr_test() {
|
||||||
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::GetAddr)),
|
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::GetAddr)),
|
||||||
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x67, 0x65, 0x74, 0x61,
|
[0xf9, 0xbe, 0xb4, 0xd9, 0x67, 0x65, 0x74, 0x61,
|
||||||
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1682,7 +1682,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn u256_is_max_correct_negative() {
|
fn u256_is_max_correct_negative() {
|
||||||
let tc = vec![U256::ZERO, U256::ONE, U256::from(u128::MAX)];
|
let tc = [U256::ZERO, U256::ONE, U256::from(u128::MAX)];
|
||||||
for t in tc {
|
for t in tc {
|
||||||
assert!(!t.is_max())
|
assert!(!t.is_max())
|
||||||
}
|
}
|
||||||
|
@ -1847,7 +1847,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn target_from_compact() {
|
fn target_from_compact() {
|
||||||
// (nBits, target)
|
// (nBits, target)
|
||||||
let tests = vec![
|
let tests = [
|
||||||
(0x0100_3456_u32, 0x00_u64), // High bit set.
|
(0x0100_3456_u32, 0x00_u64), // High bit set.
|
||||||
(0x0112_3456_u32, 0x12_u64),
|
(0x0112_3456_u32, 0x12_u64),
|
||||||
(0x0200_8000_u32, 0x80_u64),
|
(0x0200_8000_u32, 0x80_u64),
|
||||||
|
@ -1930,7 +1930,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn work_log2() {
|
fn work_log2() {
|
||||||
// Compare work log2 to historical Bitcoin Core values found in Core logs.
|
// Compare work log2 to historical Bitcoin Core values found in Core logs.
|
||||||
let tests: Vec<(u128, f64)> = vec![
|
let tests: [(u128, f64); 5] = [
|
||||||
// (chainwork, core log2) // height
|
// (chainwork, core log2) // height
|
||||||
(0x200020002, 33.000022), // 1
|
(0x200020002, 33.000022), // 1
|
||||||
(0xa97d67041c5e51596ee7, 79.405055), // 308004
|
(0xa97d67041c5e51596ee7, 79.405055), // 308004
|
||||||
|
|
|
@ -1705,7 +1705,7 @@ mod test {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let script_weights = vec![
|
let script_weights = [
|
||||||
(10, ScriptBuf::from_hex("51").unwrap()), // semantics of script don't matter for this test
|
(10, ScriptBuf::from_hex("51").unwrap()), // semantics of script don't matter for this test
|
||||||
(20, ScriptBuf::from_hex("52").unwrap()),
|
(20, ScriptBuf::from_hex("52").unwrap()),
|
||||||
(20, ScriptBuf::from_hex("53").unwrap()),
|
(20, ScriptBuf::from_hex("53").unwrap()),
|
||||||
|
|
|
@ -61,7 +61,7 @@ fn bip174_psbt_workflow() {
|
||||||
//
|
//
|
||||||
|
|
||||||
// Strings from BIP 174 test vector.
|
// Strings from BIP 174 test vector.
|
||||||
let test_vector = vec![
|
let test_vector = [
|
||||||
("cP53pDbR5WtAD8dYAW9hhTjuvvTVaEiQBdrz9XPrgLBeRFiyCbQr", "0h/0h/0h"), // from_priv, into_derivation_path?
|
("cP53pDbR5WtAD8dYAW9hhTjuvvTVaEiQBdrz9XPrgLBeRFiyCbQr", "0h/0h/0h"), // from_priv, into_derivation_path?
|
||||||
("cR6SXDoyfQrcp4piaiHE97Rsgta9mNhGTen9XeonVgwsh4iSgw6d", "0h/0h/2h"),
|
("cR6SXDoyfQrcp4piaiHE97Rsgta9mNhGTen9XeonVgwsh4iSgw6d", "0h/0h/2h"),
|
||||||
];
|
];
|
||||||
|
@ -76,7 +76,7 @@ fn bip174_psbt_workflow() {
|
||||||
//
|
//
|
||||||
|
|
||||||
// Strings from BIP 174 test vector.
|
// Strings from BIP 174 test vector.
|
||||||
let test_vector = vec![
|
let test_vector = [
|
||||||
("cT7J9YpCwY3AVRFSjN6ukeEeWY6mhpbJPxRaDaP5QTdygQRxP9Au", "0h/0h/1h"),
|
("cT7J9YpCwY3AVRFSjN6ukeEeWY6mhpbJPxRaDaP5QTdygQRxP9Au", "0h/0h/1h"),
|
||||||
("cNBc3SWUip9PPm1GjRoLEJT6T41iNzCYtD7qro84FMnM5zEqeJsE", "0h/0h/3h"),
|
("cNBc3SWUip9PPm1GjRoLEJT6T41iNzCYtD7qro84FMnM5zEqeJsE", "0h/0h/3h"),
|
||||||
];
|
];
|
||||||
|
@ -220,7 +220,7 @@ fn update_psbt(mut psbt: Psbt, fingerprint: Fingerprint) -> Psbt {
|
||||||
|
|
||||||
// Public key and its derivation path (these are the child pubkeys for our `Xpriv`,
|
// Public key and its derivation path (these are the child pubkeys for our `Xpriv`,
|
||||||
// can be verified by deriving the key using this derivation path).
|
// can be verified by deriving the key using this derivation path).
|
||||||
let pk_path = vec![
|
let pk_path = [
|
||||||
("029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f", "0h/0h/0h"),
|
("029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f", "0h/0h/0h"),
|
||||||
("02dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d7", "0h/0h/1h"),
|
("02dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d7", "0h/0h/1h"),
|
||||||
("03089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc", "0h/0h/2h"),
|
("03089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc", "0h/0h/2h"),
|
||||||
|
|
|
@ -132,7 +132,7 @@ fn serde_regression_witness() {
|
||||||
let w0 = Vec::from_hex("03d2e15674941bad4a996372cb87e1856d3652606d98562fe39c5e9e7e413f2105")
|
let w0 = Vec::from_hex("03d2e15674941bad4a996372cb87e1856d3652606d98562fe39c5e9e7e413f2105")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let w1 = Vec::from_hex("000000").unwrap();
|
let w1 = Vec::from_hex("000000").unwrap();
|
||||||
let vec = vec![w0, w1];
|
let vec = [w0, w1];
|
||||||
let witness = Witness::from_slice(&vec);
|
let witness = Witness::from_slice(&vec);
|
||||||
|
|
||||||
let got = serialize(&witness).unwrap();
|
let got = serialize(&witness).unwrap();
|
||||||
|
|
|
@ -57,16 +57,16 @@ mod tests {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: Vec<u8>,
|
input: [u8; 65],
|
||||||
output: Vec<u8>,
|
output: [u8; 20],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Uncompressed pubkey obtained from Bitcoin key; data from validateaddress
|
// Uncompressed pubkey obtained from Bitcoin key; data from validateaddress
|
||||||
Test {
|
Test {
|
||||||
input: vec![
|
input: [
|
||||||
0x04, 0xa1, 0x49, 0xd7, 0x6c, 0x5d, 0xe2, 0x7a, 0x2d,
|
0x04, 0xa1, 0x49, 0xd7, 0x6c, 0x5d, 0xe2, 0x7a, 0x2d,
|
||||||
0xdb, 0xfa, 0xa1, 0x24, 0x6c, 0x4a, 0xdc, 0xd2, 0xb6,
|
0xdb, 0xfa, 0xa1, 0x24, 0x6c, 0x4a, 0xdc, 0xd2, 0xb6,
|
||||||
0xf7, 0xaa, 0x29, 0x54, 0xc2, 0xe2, 0x53, 0x03, 0xf5,
|
0xf7, 0xaa, 0x29, 0x54, 0xc2, 0xe2, 0x53, 0x03, 0xf5,
|
||||||
|
@ -76,7 +76,7 @@ mod tests {
|
||||||
0x81, 0x64, 0xcc, 0xf9, 0x82, 0xa1, 0x38, 0x69, 0x1a,
|
0x81, 0x64, 0xcc, 0xf9, 0x82, 0xa1, 0x38, 0x69, 0x1a,
|
||||||
0x55, 0x19,
|
0x55, 0x19,
|
||||||
],
|
],
|
||||||
output: vec![
|
output: [
|
||||||
0xda, 0x0b, 0x34, 0x52, 0xb0, 0x6f, 0xe3, 0x41,
|
0xda, 0x0b, 0x34, 0x52, 0xb0, 0x6f, 0xe3, 0x41,
|
||||||
0x62, 0x6a, 0xd0, 0x94, 0x9c, 0x18, 0x3f, 0xbd,
|
0x62, 0x6a, 0xd0, 0x94, 0x9c, 0x18, 0x3f, 0xbd,
|
||||||
0xa5, 0x67, 0x68, 0x26,
|
0xa5, 0x67, 0x68, 0x26,
|
||||||
|
|
|
@ -169,21 +169,21 @@ mod tests {
|
||||||
use crate::{sha256, GeneralHash as _, Hash as _, HashEngine, Hmac, HmacEngine};
|
use crate::{sha256, GeneralHash as _, Hash as _, HashEngine, Hmac, HmacEngine};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test<'a> {
|
||||||
key: Vec<u8>,
|
key: &'a [u8],
|
||||||
input: Vec<u8>,
|
input: &'a [u8],
|
||||||
output: Vec<u8>,
|
output: &'a [u8],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Test vectors copied from libsecp256k1
|
// Test vectors copied from libsecp256k1
|
||||||
// Sadly the RFC2104 test vectors all use MD5 as their underlying hash function,
|
// Sadly the RFC2104 test vectors all use MD5 as their underlying hash function,
|
||||||
// which of course this library does not support.
|
// which of course this library does not support.
|
||||||
Test {
|
Test {
|
||||||
key: vec![ 0x0b; 20],
|
key: &[ 0x0b; 20],
|
||||||
input: vec![0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65],
|
input: &[0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65],
|
||||||
output: vec![
|
output: &[
|
||||||
0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
|
0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
|
||||||
0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
|
0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
|
||||||
0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
|
0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
|
||||||
|
@ -191,14 +191,14 @@ mod tests {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
key: vec![ 0x4a, 0x65, 0x66, 0x65 ],
|
key: &[ 0x4a, 0x65, 0x66, 0x65 ],
|
||||||
input: vec![
|
input: &[
|
||||||
0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20,
|
0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20,
|
||||||
0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20,
|
0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20,
|
||||||
0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68,
|
0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68,
|
||||||
0x69, 0x6e, 0x67, 0x3f,
|
0x69, 0x6e, 0x67, 0x3f,
|
||||||
],
|
],
|
||||||
output: vec![
|
output: &[
|
||||||
0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
|
0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
|
||||||
0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
|
0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
|
||||||
0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
|
0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
|
||||||
|
@ -206,9 +206,9 @@ mod tests {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
key: vec![ 0xaa; 20 ],
|
key: &[ 0xaa; 20 ],
|
||||||
input: vec![ 0xdd; 50 ],
|
input: &[ 0xdd; 50 ],
|
||||||
output: vec![
|
output: &[
|
||||||
0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46,
|
0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46,
|
||||||
0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7,
|
0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7,
|
||||||
0x29, 0x59, 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22,
|
0x29, 0x59, 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22,
|
||||||
|
@ -216,14 +216,14 @@ mod tests {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
key: vec![
|
key: &[
|
||||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
||||||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
||||||
0x19
|
0x19
|
||||||
],
|
],
|
||||||
input: vec![ 0xcd; 50 ],
|
input: &[ 0xcd; 50 ],
|
||||||
output: vec![
|
output: &[
|
||||||
0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e,
|
0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e,
|
||||||
0xa4, 0xcc, 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a,
|
0xa4, 0xcc, 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a,
|
||||||
0x85, 0xf0, 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07,
|
0x85, 0xf0, 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07,
|
||||||
|
@ -231,8 +231,8 @@ mod tests {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
key: vec! [ 0xaa; 131 ],
|
key: &[ 0xaa; 131 ],
|
||||||
input: vec![
|
input: &[
|
||||||
0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x73, 0x69,
|
0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x73, 0x69,
|
||||||
0x6e, 0x67, 0x20, 0x4c, 0x61, 0x72, 0x67, 0x65,
|
0x6e, 0x67, 0x20, 0x4c, 0x61, 0x72, 0x67, 0x65,
|
||||||
0x72, 0x20, 0x54, 0x68, 0x61, 0x6e, 0x20, 0x42,
|
0x72, 0x20, 0x54, 0x68, 0x61, 0x6e, 0x20, 0x42,
|
||||||
|
@ -241,7 +241,7 @@ mod tests {
|
||||||
0x48, 0x61, 0x73, 0x68, 0x20, 0x4b, 0x65, 0x79,
|
0x48, 0x61, 0x73, 0x68, 0x20, 0x4b, 0x65, 0x79,
|
||||||
0x20, 0x46, 0x69, 0x72, 0x73, 0x74,
|
0x20, 0x46, 0x69, 0x72, 0x73, 0x74,
|
||||||
],
|
],
|
||||||
output: vec![
|
output: &[
|
||||||
0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f,
|
0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f,
|
||||||
0x0d, 0x8a, 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f,
|
0x0d, 0x8a, 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f,
|
||||||
0x8e, 0x0b, 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14,
|
0x8e, 0x0b, 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14,
|
||||||
|
@ -249,8 +249,8 @@ mod tests {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
key: vec! [ 0xaa; 131 ],
|
key: &[ 0xaa; 131 ],
|
||||||
input: vec![
|
input: &[
|
||||||
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
|
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
|
||||||
0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x75,
|
0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x75,
|
||||||
0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x6c,
|
0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x6c,
|
||||||
|
@ -271,7 +271,7 @@ mod tests {
|
||||||
0x20, 0x48, 0x4d, 0x41, 0x43, 0x20, 0x61, 0x6c,
|
0x20, 0x48, 0x4d, 0x41, 0x43, 0x20, 0x61, 0x6c,
|
||||||
0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x2e,
|
0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x2e,
|
||||||
],
|
],
|
||||||
output: vec![
|
output: &[
|
||||||
0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb,
|
0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb,
|
||||||
0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44,
|
0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44,
|
||||||
0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93,
|
0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93,
|
||||||
|
@ -281,11 +281,11 @@ mod tests {
|
||||||
];
|
];
|
||||||
|
|
||||||
for test in tests {
|
for test in tests {
|
||||||
let mut engine = HmacEngine::<sha256::Hash>::new(&test.key);
|
let mut engine = HmacEngine::<sha256::Hash>::new(test.key);
|
||||||
engine.input(&test.input);
|
engine.input(test.input);
|
||||||
let hash = Hmac::<sha256::Hash>::from_engine(engine);
|
let hash = Hmac::<sha256::Hash>::from_engine(engine);
|
||||||
assert_eq!(hash.as_ref(), &test.output[..]);
|
assert_eq!(hash.as_ref(), test.output);
|
||||||
assert_eq!(hash.as_byte_array(), test.output.as_slice());
|
assert_eq!(hash.as_byte_array(), test.output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,23 +413,21 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
fn test() {
|
fn test() {
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
use crate::{ripemd160, HashEngine};
|
use crate::{ripemd160, HashEngine};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: &'static str,
|
input: &'static str,
|
||||||
output: Vec<u8>,
|
output: [u8; 20],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Test messages from FIPS 180-1
|
// Test messages from FIPS 180-1
|
||||||
Test {
|
Test {
|
||||||
input: "abc",
|
input: "abc",
|
||||||
output: vec![
|
output: [
|
||||||
0x8e, 0xb2, 0x08, 0xf7,
|
0x8e, 0xb2, 0x08, 0xf7,
|
||||||
0xe0, 0x5d, 0x98, 0x7a,
|
0xe0, 0x5d, 0x98, 0x7a,
|
||||||
0x9b, 0x04, 0x4a, 0x8e,
|
0x9b, 0x04, 0x4a, 0x8e,
|
||||||
|
@ -441,7 +439,7 @@ mod tests {
|
||||||
Test {
|
Test {
|
||||||
input:
|
input:
|
||||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||||
output: vec![
|
output: [
|
||||||
0x12, 0xa0, 0x53, 0x38,
|
0x12, 0xa0, 0x53, 0x38,
|
||||||
0x4a, 0x9c, 0x0c, 0x88,
|
0x4a, 0x9c, 0x0c, 0x88,
|
||||||
0xe4, 0x05, 0xa0, 0x6c,
|
0xe4, 0x05, 0xa0, 0x6c,
|
||||||
|
@ -453,7 +451,7 @@ mod tests {
|
||||||
// Examples from wikipedia
|
// Examples from wikipedia
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy dog",
|
input: "The quick brown fox jumps over the lazy dog",
|
||||||
output: vec![
|
output: [
|
||||||
0x37, 0xf3, 0x32, 0xf6,
|
0x37, 0xf3, 0x32, 0xf6,
|
||||||
0x8d, 0xb7, 0x7b, 0xd9,
|
0x8d, 0xb7, 0x7b, 0xd9,
|
||||||
0xd7, 0xed, 0xd4, 0x96,
|
0xd7, 0xed, 0xd4, 0x96,
|
||||||
|
@ -464,7 +462,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy cog",
|
input: "The quick brown fox jumps over the lazy cog",
|
||||||
output: vec![
|
output: [
|
||||||
0x13, 0x20, 0x72, 0xdf,
|
0x13, 0x20, 0x72, 0xdf,
|
||||||
0x69, 0x09, 0x33, 0x83,
|
0x69, 0x09, 0x33, 0x83,
|
||||||
0x5e, 0xb8, 0xb6, 0xad,
|
0x5e, 0xb8, 0xb6, 0xad,
|
||||||
|
@ -481,18 +479,8 @@ mod tests {
|
||||||
assert_eq!(hash, test.output_str.parse::<ripemd160::Hash>().expect("parse hex"));
|
assert_eq!(hash, test.output_str.parse::<ripemd160::Hash>().expect("parse hex"));
|
||||||
assert_eq!(&hash[..], &test.output[..]);
|
assert_eq!(&hash[..], &test.output[..]);
|
||||||
assert_eq!(&hash.to_string(), &test.output_str);
|
assert_eq!(&hash.to_string(), &test.output_str);
|
||||||
assert_eq!(
|
assert_eq!(ripemd160::Hash::from_bytes_ref(&test.output), &hash);
|
||||||
ripemd160::Hash::from_bytes_ref(
|
assert_eq!(ripemd160::Hash::from_bytes_mut(&mut test.output), &hash);
|
||||||
<&[u8; 20]>::try_from(&*test.output).expect("known length")
|
|
||||||
),
|
|
||||||
&hash
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
ripemd160::Hash::from_bytes_mut(
|
|
||||||
<&mut [u8; 20]>::try_from(&mut *test.output).expect("known length")
|
|
||||||
),
|
|
||||||
&hash
|
|
||||||
);
|
|
||||||
|
|
||||||
// Hash through engine, checking that we can input byte by byte
|
// Hash through engine, checking that we can input byte by byte
|
||||||
let mut engine = ripemd160::Hash::engine();
|
let mut engine = ripemd160::Hash::engine();
|
||||||
|
|
|
@ -137,16 +137,16 @@ mod tests {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: &'static str,
|
input: &'static str,
|
||||||
output: Vec<u8>,
|
output: [u8; 20],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Examples from wikipedia
|
// Examples from wikipedia
|
||||||
Test {
|
Test {
|
||||||
input: "",
|
input: "",
|
||||||
output: vec![
|
output: [
|
||||||
0xda, 0x39, 0xa3, 0xee,
|
0xda, 0x39, 0xa3, 0xee,
|
||||||
0x5e, 0x6b, 0x4b, 0x0d,
|
0x5e, 0x6b, 0x4b, 0x0d,
|
||||||
0x32, 0x55, 0xbf, 0xef,
|
0x32, 0x55, 0xbf, 0xef,
|
||||||
|
@ -157,7 +157,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy dog",
|
input: "The quick brown fox jumps over the lazy dog",
|
||||||
output: vec![
|
output: [
|
||||||
0x2f, 0xd4, 0xe1, 0xc6,
|
0x2f, 0xd4, 0xe1, 0xc6,
|
||||||
0x7a, 0x2d, 0x28, 0xfc,
|
0x7a, 0x2d, 0x28, 0xfc,
|
||||||
0xed, 0x84, 0x9e, 0xe1,
|
0xed, 0x84, 0x9e, 0xe1,
|
||||||
|
@ -168,7 +168,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy cog",
|
input: "The quick brown fox jumps over the lazy cog",
|
||||||
output: vec![
|
output: [
|
||||||
0xde, 0x9f, 0x2c, 0x7f,
|
0xde, 0x9f, 0x2c, 0x7f,
|
||||||
0xd2, 0x5e, 0x1b, 0x3a,
|
0xd2, 0x5e, 0x1b, 0x3a,
|
||||||
0xfa, 0xd3, 0xe8, 0x5a,
|
0xfa, 0xd3, 0xe8, 0x5a,
|
||||||
|
|
|
@ -877,16 +877,16 @@ mod tests {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: &'static str,
|
input: &'static str,
|
||||||
output: Vec<u8>,
|
output: [u8; 32],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Examples from wikipedia
|
// Examples from wikipedia
|
||||||
Test {
|
Test {
|
||||||
input: "",
|
input: "",
|
||||||
output: vec![
|
output: [
|
||||||
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
|
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
|
||||||
0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
|
0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
|
||||||
0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
|
0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
|
||||||
|
@ -896,7 +896,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy dog",
|
input: "The quick brown fox jumps over the lazy dog",
|
||||||
output: vec![
|
output: [
|
||||||
0xd7, 0xa8, 0xfb, 0xb3, 0x07, 0xd7, 0x80, 0x94,
|
0xd7, 0xa8, 0xfb, 0xb3, 0x07, 0xd7, 0x80, 0x94,
|
||||||
0x69, 0xca, 0x9a, 0xbc, 0xb0, 0x08, 0x2e, 0x4f,
|
0x69, 0xca, 0x9a, 0xbc, 0xb0, 0x08, 0x2e, 0x4f,
|
||||||
0x8d, 0x56, 0x51, 0xe4, 0x6d, 0x3c, 0xdb, 0x76,
|
0x8d, 0x56, 0x51, 0xe4, 0x6d, 0x3c, 0xdb, 0x76,
|
||||||
|
@ -906,7 +906,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy dog.",
|
input: "The quick brown fox jumps over the lazy dog.",
|
||||||
output: vec![
|
output: [
|
||||||
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7,
|
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7,
|
||||||
0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97,
|
0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97,
|
||||||
0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2,
|
0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2,
|
||||||
|
@ -987,15 +987,15 @@ mod tests {
|
||||||
|
|
||||||
// Initializing an engine with midstate from another engine should result in
|
// Initializing an engine with midstate from another engine should result in
|
||||||
// both engines producing the same hashes
|
// both engines producing the same hashes
|
||||||
let data_vec = vec![vec![3; 1], vec![4; 63], vec![5; 65], vec![6; 66]];
|
let data_vec: &[&[u8]] = &[&[3u8; 1], &[4u8; 63], &[5u8; 65], &[6u8; 66]];
|
||||||
for data in data_vec {
|
for data in data_vec {
|
||||||
let mut engine = engine.clone();
|
let mut engine = engine.clone();
|
||||||
let mut midstate_engine =
|
let mut midstate_engine =
|
||||||
sha256::HashEngine::from_midstate(engine.midstate_unchecked());
|
sha256::HashEngine::from_midstate(engine.midstate_unchecked());
|
||||||
assert_eq!(engine.h, midstate_engine.h);
|
assert_eq!(engine.h, midstate_engine.h);
|
||||||
assert_eq!(engine.length, midstate_engine.length);
|
assert_eq!(engine.length, midstate_engine.length);
|
||||||
engine.input(&data);
|
engine.input(data);
|
||||||
midstate_engine.input(&data);
|
midstate_engine.input(data);
|
||||||
assert_eq!(engine.h, midstate_engine.h);
|
assert_eq!(engine.h, midstate_engine.h);
|
||||||
let hash1 = sha256::Hash::from_engine(engine);
|
let hash1 = sha256::Hash::from_engine(engine);
|
||||||
let hash2 = sha256::Hash::from_engine(midstate_engine);
|
let hash2 = sha256::Hash::from_engine(midstate_engine);
|
||||||
|
|
|
@ -53,16 +53,16 @@ mod tests {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: &'static str,
|
input: &'static str,
|
||||||
output: Vec<u8>,
|
output: [u8; 32],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Test vector copied out of rust-bitcoin
|
// Test vector copied out of rust-bitcoin
|
||||||
Test {
|
Test {
|
||||||
input: "",
|
input: "",
|
||||||
output: vec![
|
output: [
|
||||||
0x5d, 0xf6, 0xe0, 0xe2, 0x76, 0x13, 0x59, 0xd3,
|
0x5d, 0xf6, 0xe0, 0xe2, 0x76, 0x13, 0x59, 0xd3,
|
||||||
0x0a, 0x82, 0x75, 0x05, 0x8e, 0x29, 0x9f, 0xcc,
|
0x0a, 0x82, 0x75, 0x05, 0x8e, 0x29, 0x9f, 0xcc,
|
||||||
0x03, 0x81, 0x53, 0x45, 0x45, 0xf5, 0x5c, 0xf4,
|
0x03, 0x81, 0x53, 0x45, 0x45, 0xf5, 0x5c, 0xf4,
|
||||||
|
|
|
@ -50,16 +50,16 @@ mod tests {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: &'static str,
|
input: &'static str,
|
||||||
output: Vec<u8>,
|
output: [u8; 48],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Examples from go sha384 tests.
|
// Examples from go sha384 tests.
|
||||||
Test {
|
Test {
|
||||||
input: "",
|
input: "",
|
||||||
output: vec![
|
output: [
|
||||||
0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38,
|
0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38,
|
||||||
0x4c, 0xd9, 0x32, 0x7e, 0xb1, 0xb1, 0xe3, 0x6a,
|
0x4c, 0xd9, 0x32, 0x7e, 0xb1, 0xb1, 0xe3, 0x6a,
|
||||||
0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43,
|
0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43,
|
||||||
|
@ -71,7 +71,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "abcdef",
|
input: "abcdef",
|
||||||
output: vec![
|
output: [
|
||||||
0xc6, 0xa4, 0xc6, 0x5b, 0x22, 0x7e, 0x73, 0x87,
|
0xc6, 0xa4, 0xc6, 0x5b, 0x22, 0x7e, 0x73, 0x87,
|
||||||
0xb9, 0xc3, 0xe8, 0x39, 0xd4, 0x48, 0x69, 0xc4,
|
0xb9, 0xc3, 0xe8, 0x39, 0xd4, 0x48, 0x69, 0xc4,
|
||||||
0xcf, 0xca, 0x3e, 0xf5, 0x83, 0xde, 0xa6, 0x41,
|
0xcf, 0xca, 0x3e, 0xf5, 0x83, 0xde, 0xa6, 0x41,
|
||||||
|
@ -83,7 +83,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "Discard medicine more than two years old.",
|
input: "Discard medicine more than two years old.",
|
||||||
output: vec![
|
output: [
|
||||||
0x86, 0xf5, 0x8e, 0xc2, 0xd7, 0x4d, 0x1b, 0x7f,
|
0x86, 0xf5, 0x8e, 0xc2, 0xd7, 0x4d, 0x1b, 0x7f,
|
||||||
0x8e, 0xb0, 0xc2, 0xff, 0x09, 0x67, 0x31, 0x66,
|
0x8e, 0xb0, 0xc2, 0xff, 0x09, 0x67, 0x31, 0x66,
|
||||||
0x99, 0x63, 0x9e, 0x8d, 0x4e, 0xb1, 0x29, 0xde,
|
0x99, 0x63, 0x9e, 0x8d, 0x4e, 0xb1, 0x29, 0xde,
|
||||||
|
@ -95,7 +95,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977",
|
input: "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977",
|
||||||
output: vec![
|
output: [
|
||||||
0x72, 0x2d, 0x10, 0xc5, 0xde, 0x37, 0x1e, 0xc0,
|
0x72, 0x2d, 0x10, 0xc5, 0xde, 0x37, 0x1e, 0xc0,
|
||||||
0xc8, 0xc4, 0xb5, 0x24, 0x7a, 0xc8, 0xa5, 0xf1,
|
0xc8, 0xc4, 0xb5, 0x24, 0x7a, 0xc8, 0xa5, 0xf1,
|
||||||
0xd2, 0x40, 0xd6, 0x8c, 0x73, 0xf8, 0xda, 0x13,
|
0xd2, 0x40, 0xd6, 0x8c, 0x73, 0xf8, 0xda, 0x13,
|
||||||
|
@ -107,7 +107,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The major problem is with sendmail. -Mark Horton",
|
input: "The major problem is with sendmail. -Mark Horton",
|
||||||
output: vec![
|
output: [
|
||||||
0x5f, 0xf8, 0xe0, 0x75, 0xe4, 0x65, 0x64, 0x6e,
|
0x5f, 0xf8, 0xe0, 0x75, 0xe4, 0x65, 0x64, 0x6e,
|
||||||
0x7b, 0x73, 0xef, 0x36, 0xd8, 0x12, 0xc6, 0xe9,
|
0x7b, 0x73, 0xef, 0x36, 0xd8, 0x12, 0xc6, 0xe9,
|
||||||
0xf7, 0xd6, 0x0f, 0xa6, 0xea, 0x0e, 0x53, 0x3e,
|
0xf7, 0xd6, 0x0f, 0xa6, 0xea, 0x0e, 0x53, 0x3e,
|
||||||
|
|
|
@ -315,16 +315,16 @@ mod tests {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: &'static str,
|
input: &'static str,
|
||||||
output: Vec<u8>,
|
output: [u8; 64],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Test vectors computed with `sha512sum`
|
// Test vectors computed with `sha512sum`
|
||||||
Test {
|
Test {
|
||||||
input: "",
|
input: "",
|
||||||
output: vec![
|
output: [
|
||||||
0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd,
|
0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd,
|
||||||
0xf1, 0x54, 0x28, 0x50, 0xd6, 0x6d, 0x80, 0x07,
|
0xf1, 0x54, 0x28, 0x50, 0xd6, 0x6d, 0x80, 0x07,
|
||||||
0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc,
|
0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc,
|
||||||
|
@ -338,7 +338,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy dog",
|
input: "The quick brown fox jumps over the lazy dog",
|
||||||
output: vec![
|
output: [
|
||||||
0x07, 0xe5, 0x47, 0xd9, 0x58, 0x6f, 0x6a, 0x73,
|
0x07, 0xe5, 0x47, 0xd9, 0x58, 0x6f, 0x6a, 0x73,
|
||||||
0xf7, 0x3f, 0xba, 0xc0, 0x43, 0x5e, 0xd7, 0x69,
|
0xf7, 0x3f, 0xba, 0xc0, 0x43, 0x5e, 0xd7, 0x69,
|
||||||
0x51, 0x21, 0x8f, 0xb7, 0xd0, 0xc8, 0xd7, 0x88,
|
0x51, 0x21, 0x8f, 0xb7, 0xd0, 0xc8, 0xd7, 0x88,
|
||||||
|
@ -352,7 +352,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The quick brown fox jumps over the lazy dog.",
|
input: "The quick brown fox jumps over the lazy dog.",
|
||||||
output: vec![
|
output: [
|
||||||
0x91, 0xea, 0x12, 0x45, 0xf2, 0x0d, 0x46, 0xae,
|
0x91, 0xea, 0x12, 0x45, 0xf2, 0x0d, 0x46, 0xae,
|
||||||
0x9a, 0x03, 0x7a, 0x98, 0x9f, 0x54, 0xf1, 0xf7,
|
0x9a, 0x03, 0x7a, 0x98, 0x9f, 0x54, 0xf1, 0xf7,
|
||||||
0x90, 0xf0, 0xa4, 0x76, 0x07, 0xee, 0xb8, 0xa1,
|
0x90, 0xf0, 0xa4, 0x76, 0x07, 0xee, 0xb8, 0xa1,
|
||||||
|
|
|
@ -60,16 +60,16 @@ mod tests {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Test {
|
struct Test {
|
||||||
input: &'static str,
|
input: &'static str,
|
||||||
output: Vec<u8>,
|
output: [u8; 32],
|
||||||
output_str: &'static str,
|
output_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let tests = vec![
|
let tests = [
|
||||||
// Examples from go sha512/256 tests.
|
// Examples from go sha512/256 tests.
|
||||||
Test {
|
Test {
|
||||||
input: "",
|
input: "",
|
||||||
output: vec![
|
output: [
|
||||||
0xc6, 0x72, 0xb8, 0xd1, 0xef, 0x56, 0xed, 0x28,
|
0xc6, 0x72, 0xb8, 0xd1, 0xef, 0x56, 0xed, 0x28,
|
||||||
0xab, 0x87, 0xc3, 0x62, 0x2c, 0x51, 0x14, 0x06,
|
0xab, 0x87, 0xc3, 0x62, 0x2c, 0x51, 0x14, 0x06,
|
||||||
0x9b, 0xdd, 0x3a, 0xd7, 0xb8, 0xf9, 0x73, 0x74,
|
0x9b, 0xdd, 0x3a, 0xd7, 0xb8, 0xf9, 0x73, 0x74,
|
||||||
|
@ -79,7 +79,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "abcdef",
|
input: "abcdef",
|
||||||
output: vec![
|
output: [
|
||||||
0xe4, 0xfd, 0xcb, 0x11, 0xd1, 0xac, 0x14, 0xe6,
|
0xe4, 0xfd, 0xcb, 0x11, 0xd1, 0xac, 0x14, 0xe6,
|
||||||
0x98, 0x74, 0x3a, 0xcd, 0x88, 0x05, 0x17, 0x4c,
|
0x98, 0x74, 0x3a, 0xcd, 0x88, 0x05, 0x17, 0x4c,
|
||||||
0xea, 0x5d, 0xdc, 0x0d, 0x31, 0x2e, 0x3e, 0x47,
|
0xea, 0x5d, 0xdc, 0x0d, 0x31, 0x2e, 0x3e, 0x47,
|
||||||
|
@ -89,7 +89,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "Discard medicine more than two years old.",
|
input: "Discard medicine more than two years old.",
|
||||||
output: vec![
|
output: [
|
||||||
0x69, 0x0c, 0x8a, 0xd3, 0x91, 0x6c, 0xef, 0xd3,
|
0x69, 0x0c, 0x8a, 0xd3, 0x91, 0x6c, 0xef, 0xd3,
|
||||||
0xad, 0x29, 0x22, 0x6d, 0x98, 0x75, 0x96, 0x5e,
|
0xad, 0x29, 0x22, 0x6d, 0x98, 0x75, 0x96, 0x5e,
|
||||||
0x3e, 0xe9, 0xec, 0x0d, 0x44, 0x82, 0xea, 0xcc,
|
0x3e, 0xe9, 0xec, 0x0d, 0x44, 0x82, 0xea, 0xcc,
|
||||||
|
@ -99,7 +99,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977",
|
input: "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977",
|
||||||
output: vec![
|
output: [
|
||||||
0xb5, 0xba, 0xf7, 0x47, 0xc3, 0x07, 0xf9, 0x88,
|
0xb5, 0xba, 0xf7, 0x47, 0xc3, 0x07, 0xf9, 0x88,
|
||||||
0x49, 0xec, 0x88, 0x1c, 0xf0, 0xd4, 0x86, 0x05,
|
0x49, 0xec, 0x88, 0x1c, 0xf0, 0xd4, 0x86, 0x05,
|
||||||
0xae, 0x4e, 0xdd, 0x38, 0x63, 0x72, 0xae, 0xa9,
|
0xae, 0x4e, 0xdd, 0x38, 0x63, 0x72, 0xae, 0xa9,
|
||||||
|
@ -109,7 +109,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
input: "The major problem is with sendmail. -Mark Horton",
|
input: "The major problem is with sendmail. -Mark Horton",
|
||||||
output: vec![
|
output: [
|
||||||
0x53, 0xed, 0x5f, 0x9b, 0x5c, 0x0b, 0x67, 0x4a,
|
0x53, 0xed, 0x5f, 0x9b, 0x5c, 0x0b, 0x67, 0x4a,
|
||||||
0xc0, 0xf3, 0x42, 0x5d, 0x9f, 0x9a, 0x5d, 0x46,
|
0xc0, 0xf3, 0x42, 0x5d, 0x9f, 0x9a, 0x5d, 0x46,
|
||||||
0x26, 0x55, 0xb0, 0x7c, 0xc9, 0x0f, 0x5d, 0x0f,
|
0x26, 0x55, 0xb0, 0x7c, 0xc9, 0x0f, 0x5d, 0x0f,
|
||||||
|
|
Loading…
Reference in New Issue