upstream: github.com/mirage/ca-certs
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

use X509.Certificate.fold_decode_pem_multiple also in tests (#35)

* use X509.Certificate.fold_decode_pem_multiple also in tests

* require OCaml 4.13 (transitive from X509)

authored by

Hannes Mehnert and committed by
GitHub
0978eeb0 6ac7ef85

+14 -32
+1 -1
ca-certs.opam
··· 23 23 "digestif" {>= "1.2.0"} 24 24 "mirage-crypto" {>= "1.0.0"} 25 25 "x509" {>= "1.0.0"} 26 - "ocaml" {>= "4.08.0"} 26 + "ocaml" {>= "4.13.0"} 27 27 "ohex" {>= "0.2.0"} 28 28 "alcotest" {with-test} 29 29 "fmt" {with-test & >= "0.8.7"}
+1 -1
dune-project
··· 15 15 (digestif (>= 1.2.0)) 16 16 (mirage-crypto (>= 1.0.0)) 17 17 (x509 (>= 1.0.0)) 18 - (ocaml (>= 4.08.0)) 18 + (ocaml (>= 4.13.0)) 19 19 (ohex (>= 0.2.0)) 20 20 (alcotest :with-test) 21 21 (fmt (and :with-test (>= 0.8.7))))
+12 -30
test/tests.ml
··· 984 984 err_tests 985 985 986 986 let ta () = 987 - Result.bind (Ca_certs.trust_anchors ()) (fun data -> 988 - (* we cannot use decode_pem_multiple since this fails on the first 989 - undecodable certificate - while we'd like to stay operational, and 990 - ignore some certificates *) 991 - let d = "-----" in 992 - let new_cert = d ^ "BEGIN CERTIFICATE" ^ d 993 - and end_of_cert = d ^ "END CERTIFICATE" ^ d in 994 - let len_new = String.length new_cert 995 - and len_end = String.length end_of_cert in 996 - let lines = String.split_on_char '\n' data in 997 - let _, cas = 998 - List.fold_left 999 - (fun (acc, cas) line -> 1000 - match acc with 1001 - | None 1002 - when String.length line >= len_new 1003 - && String.(equal (sub line 0 len_new) new_cert) -> 1004 - (Some [ line ], cas) 1005 - | None -> (None, cas) 1006 - | Some lines 1007 - when String.length line >= len_end 1008 - && String.(equal (sub line 0 len_end) end_of_cert) -> ( 1009 - let data = String.concat "\n" (List.rev (line :: lines)) in 1010 - match X509.Certificate.decode_pem data with 1011 - | Ok ca -> (None, ca :: cas) 1012 - | Error (`Msg _) -> (None, cas)) 1013 - | Some lines -> (Some (line :: lines), cas)) 1014 - (None, []) lines 1015 - in 1016 - Ok (List.rev cas)) 987 + let ( let* ) = Result.bind in 988 + let* data = Ca_certs.trust_anchors () in 989 + let cas = 990 + X509.Certificate.fold_decode_pem_multiple 991 + (fun acc -> function 992 + | Ok t -> t :: acc 993 + | Error (`Msg msg) -> 994 + Logs.warn (fun m -> m "Ignoring undecodable trust anchor: %s." msg); 995 + acc) 996 + [] data 997 + in 998 + Ok cas 1017 999 1018 1000 let () = 1019 1001 Logs.set_reporter (Logs_fmt.reporter ());