better module for BytesXX

This commit is contained in:
swrup 2026-02-26 16:20:20 +01:00
parent 6bd65561f8
commit 9372506c45
5 changed files with 61 additions and 13 deletions

View file

@ -33,16 +33,40 @@ open Aliases
let size_of_int32 = 4
module Bytes32 = struct
type t = string
module type BYTES = sig
type t
let bin = Bin.bytes 32
val of_octets : string -> (t, string) result
val to_octets : t -> string
val bin : t Bin.t
end
module Bytes64 = struct
module Bytes32 : BYTES = struct
let n = 32
type t = string
let bin = Bin.bytes 64
let of_octets s =
match String.length s = n with
| false -> Error "invalid bytes length"
| true -> Ok s
let to_octets = Fun.id
let bin = Bin.bytes n
end
module Bytes64 : BYTES = struct
let n = 64
type t = string
let of_octets s =
match String.length s = n with
| false -> Error "invalid bytes length"
| true -> Ok s
let to_octets = Fun.id
let bin = Bin.bytes n
end
module TransferSecretP = Bytes64