summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/ast
diff options
context:
space:
mode:
authorNadrieril2020-04-05 22:40:02 +0100
committerNadrieril2020-04-05 22:40:38 +0100
commitfc965361346461fbd52bb132caa874778d9fe913 (patch)
treed48a697de0491209a8ece2eaad1011e2dcb218fd /dhall/src/syntax/ast
parent251b378fd8d93ea625a739cde06675e2bbc32c2c (diff)
Check code hashes in import
Diffstat (limited to 'dhall/src/syntax/ast')
-rw-r--r--dhall/src/syntax/ast/expr.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 6ba6649..9e935dc 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;
+use crate::error::Error;
use crate::semantics::Universe;
use crate::syntax::map::{DupTreeMap, DupTreeSet};
use crate::syntax::visitor;
@@ -255,6 +256,13 @@ impl Expr {
span,
}
}
+
+ // Compute the sha256 hash of the binary form of the expression.
+ pub fn hash(&self) -> Result<Box<[u8]>, Error> {
+ use sha2::Digest;
+ let data = binary::encode(self)?;
+ Ok(sha2::Sha256::digest(&data).as_slice().into())
+ }
}
// Empty enum to indicate that no error can occur