From 4fe87bab1ee4b4ecb2ce12f6385a9c934491c4ea Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Mon, 5 Feb 2024 22:23:57 +0800 Subject: [PATCH] refactor(katana-primitives): remove base64 genesis prefix (#1518) --- crates/katana/primitives/src/genesis/json.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/crates/katana/primitives/src/genesis/json.rs b/crates/katana/primitives/src/genesis/json.rs index 193af90b41..c3df1aaf2a 100644 --- a/crates/katana/primitives/src/genesis/json.rs +++ b/crates/katana/primitives/src/genesis/json.rs @@ -495,30 +495,20 @@ pub fn resolve_artifacts_and_to_base64>( pub fn to_base64(genesis: GenesisJson) -> Result, GenesisJsonError> { let data = serde_json::to_vec(&genesis)?; - let mut buf = vec![b'b', b'a', b's', b'e', b'6', b'4', b':']; // make sure we'll have a slice big enough for base64 + padding - buf.resize((4 * data.len() / 3 + 4) + buf.len(), 0); + let mut buf = vec![0; (4 * data.len() / 3) + 4]; - let bytes_written = BASE64_STANDARD.encode_slice(data, &mut buf[7..])?; + let bytes_written = BASE64_STANDARD.encode_slice(data, &mut buf)?; // shorten the buffer to the actual length written - buf.truncate(bytes_written + 7); + buf.truncate(bytes_written); Ok(buf) } /// Deserialize the [GenesisJson] from base64 encoded bytes. pub fn from_base64(data: &[u8]) -> Result { - match data { - [b'b', b'a', b's', b'e', b'6', b'4', b':', rest @ ..] => { - let decoded = BASE64_STANDARD.decode(rest)?; - Ok(serde_json::from_slice::(&decoded)?) - } - - _ => { - let decoded = BASE64_STANDARD.decode(data)?; - Ok(serde_json::from_slice::(&decoded)?) - } - } + let decoded = BASE64_STANDARD.decode(data)?; + Ok(serde_json::from_slice::(&decoded)?) } fn class_artifact_at_path(