123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133(*
* Copyright (c) 2013-2022 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduletypeS=sig(** Signature for digest hashes, inspired by Digestif. *)typet(** The type for digest hashes. *)valhash:((string->unit)->unit)->t(** Compute a deterministic store key from a sequence of strings. *)valshort_hash:t->int(** [short_hash h] is a small hash of [h], to be used for instance as the
`hash` function of an OCaml [Hashtbl]. *)valhash_size:int(** [hash_size] is the size of hash results, in bytes. *)valto_raw_string:t->string(** [to_raw_string t] is the raw sequence of bytes in [t] (of length
{!hash_size}). *)valunsafe_of_raw_string:string->t(** [unsafe_of_raw_string b] is the hash consisting of the raw sequence of
bytes [b].
{b Warning}: this function cannot guarantee that the supplied byte string
is a valid output of the hash process, so should only be used on strings
that are known to have been built with {!to_raw_string}. *)valshort_hash_substring:Bigstringaf.t->off:int->int(** [short_hash_substring t off] computes the short-hash of the raw hash data
contained in [t] at offset [off]. It has behaviour equivalent to:
{[
Bigstringaf.substring t ~off ~len:hash_size
|> unsafe_of_raw_string
|> short_hash
]}
but may be more efficient due to not needing to allocate an intermediate
[string]. *)(** {1 Value Types} *)valt:tType.t(** [t] is the value type for {!type-t}. *)endmoduletypeTyped=sigtypettypevaluevalhash:value->t(** Compute a deterministic store key from a string. *)valshort_hash:t->int(** [short_hash h] is a small hash of [h], to be used for instance as the
`hash` function of an OCaml [Hashtbl]. *)valhash_size:int(** [hash_size] is the size of hash results, in bytes. *)(** {1 Value Types} *)valt:tType.t(** [t] is the value type for {!type-t}. *)endmoduletypeSet=sigtypettypehashvalcreate:?initial_slots:int->unit->tvaladd:t->hash->[`Ok|`Duplicate]valmem:t->hash->boolendmoduletypeSigs=sigmoduletypeS=S(** Signature for hash values. *)moduletypeTyped=Typed(** Signature for typed hashes, where [hash] directly takes a value as
argument and incremental hashing is not possible. *)(** Digestif hashes. *)moduleMake(H:Digestif.S):Swithtypet=H.tmoduleMake_BLAKE2B(D:sigvaldigest_size:intend):SmoduleMake_BLAKE2S(D:sigvaldigest_size:intend):SmoduleSHA1:SmoduleRMD160:SmoduleSHA224:SmoduleSHA256:SmoduleSHA384:SmoduleSHA512:SmoduleBLAKE2B:SmoduleBLAKE2S:S(** v1 serialisation *)moduleV1(H:S):Swithtypet=H.t(** Typed hashes. *)moduleTyped(K:S)(V:Type.S):Typedwithtypet=K.tandtypevalue=V.tmoduleSet:sigmoduleMake(Hash:S):Setwithtypehash:=Hash.tmoduletypeS=Setendend