diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/concepts/Hash.ml | 5 | ||||
| -rw-r--r-- | lib/concepts/Hash.mli | 7 | ||||
| -rw-r--r-- | lib/kernel/Identity.ml | 7 | ||||
| -rw-r--r-- | lib/kernel/Identity.mli | 5 |
4 files changed, 22 insertions, 2 deletions
diff --git a/lib/concepts/Hash.ml b/lib/concepts/Hash.ml index 922851a..5f023fc 100644 --- a/lib/concepts/Hash.ml +++ b/lib/concepts/Hash.ml @@ -11,6 +11,11 @@ let hash_of_bytes bytes = Digestif.SHA256.digest_bytes bytes let hash_of_blob blob = Blob.bytes_of_blob blob |> Digestif.SHA256.digest_bytes +let hash_of_int i = + let b = Blob.create 8 in + Blob.set_int64_be b 0 (Int64.of_int i); + hash_of_blob b + let bytes_of_hash (h : hash) = Bytes.of_string (Digestif.SHA256.to_raw_string h) let blob_of_hash h = bytes_of_hash h |> Blob.blob_of_bytes diff --git a/lib/concepts/Hash.mli b/lib/concepts/Hash.mli index ca50406..256f3cd 100644 --- a/lib/concepts/Hash.mli +++ b/lib/concepts/Hash.mli @@ -4,12 +4,15 @@ type hash (** the size of a hash, in bytes *) val size : int -(** given a bag of bytes, compute it's hash *) +(** given a bag of bytes, compute its hash *) val hash_of_bytes : bytes -> hash -(** given a blob, compute it's hash *) +(** given a blob, compute its hash *) val hash_of_blob : Blob.t -> hash +(** given an int, compute its hash *) +val hash_of_int : int -> hash + (** given a hash, return a representation of it as a string (/not/ the usual hex representation!) *) val to_raw_string : hash -> string diff --git a/lib/kernel/Identity.ml b/lib/kernel/Identity.ml new file mode 100644 index 0000000..ce3d30c --- /dev/null +++ b/lib/kernel/Identity.ml @@ -0,0 +1,7 @@ +class type identity = object + method hash : Concepts.Hash.hash +end + +class of_id = object (self) + method hash = Oo.id self |> Concepts.Hash.hash_of_int +end diff --git a/lib/kernel/Identity.mli b/lib/kernel/Identity.mli new file mode 100644 index 0000000..cdf417c --- /dev/null +++ b/lib/kernel/Identity.mli @@ -0,0 +1,5 @@ +class type identity = object + method hash : Concepts.Hash.hash +end + +class of_id : identity |
