Skip to content

Commit 1ceb38f

Browse files
Fix mirage-crypto
1 parent ea2403d commit 1ceb38f

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

cohttp-async.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ depends: [
3434
"cohttp" {= version}
3535
"conduit-async" {>= "1.2.0"}
3636
"magic-mime"
37-
"mirage-crypto" {with-test}
37+
"digestif" {with-test}
3838
"logs"
3939
"fmt" {>= "0.8.2"}
4040
"sexplib0"

cohttp-async/test/test_async_integration.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ let ts =
111111
("Pipe with empty strings", Pipe.of_list [ ""; ""; "" ], true);
112112
]
113113
in
114-
Deferred.List.iter ~how:`Sequential tests
115-
~f:(fun (msg, pipe, expected) ->
114+
Deferred.List.iter ~how:`Sequential tests
115+
~f:(fun (msg, pipe, expected) ->
116116
is_empty (`Pipe pipe) >>| fun real ->
117117
assert_equal ~msg expected real)
118118
>>= fun () ->

examples/async/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(executables
22
(names hello_world receive_post s3_cp)
3-
(libraries mirage-crypto cohttp-async base async_kernel
4-
core_unix.command_unix cstruct))
3+
(libraries digestif.c cohttp-async base async_kernel core_unix.command_unix
4+
cstruct))
55

66
(alias
77
(name runtest)

examples/async/s3_cp.ml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ module Auth = struct
169169

170170
let digest s =
171171
(* string -> sha256 as a hex string *)
172-
Mirage_crypto.Hash.(digest `SHA256 (Cstruct.of_string s))
173-
|> Compat.cstruct_to_hex_string
172+
Digestif.SHA256.(digest_string s |> to_hex)
174173

175174
let make_amz_headers ?body time =
176175
(* Return x-amz-date and x-amz-sha256 headers *)
@@ -238,16 +237,12 @@ module Auth = struct
238237
Printf.sprintf "AWS4-HMAC-SHA256\n%s\n%s\n%s" time_str scope_str hashed_req
239238

240239
let make_signing_key ?date ~region ~service ~secret_access_key () =
241-
let mac k v =
242-
Mirage_crypto.Hash.(mac `SHA256 ~key:k (Cstruct.of_string v))
243-
in
240+
let mac k v = Digestif.SHA256.(hmac_string ~key:k v |> to_raw_string) in
244241
let date' =
245242
match date with None -> Date.today ~zone:Time.Zone.utc | Some d -> d
246243
in
247244
let date_str = Date.to_string_iso8601_basic date' in
248-
let date_key =
249-
mac (Cstruct.of_string ("AWS4" ^ secret_access_key)) date_str
250-
in
245+
let date_key = mac ("AWS4" ^ secret_access_key) date_str in
251246
let date_region_key = mac date_key (string_of_region region) in
252247
let date_region_service_key =
253248
mac date_region_key (string_of_service service)
@@ -277,14 +272,12 @@ module Auth = struct
277272
(string_of_service service)
278273
in
279274
let signature =
280-
Mirage_crypto.Hash.(
281-
mac `SHA256 ~key:signing_key (Cstruct.of_string string_to_sign))
275+
Digestif.SHA256.(hmac_string ~key:signing_key string_to_sign |> to_hex)
282276
in
283277
let auth_header =
284278
Printf.sprintf
285279
"AWS4-HMAC-SHA256 Credential=%s,SignedHeaders=%s,Signature=%s" creds
286-
signed_headers
287-
(Compat.cstruct_to_hex_string signature)
280+
signed_headers signature
288281
in
289282
[ ("Authorization", auth_header) ]
290283
end

0 commit comments

Comments
 (0)