From 66ea301fc25a07485286560c434a9fdaf460c431 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Nov 2020 16:10:00 +0000 Subject: Untangle caching code --- dhall/src/syntax/ast/expr.rs | 5 ++--- dhall/src/syntax/ast/import.rs | 2 +- dhall/src/syntax/binary/decode.rs | 2 +- dhall/src/syntax/text/parser.rs | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index b1a978f..eba2735 100644 --- a/dhall/src/syntax/ast/expr.rs +++ b/dhall/src/syntax/ast/expr.rs @@ -178,10 +178,9 @@ impl Expr { } // Compute the sha256 hash of the binary form of the expression. - pub fn hash(&self) -> Result, Error> { - use sha2::Digest; + pub fn sha256_hash(&self) -> Result, Error> { let data = binary::encode(self)?; - Ok(sha2::Sha256::digest(&data).as_slice().into()) + Ok(crate::utils::sha256_hash(&data)) } } diff --git a/dhall/src/syntax/ast/import.rs b/dhall/src/syntax/ast/import.rs index c45fe51..69f4021 100644 --- a/dhall/src/syntax/ast/import.rs +++ b/dhall/src/syntax/ast/import.rs @@ -52,7 +52,7 @@ pub enum ImportMode { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Hash { - SHA256(Vec), + SHA256(Box<[u8]>), } /// Reference to an external resource diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs index f4747d3..4ea7d98 100644 --- a/dhall/src/syntax/binary/decode.rs +++ b/dhall/src/syntax/binary/decode.rs @@ -290,7 +290,7 @@ fn cbor_value_to_dhall(data: &Value) -> Result { Null => None, Bytes(bytes) => match bytes.as_slice() { [18, 32, rest @ ..] => { - Some(Hash::SHA256(rest.to_vec())) + Some(Hash::SHA256(rest.to_vec().into())) } _ => { return Err(DecodeError::WrongFormatError(format!( diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 37f28e5..07921b5 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -593,7 +593,7 @@ impl DhallParser { input.error(format!("Unknown hashing protocol '{}'", protocol)) ); } - Ok(Hash::SHA256(hex::decode(hash).unwrap())) + Ok(Hash::SHA256(hex::decode(hash).unwrap().into())) } fn import_hashed( -- cgit v1.2.3