Define Magic newtype as `[u8; 4]`, not `u32`.

The magic value isn't a u32, it's a byte string, so specifying it as
such avoids ambiguity about endianness.
This commit is contained in:
Henry de Valence 2019-09-14 08:20:23 -07:00
parent 653758858c
commit f7c095278d
3 changed files with 4 additions and 4 deletions

View File

@ -9,7 +9,7 @@ pub const CURRENT_VERSION: Version = Version(170_007);
pub mod magics {
use super::*;
/// The production mainnet.
pub const MAINNET: Magic = Magic(0x6427e924);
pub const MAINNET: Magic = Magic([0x24, 0xe9, 0x27, 0x64]);
/// The testnet.
pub const TESTNET: Magic = Magic(0xbff91afa);
pub const TESTNET: Magic = Magic([0xfa, 0x1a, 0xf9, 0xbf]);
}

View File

@ -329,7 +329,7 @@ impl ZcashSerialization for Message {
};
// Write the header and then the body.
writer.write_u32::<LittleEndian>(magic.0)?;
writer.write_all(&magic.0)?;
writer.write_all(command)?;
writer.write_u32::<LittleEndian>(body.len() as u32)?;
writer.write_all(&Sha256dChecksum::from(&body[..]).0)?;

View File

@ -2,7 +2,7 @@
/// A magic number identifying the network.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Magic(pub u32);
pub struct Magic(pub [u8; 4]);
/// A protocol version number.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]