rename cstring hashs

This commit is contained in:
swrup 2026-03-20 00:31:32 +01:00 committed by Swrup
parent 6e5b4fc179
commit e44748eb99
4 changed files with 56 additions and 61 deletions

View file

@ -16,7 +16,7 @@ module type S = sig
val to_b32 : t -> B32.t
end
module H32 = struct
module H32 : S = struct
type t = SHA256.t
let hash s = SHA256.(digest_string s)
@ -34,7 +34,7 @@ module H32 = struct
let open Bin in
map (bytes 32) of_octets to_octets
(* hashes are not b32 encoded in the database *)
(* hashs are not b32 encoded in the database *)
let caqti =
let open Caqti_type in
custom
@ -45,7 +45,7 @@ module H32 = struct
let jsont = Jsont.of_of_string ~kind:"Hash 32" of_b32 ~enc:to_b32
end
module H64 = struct
module H64 : S = struct
type t = SHA512.t
let hash s = SHA512.(digest_string s)
@ -63,7 +63,6 @@ module H64 = struct
let open Bin in
map (bytes 64) of_octets to_octets
(* hashes are not b32 encoded in the database *)
let caqti =
let open Caqti_type in
custom
@ -74,20 +73,16 @@ module H64 = struct
let jsont = Jsont.of_of_string ~kind:"Hash 64" of_b32 ~enc:to_b32
end
(* C-terminated strings
some strings need to be hashed with a '\0' termination char *)
module Cstring = struct
module H32 = struct
include H32
module H32_cstring : S = struct
include H32
let hash s = hash (s ^ "\x00")
end
let hash s = hash (s ^ "\x00")
end
module H64 = struct
include H64
module H64_cstring : S = struct
include H64
let hash s = hash (s ^ "\x00")
end
let hash s = hash (s ^ "\x00")
end
(* TODO

View file

@ -160,7 +160,7 @@ module Make (Conn : Pg.CONN) (Fs : Fat.FS) : S = struct
signf Sm_rsa.sign_secmod
{
h_denom_pub= h_pub;
h_section_name= Hash.Cstring.H64.hash section_name;
h_section_name= Hash.H64_cstring.hash section_name;
anchor_time= stamp_start;
duration_withdraw= Timestamp.diff stamp_start stamp_expire_withdraw;
}

View file

@ -108,7 +108,7 @@ module Auditors = struct
{
start_date= validity_start;
auditor_pub;
h_auditor_url= Hash.Cstring.H64.hash auditor_url;
h_auditor_url= Hash.H64_cstring.hash auditor_url;
}
let do_ ~db_conn v =
@ -204,7 +204,7 @@ module Wire_fee = struct
let open Signatures.MasterWireFee in
verify Config.master_public_key master_sig_wire
{
h_wire_method= Hash.Cstring.H64.hash wire_method;
h_wire_method= Hash.H64_cstring.hash wire_method;
start_date= fee_start;
end_date= fee_end;
wire_fee;
@ -320,10 +320,10 @@ module Wire = struct
in
let h_wire_details = Hash.FullPaytoHash.hash payto_uri in
let h_conversion_url =
Hash.Cstring.H64.hash ((* ?? *) Option.value ~default:"" conversion_url)
Hash.H64_cstring.hash ((* ?? *) Option.value ~default:"" conversion_url)
in
let h_credit_restrictions = Hash.Cstring.H64.hash "" in
let h_debit_restrictions = Hash.Cstring.H64.hash "" in
let h_credit_restrictions = Hash.H64_cstring.hash "" in
let h_debit_restrictions = Hash.H64_cstring.hash "" in
(* - *)
let* () =
let open Signatures.MasterWireDetails in
@ -466,7 +466,7 @@ module Drain = struct
wtid;
date;
amount;
h_section= Hash.Cstring.H64.hash debit_account_section;
h_section= Hash.H64_cstring.hash debit_account_section;
h_payto= FullPaytoHash.hash credit_payto_uri;
}
@ -515,7 +515,7 @@ module AmlOfficer = struct
{
change_date;
officer_pub;
h_officer_name= Hash.Cstring.H64.hash officer_name;
h_officer_name= Hash.H64_cstring.hash officer_name;
is_active;
}
@ -558,7 +558,7 @@ module Partners = struct
end_date;
wad_frequency;
wad_fee;
h_url= Hash.Cstring.H64.hash partner_base_url;
h_url= Hash.H64_cstring.hash partner_base_url;
}
let do_ ~db_conn v =

View file

@ -180,7 +180,7 @@ module DenominationKeyAnnouncement = struct
(* purpose = TALER_SIGNATURE_SM_RSA_DENOMINATION_KEY *)
type r = {
h_denom_pub: DenominationHash.t;
h_section_name: Hash.Cstring.H64.t;
h_section_name: Hash.H64_cstring.t;
anchor_time: Timestamp.t;
duration_withdraw: TimeRelative.t;
}
@ -195,7 +195,7 @@ module DenominationKeyAnnouncement = struct
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw })
|+ Purpose.field purpose
|+ field DenominationHash.bin (fun t -> t.h_denom_pub)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_section_name)
|+ field Hash.H64_cstring.bin (fun t -> t.h_section_name)
|+ field Timestamp.bin (fun t -> t.anchor_time)
|+ field TimeRelative.bin (fun t -> t.duration_withdraw)
|> sealr
@ -365,7 +365,7 @@ module MasterAddAuditor = struct
type r = {
start_date: Timestamp.t;
auditor_pub: AuditorPublicKeyP.t;
h_auditor_url: Hash.Cstring.H64.t;
h_auditor_url: Hash.H64_cstring.t;
}
let bin =
@ -376,7 +376,7 @@ module MasterAddAuditor = struct
|+ Purpose.field purpose
|+ field Timestamp.bin (fun t -> t.start_date)
|+ field AuditorPublicKeyP.bin (fun t -> t.auditor_pub)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_auditor_url)
|+ field Hash.H64_cstring.bin (fun t -> t.h_auditor_url)
|> sealr
end
@ -464,9 +464,9 @@ module MasterWireDetails = struct
(* purpose = TALER_SIGNATURE_MASTER_WIRE_DETAILS *)
type r = {
h_wire_details: FullPaytoHash.t;
h_conversion_url: Hash.Cstring.H64.t;
h_credit_restrictions: Hash.Cstring.H64.t;
h_debit_restrictions: Hash.Cstring.H64.t;
h_conversion_url: Hash.H64_cstring.t;
h_credit_restrictions: Hash.H64_cstring.t;
h_debit_restrictions: Hash.H64_cstring.t;
}
let bin =
@ -488,9 +488,9 @@ module MasterWireDetails = struct
})
|+ Purpose.field purpose
|+ field FullPaytoHash.bin (fun t -> t.h_wire_details)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_conversion_url)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_credit_restrictions)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_debit_restrictions)
|+ field Hash.H64_cstring.bin (fun t -> t.h_conversion_url)
|+ field Hash.H64_cstring.bin (fun t -> t.h_credit_restrictions)
|+ field Hash.H64_cstring.bin (fun t -> t.h_debit_restrictions)
|> sealr
end
@ -503,9 +503,9 @@ module MasterAddWire = struct
type r = {
start_date: Timestamp.t;
h_wire: FullPaytoHash.t;
h_conversion_url: Hash.Cstring.H64.t;
h_credit_restrictions: Hash.Cstring.H64.t;
h_debit_restrictions: Hash.Cstring.H64.t;
h_conversion_url: Hash.H64_cstring.t;
h_credit_restrictions: Hash.H64_cstring.t;
h_debit_restrictions: Hash.H64_cstring.t;
}
let bin =
@ -530,9 +530,9 @@ module MasterAddWire = struct
|+ Purpose.field _purpose
|+ field Timestamp.bin (fun t -> t.start_date)
|+ field FullPaytoHash.bin (fun t -> t.h_wire)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_conversion_url)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_credit_restrictions)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_debit_restrictions)
|+ field Hash.H64_cstring.bin (fun t -> t.h_conversion_url)
|+ field Hash.H64_cstring.bin (fun t -> t.h_credit_restrictions)
|+ field Hash.H64_cstring.bin (fun t -> t.h_debit_restrictions)
|> sealr
end
@ -567,7 +567,7 @@ module MasterDrainProfit = struct
wtid: WireTransferIdentifierRawP.t;
date: Timestamp.t;
amount: Amount.t;
h_section: Hash.Cstring.H64.t;
h_section: Hash.H64_cstring.t;
h_payto: FullPaytoHash.t;
}
@ -580,7 +580,7 @@ module MasterDrainProfit = struct
|+ field WireTransferIdentifierRawP.bin (fun t -> t.wtid)
|+ field Timestamp.bin (fun t -> t.date)
|+ field Amount.bin (fun t -> t.amount)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_section)
|+ field Hash.H64_cstring.bin (fun t -> t.h_section)
|+ field FullPaytoHash.bin (fun t -> t.h_payto)
|> sealr
end
@ -594,7 +594,7 @@ module MasterAmlOfficerStatus = struct
type r = {
change_date: Timestamp.t;
officer_pub: AmlOfficerPublicKeyP.t;
h_officer_name: Hash.Cstring.H64.t;
h_officer_name: Hash.H64_cstring.t;
is_active: int32;
}
@ -606,7 +606,7 @@ module MasterAmlOfficerStatus = struct
|+ Purpose.field _purpose
|+ field Timestamp.bin (fun t -> t.change_date)
|+ field AmlOfficerPublicKeyP.bin (fun t -> t.officer_pub)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_officer_name)
|+ field Hash.H64_cstring.bin (fun t -> t.h_officer_name)
|+ field beint32 (fun t -> t.is_active)
|> sealr
end
@ -623,7 +623,7 @@ module PartnerConfiguration = struct
end_date: Timestamp.t;
wad_frequency: TimeRelative.t;
wad_fee: Amount.t;
h_url: Hash.Cstring.H64.t;
h_url: Hash.H64_cstring.t;
}
let bin =
@ -646,7 +646,7 @@ module PartnerConfiguration = struct
|+ field Timestamp.bin (fun t -> t.end_date)
|+ field TimeRelative.bin (fun t -> t.wad_frequency)
|+ field Amount.bin (fun t -> t.wad_fee)
|+ field Hash.Cstring.H64.bin (fun t -> t.h_url)
|+ field Hash.H64_cstring.bin (fun t -> t.h_url)
|> sealr
end
@ -657,7 +657,7 @@ module WadPartnerSignature = struct
module R = struct
(* purpose = TALER_SIGNATURE_MASTER_PARTNER_DETAILS *)
type r = {
h_partner_base_url: Hash.Cstring.H64.t;
h_partner_base_url: Hash.H64_cstring.t;
master_public_key: MasterPublicKeyP.t;
start_date: Timestamp.t;
end_date: Timestamp.t;
@ -688,7 +688,7 @@ module WadPartnerSignature = struct
wad_frequency;
})
|+ Purpose.field _purpose
|+ field Hash.Cstring.H64.bin (fun t -> t.h_partner_base_url)
|+ field Hash.H64_cstring.bin (fun t -> t.h_partner_base_url)
|+ field MasterPublicKeyP.bin (fun t -> t.master_public_key)
|+ field Timestamp.bin (fun t -> t.start_date)
|+ field Timestamp.bin (fun t -> t.end_date)
@ -704,7 +704,7 @@ module MasterWireFee = struct
module R = struct
(* purpose = TALER_SIGNATURE_MASTER_WIRE_FEES *)
type r = {
h_wire_method: Hash.Cstring.H64.t;
h_wire_method: Hash.H64_cstring.t;
start_date: Timestamp.t;
end_date: Timestamp.t;
wire_fee: Amount.t;
@ -718,7 +718,7 @@ module MasterWireFee = struct
(fun _purpose h_wire_method start_date end_date wire_fee closing_fee ->
{ h_wire_method; start_date; end_date; wire_fee; closing_fee })
|+ Purpose.field _purpose
|+ field Hash.Cstring.H64.bin (fun t -> t.h_wire_method)
|+ field Hash.H64_cstring.bin (fun t -> t.h_wire_method)
|+ field Timestamp.bin (fun t -> t.start_date)
|+ field Timestamp.bin (fun t -> t.end_date)
|+ field Amount.bin (fun t -> t.wire_fee)
@ -733,7 +733,7 @@ module ExchangeKeyValidity = struct
module R = struct
(* purpose = TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS *)
type r = {
auditor_url_hash: Hash.Cstring.H64.t;
auditor_url_hash: Hash.H64_cstring.t;
master: MasterPublicKeyP.t;
start: Timestamp.t;
expire_withdraw: Timestamp.t;
@ -778,7 +778,7 @@ module ExchangeKeyValidity = struct
denom_hash;
})
|+ Purpose.field _purpose
|+ field Hash.Cstring.H64.bin (fun t -> t.auditor_url_hash)
|+ field Hash.H64_cstring.bin (fun t -> t.auditor_url_hash)
|+ field MasterPublicKeyP.bin (fun t -> t.master)
|+ field Timestamp.bin (fun t -> t.start)
|+ field Timestamp.bin (fun t -> t.expire_withdraw)
@ -887,7 +887,7 @@ module DepositRequest = struct
amount_with_fee: Amount.t;
deposit_fee: Amount.t;
merchant: MerchantPublicKeyP.t;
wallet_data_hash: Hash.Cstring.H64.t;
wallet_data_hash: Hash.H64_cstring.t;
}
end
@ -950,7 +950,7 @@ module WireDepositData = struct
wire_fee: Amount.t;
merchant_pub: MerchantPublicKeyP.t;
h_wire: MerchantWireHash.t;
h_details: Hash.Cstring.H64.t;
h_details: Hash.H64_cstring.t;
}
end
@ -1011,7 +1011,7 @@ end
module MerchantRefundConfirmation = struct
(* purpose = TALER_SIGNATURE_MERCHANT_REFUND_OK *)
(* Hash of the order ID (a string), hashed without the 0-termination. *)
type t = { h_order_id: Hash.Cstring.H64.t }
type t = { h_order_id: Hash.H64_cstring.t }
end
module RecoupRequest = struct
@ -1136,7 +1136,7 @@ module PurseDepositSignature = struct
h_denom_pub: DenominationHash.t;
h_age_commitment: AgeCommitmentHash.t;
purse_pub: PursePublicKey.t;
h_exchange_base_url: Hash.Cstring.H64.t;
h_exchange_base_url: Hash.H64_cstring.t;
}
end
@ -1203,7 +1203,7 @@ module WadDataSignature = struct
type t = {
wad_execution_time: Timestamp.t;
total_amount: Amount.t;
h_items: Hash.Cstring.H64.t;
h_items: Hash.H64_cstring.t;
wad_id: WadId.t;
}
end
@ -1236,11 +1236,11 @@ end
module AmlDecision = struct
(* purpose = TALER_SIGNATURE_AML_DECISION *)
type t = {
h_justification: Hash.Cstring.H64.t;
h_justification: Hash.H64_cstring.t;
decision_time: Timestamp.t;
new_threshold: Amount.t;
h_payto: NormalizedPaytoHash.t;
h_kyc_requirements: Hash.Cstring.H64.t;
h_kyc_requirements: Hash.H64_cstring.t;
new_state: int;
}
end
@ -1267,7 +1267,7 @@ module ReserveAttestRequest = struct
(* purpose = TALER_SIGNATURE_WALLET_ATTEST_REQUEST *)
type t = {
request_timestamp: Timestamp.t;
h_details: Hash.Cstring.H64.t;
h_details: Hash.H64_cstring.t;
}
end
@ -1277,6 +1277,6 @@ module ExchangeAttest = struct
attest_timestamp: Timestamp.t;
expiration_time: Timestamp.t;
reserve_pub: ReservePublicKeyP.t;
h_attributes: Hash.Cstring.H64.t;
h_attributes: Hash.H64_cstring.t;
}
end