Skip to content

Commit

Permalink
remove cstruct
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Apr 3, 2024
1 parent fa4ff94 commit 66842b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/ca_certs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let get_anchors () =
let der_list = ref [] in
match
iter_on_anchors (fun der_cert ->
der_list := Cstruct.of_string der_cert :: !der_list)
der_list := der_cert :: !der_list)
with
| () -> Ok !der_list
| exception Failure msg -> Error (`Msg msg)
Expand All @@ -76,7 +76,7 @@ let rec map_m f l =
let windows_trust_anchors () =
let* anchors = get_anchors () in
let* cert_list = map_m X509.Certificate.decode_der anchors in
Ok (X509.Certificate.encode_pem_multiple cert_list |> Cstruct.to_string)
Ok (X509.Certificate.encode_pem_multiple cert_list)

let trust_anchors () =
if Sys.win32 then windows_trust_anchors ()
Expand Down Expand Up @@ -134,7 +134,7 @@ let authenticator ?crls ?allowed_hashes () =
when String.length line >= len_end
&& String.(equal (sub line 0 len_end) end_of_cert) -> (
let data = String.concat "\n" (List.rev (line :: lines)) in
match X509.Certificate.decode_pem (Cstruct.of_string data) with
match X509.Certificate.decode_pem data with
| Ok ca -> (None, ca :: cas)
| Error (`Msg msg) ->
Log.warn (fun m -> m "Failed to decode a trust anchor %s." msg);
Expand Down
2 changes: 1 addition & 1 deletion lib/ca_certs.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
val authenticator :
?crls:X509.CRL.t list ->
?allowed_hashes:Mirage_crypto.Hash.hash list ->
?allowed_hashes:Digestif.hash' list ->
unit ->
(X509.Authenticator.t, [> `Msg of string ]) result
(** [authenticator ~crls ~allowed_hashes ()] detects the root CAs (trust
Expand Down
6 changes: 3 additions & 3 deletions test/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ let tests tas =
let host = Domain_name.(of_string_exn name |> host_exn)
and chain =
Result.get_ok
(X509.Certificate.decode_pem_multiple (Cstruct.of_string data))
(X509.Certificate.decode_pem_multiple data)
in
( name,
`Quick,
Expand All @@ -984,7 +984,7 @@ let tests tas =
let host = Domain_name.(of_string_exn name |> host_exn)
and chain =
Result.get_ok
(X509.Certificate.decode_pem_multiple (Cstruct.of_string data))
(X509.Certificate.decode_pem_multiple data)
in
(name, `Quick, test_one ?time tas (Error (result host chain)) host chain))
err_tests
Expand Down Expand Up @@ -1013,7 +1013,7 @@ let ta () =
when String.length line >= len_end
&& String.(equal (sub line 0 len_end) end_of_cert) -> (
let data = String.concat "\n" (List.rev (line :: lines)) in
match X509.Certificate.decode_pem (Cstruct.of_string data) with
match X509.Certificate.decode_pem data with
| Ok ca -> (None, ca :: cas)
| Error (`Msg _) -> (None, cas))
| Some lines -> (Some (line :: lines), cas))
Expand Down

0 comments on commit 66842b6

Please sign in to comment.