···984984 err_tests
985985986986let ta () =
987987- Result.bind (Ca_certs.trust_anchors ()) (fun data ->
988988- (* we cannot use decode_pem_multiple since this fails on the first
989989- undecodable certificate - while we'd like to stay operational, and
990990- ignore some certificates *)
991991- let d = "-----" in
992992- let new_cert = d ^ "BEGIN CERTIFICATE" ^ d
993993- and end_of_cert = d ^ "END CERTIFICATE" ^ d in
994994- let len_new = String.length new_cert
995995- and len_end = String.length end_of_cert in
996996- let lines = String.split_on_char '\n' data in
997997- let _, cas =
998998- List.fold_left
999999- (fun (acc, cas) line ->
10001000- match acc with
10011001- | None
10021002- when String.length line >= len_new
10031003- && String.(equal (sub line 0 len_new) new_cert) ->
10041004- (Some [ line ], cas)
10051005- | None -> (None, cas)
10061006- | Some lines
10071007- when String.length line >= len_end
10081008- && String.(equal (sub line 0 len_end) end_of_cert) -> (
10091009- let data = String.concat "\n" (List.rev (line :: lines)) in
10101010- match X509.Certificate.decode_pem data with
10111011- | Ok ca -> (None, ca :: cas)
10121012- | Error (`Msg _) -> (None, cas))
10131013- | Some lines -> (Some (line :: lines), cas))
10141014- (None, []) lines
10151015- in
10161016- Ok (List.rev cas))
987987+ let ( let* ) = Result.bind in
988988+ let* data = Ca_certs.trust_anchors () in
989989+ let cas =
990990+ X509.Certificate.fold_decode_pem_multiple
991991+ (fun acc -> function
992992+ | Ok t -> t :: acc
993993+ | Error (`Msg msg) ->
994994+ Logs.warn (fun m -> m "Ignoring undecodable trust anchor: %s." msg);
995995+ acc)
996996+ [] data
997997+ in
998998+ Ok cas
101799910181000let () =
10191001 Logs.set_reporter (Logs_fmt.reporter ());