better module for BytesXX
This commit is contained in:
parent
6bd65561f8
commit
9372506c45
5 changed files with 61 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue