more sql
This commit is contained in:
parent
056c111d88
commit
481a0644cb
5 changed files with 126 additions and 54 deletions
|
|
@ -108,6 +108,13 @@ module Hash_32 = struct
|
|||
let bin =
|
||||
let open Bin in
|
||||
map (bytes 32) of_octets to_octets
|
||||
|
||||
let caqti : t Caqti_type.t =
|
||||
let open Caqti_type in
|
||||
custom
|
||||
~encode:(fun v -> Ok (to_octets v))
|
||||
~decode:(fun v -> Ok (of_octets v))
|
||||
octets
|
||||
end
|
||||
|
||||
module Hash_64 = struct
|
||||
|
|
@ -125,51 +132,37 @@ module Hash_64 = struct
|
|||
let bin =
|
||||
let open Bin in
|
||||
map (bytes 64) of_octets to_octets
|
||||
|
||||
let caqti : t Caqti_type.t =
|
||||
let open Caqti_type in
|
||||
custom
|
||||
~encode:(fun v -> Ok (to_octets v))
|
||||
~decode:(fun v -> Ok (of_octets v))
|
||||
octets
|
||||
end
|
||||
|
||||
(* Hash over string + '\0' *)
|
||||
module Hash_32_cstr = struct
|
||||
type t = Digestif.SHA256.t
|
||||
include Hash_32
|
||||
|
||||
let hash s =
|
||||
let s = s ^ "\x00" in
|
||||
Digestif.SHA256.(digest_string s)
|
||||
|
||||
let of_octets s =
|
||||
match String.length s = 32 with
|
||||
| false -> Fmt.failwith "Hash.of_octets failure: data is not 32 bytes"
|
||||
| true -> Digestif.SHA256.of_raw_string s
|
||||
|
||||
let to_octets = Digestif.SHA256.to_raw_string
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
map (bytes 32) of_octets to_octets
|
||||
end
|
||||
|
||||
module Hash_64_cstr = struct
|
||||
type t = Digestif.SHA512.t
|
||||
include Hash_64
|
||||
|
||||
let hash s =
|
||||
let s = s ^ "\x00" in
|
||||
Digestif.SHA512.(digest_string s)
|
||||
|
||||
let of_octets s =
|
||||
match String.length s = 64 with
|
||||
| false -> Fmt.failwith "Hash.of_octets failure: data is not 64 bytes"
|
||||
| true -> Digestif.SHA512.of_raw_string s
|
||||
|
||||
let to_octets = Digestif.SHA512.to_raw_string
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
map (bytes 64) of_octets to_octets
|
||||
end
|
||||
|
||||
module type Hash_S = sig
|
||||
type t
|
||||
|
||||
val bin : t Bin.t
|
||||
val caqti : t Caqti_type.t
|
||||
val hash : string -> t
|
||||
val of_octets : string -> t
|
||||
val to_octets : t -> string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue