From d1e3a6e91694659be34f4ffb82e5978893aa668c Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 29 Oct 2024 14:13:11 +0000 Subject: [PATCH] Chore: fix CI for v5-backports --- cohttp-async.opam | 2 +- examples/async/dune | 2 +- examples/async/s3_cp.ml | 29 +++++------------------------ 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/cohttp-async.opam b/cohttp-async.opam index 99e950b4e..1f0d88e1a 100644 --- a/cohttp-async.opam +++ b/cohttp-async.opam @@ -34,7 +34,7 @@ depends: [ "cohttp" {= version} "conduit-async" {>= "1.2.0"} "magic-mime" - "mirage-crypto" {with-test} + "digestif" {with-test} "logs" "fmt" {>= "0.8.2"} "sexplib0" diff --git a/examples/async/dune b/examples/async/dune index 8d875ddcb..9bda6f013 100644 --- a/examples/async/dune +++ b/examples/async/dune @@ -1,6 +1,6 @@ (executables (names hello_world receive_post s3_cp) - (libraries mirage-crypto cohttp-async base async_kernel core_unix.command_unix)) + (libraries digestif.c cohttp-async base async_kernel core_unix.command_unix)) (alias (name runtest) diff --git a/examples/async/s3_cp.ml b/examples/async/s3_cp.ml index 48a6f6482..74a1ae13e 100644 --- a/examples/async/s3_cp.ml +++ b/examples/async/s3_cp.ml @@ -83,18 +83,6 @@ module Compat = struct let x = Char.to_int c in (hexa.[x lsr 4], hexa.[x land 0xf]) - let cstruct_to_hex_string cs = - let open Cstruct in - let n = cs.len in - let buf = Buffer.create (n * 2) in - for i = 0 to n - 1 do - let c = cs.buffer.{cs.off + i} in - let x, y = of_char c in - Buffer.add_char buf x; - Buffer.add_char buf y - done; - Buffer.contents buf - let encode_query_string uri = (* Sort and encode query string. Note that AWS wants null keys to have '=' for all keys. @@ -170,8 +158,7 @@ module Auth = struct let digest s = (* string -> sha256 as a hex string *) - Mirage_crypto.Hash.(digest `SHA256 (Cstruct.of_string s)) - |> Compat.cstruct_to_hex_string + Digestif.SHA256.(digest_string s |> to_hex) let make_amz_headers ?body time = (* Return x-amz-date and x-amz-sha256 headers *) @@ -239,16 +226,12 @@ module Auth = struct Printf.sprintf "AWS4-HMAC-SHA256\n%s\n%s\n%s" time_str scope_str hashed_req let make_signing_key ?date ~region ~service ~secret_access_key () = - let mac k v = - Mirage_crypto.Hash.(mac `SHA256 ~key:k (Cstruct.of_string v)) - in + let mac k v = Digestif.SHA256.(hmac_string ~key:k v |> to_raw_string) in let date' = match date with None -> Date.today ~zone:Time.Zone.utc | Some d -> d in let date_str = Date.to_string_iso8601_basic date' in - let date_key = - mac (Cstruct.of_string ("AWS4" ^ secret_access_key)) date_str - in + let date_key = mac ("AWS4" ^ secret_access_key) date_str in let date_region_key = mac date_key (string_of_region region) in let date_region_service_key = mac date_region_key (string_of_service service) @@ -278,14 +261,12 @@ module Auth = struct (string_of_service service) in let signature = - Mirage_crypto.Hash.( - mac `SHA256 ~key:signing_key (Cstruct.of_string string_to_sign)) + Digestif.SHA256.(hmac_string ~key:signing_key string_to_sign |> to_hex) in let auth_header = Printf.sprintf "AWS4-HMAC-SHA256 Credential=%s,SignedHeaders=%s,Signature=%s" creds - signed_headers - (Compat.cstruct_to_hex_string signature) + signed_headers signature in [ ("Authorization", auth_header) ] end