fix denomination hash
This commit is contained in:
parent
9c87aa63ea
commit
0b72705602
11 changed files with 106 additions and 55 deletions
|
|
@ -209,13 +209,12 @@ module RsaPublicKey = struct
|
|||
let of_octets = Binary_format_rsa.pub_of_octets
|
||||
let to_b32 t = B32.encode (to_octets t)
|
||||
|
||||
let jsont =
|
||||
let of_b32 s =
|
||||
let* s = B32.decode s in
|
||||
let+ v = of_octets s in
|
||||
v
|
||||
in
|
||||
Jsont.of_of_string ~kind:"RsaPublicKey" of_b32 ~enc:to_b32
|
||||
let of_b32 s =
|
||||
let* s = B32.decode s in
|
||||
let+ v = of_octets s in
|
||||
v
|
||||
|
||||
let jsont = Jsont.of_of_string ~kind:"RsaPublicKey" of_b32 ~enc:to_b32
|
||||
|
||||
let caqti : t Caqti_type.t =
|
||||
Caqti_type.custom
|
||||
|
|
@ -257,6 +256,63 @@ module RsaSignature = struct
|
|||
Jsont.of_of_string ~kind:"RsaSignature" of_b32 ~enc:to_b32
|
||||
end
|
||||
|
||||
module DenominationHash : sig
|
||||
type t
|
||||
|
||||
val bin : t Bin.t
|
||||
val caqti : t Caqti_type.t
|
||||
val jsont : t Jsont.t
|
||||
val hash_of_rsa : RsaPublicKey.t -> t
|
||||
val of_octets : string -> t
|
||||
val to_octets : t -> string
|
||||
val of_b32 : B32.t -> (t, string) result
|
||||
val to_b32 : t -> B32.t
|
||||
end = struct
|
||||
open Digestif
|
||||
|
||||
type t = SHA512.t
|
||||
|
||||
(* = GNUNET_CRYPTO_BSA_(RSA|CS) *)
|
||||
type cipher =
|
||||
| RSA
|
||||
| CS [@ocaml.warning "-37"]
|
||||
|
||||
let cipher_to_int32 = function RSA -> 1_l | CS -> 2_l
|
||||
|
||||
let hash_of_rsa pub =
|
||||
let age_mask = 0_l in
|
||||
let cipher = cipher_to_int32 RSA in
|
||||
let pub = RsaPublicKey.to_octets pub in
|
||||
let pub_len = String.length pub in
|
||||
let b = Bytes.create (2 + 2 + pub_len) in
|
||||
Bytes.set_int32_be b 0 age_mask;
|
||||
Bytes.set_int32_be b 2 cipher;
|
||||
Bytes.blit_string pub 0 b 4 pub_len;
|
||||
SHA512.(digest_bytes b)
|
||||
|
||||
let of_octets s =
|
||||
match SHA512.of_raw_string_opt s with
|
||||
| None -> Fmt.failwith "H64.of_octets failure"
|
||||
| Some t -> t
|
||||
|
||||
let to_octets = SHA512.to_raw_string
|
||||
let of_b32 s = Result.map of_octets (B32.decode s)
|
||||
let to_b32 t = B32.encode (to_octets t)
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
map (bytes 64) of_octets to_octets
|
||||
|
||||
let caqti =
|
||||
let open Caqti_type in
|
||||
custom
|
||||
~encode:(fun v -> Ok (to_octets v))
|
||||
~decode:(fun v -> Ok (of_octets v))
|
||||
octets
|
||||
|
||||
let jsont = Jsont.of_of_string ~kind:"DenominationHash" of_b32 ~enc:to_b32
|
||||
end
|
||||
|
||||
(* some type aliases, just for prettier .mli *)
|
||||
type eddsa_priv = EddsaPrivateKey.t
|
||||
type eddsa_pub = EddsaPublicKey.t
|
||||
|
|
@ -264,4 +320,4 @@ type eddsa_sig = EddsaSignature.t
|
|||
type rsa_priv = RsaPrivateKey.t
|
||||
type rsa_pub = RsaPublicKey.t
|
||||
type rsa_sig = RsaSignature.t
|
||||
type denom_hash = Hash.DenominationHash.t
|
||||
type denom_hash = DenominationHash.t
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue