@@ -8,6 +8,7 @@ use core::{fmt, u32};
88use core:: { iter, str} ;
99use cranelift_entity:: { EntityRef , PrimaryMap } ;
1010use serde_derive:: { Deserialize , Serialize } ;
11+ use sha2:: { Digest , Sha256 } ;
1112
1213/// Description of where a function is located in the text section of a
1314/// compiled image.
@@ -28,6 +29,28 @@ impl FunctionLoc {
2829 }
2930}
3031
32+ /// The checksum of a Wasm binary.
33+ ///
34+ /// Allows for features requiring the exact same Wasm Module (e.g. deterministic replay)
35+ /// to verify that the binary used matches the one originally compiled.
36+ #[ derive( Copy , Clone , PartialEq , Eq , Ord , PartialOrd , Debug , Serialize , Deserialize ) ]
37+ pub struct WasmChecksum ( [ u8 ; 32 ] ) ;
38+
39+ impl WasmChecksum {
40+ /// Construct a [`WasmChecksum`] from the given wasm binary.
41+ pub fn from_binary ( bin : & [ u8 ] ) -> WasmChecksum {
42+ WasmChecksum ( Sha256 :: digest ( bin) . into ( ) )
43+ }
44+ }
45+
46+ impl core:: ops:: Deref for WasmChecksum {
47+ type Target = [ u8 ; 32 ] ;
48+
49+ fn deref ( & self ) -> & Self :: Target {
50+ & self . 0
51+ }
52+ }
53+
3154/// A builder for a `CompiledFunctionsTable`.
3255pub struct CompiledFunctionsTableBuilder {
3356 inner : CompiledFunctionsTable ,
@@ -546,8 +569,8 @@ pub struct CompiledModuleInfo {
546569 /// Sorted list, by function index, of names we have for this module.
547570 pub func_names : Vec < FunctionName > ,
548571
549- /// Checksum of the source Wasm binary from which this module was compiled
550- pub checksum : [ u8 ; 32 ] ,
572+ /// Checksum of the source Wasm binary from which this module was compiled.
573+ pub checksum : WasmChecksum ,
551574}
552575
553576/// The name of a function stored in the
0 commit comments