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

Configure Feed

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

remove astring from opam and tests (#27)

* remove astring from opam and tests

* autoformat

authored by

Hannes Mehnert and committed by
GitHub
4af68ae9 efd88849

+24 -11
-1
ca-certs.opam
··· 16 16 bug-reports: "https://github.com/mirage/ca-certs/issues" 17 17 depends: [ 18 18 "dune" {>= "2.0"} 19 - "astring" 20 19 "bos" 21 20 "fpath" 22 21 "ptime"
+1 -1
dune-project
··· 11 11 (package 12 12 (name ca-certs) 13 13 (depends 14 - astring bos fpath ptime logs mirage-crypto 14 + bos fpath ptime logs mirage-crypto 15 15 (x509 (>= 0.13.0)) 16 16 (ocaml (>= 4.08.0)) 17 17 (alcotest :with-test)
+23 -9
test/tests.ml
··· 994 994 (* we cannot use decode_pem_multiple since this fails on the first 995 995 undecodable certificate - while we'd like to stay operational, and 996 996 ignore some certificates *) 997 - let sep = "-----END CERTIFICATE-----" in 998 - let certs = Astring.String.cuts ~sep ~empty:false data in 999 - let cas = 997 + let d = "-----" in 998 + let new_cert = d ^ "BEGIN CERTIFICATE" ^ d 999 + and end_of_cert = d ^ "END CERTIFICATE" ^ d in 1000 + let len_new = String.length new_cert 1001 + and len_end = String.length end_of_cert in 1002 + let lines = String.split_on_char '\n' data in 1003 + let _, cas = 1000 1004 List.fold_left 1001 - (fun acc data -> 1002 - let data = data ^ sep in 1003 - match X509.Certificate.decode_pem (Cstruct.of_string data) with 1004 - | Ok ca -> ca :: acc 1005 - | Error _ -> acc) 1006 - [] certs 1005 + (fun (acc, cas) line -> 1006 + match acc with 1007 + | None 1008 + when String.length line >= len_new 1009 + && String.(equal (sub line 0 len_new) new_cert) -> 1010 + (Some [ line ], cas) 1011 + | None -> (None, cas) 1012 + | Some lines 1013 + when String.length line >= len_end 1014 + && String.(equal (sub line 0 len_end) end_of_cert) -> ( 1015 + let data = String.concat "\n" (List.rev (line :: lines)) in 1016 + match X509.Certificate.decode_pem (Cstruct.of_string data) with 1017 + | Ok ca -> (None, ca :: cas) 1018 + | Error (`Msg _) -> (None, cas)) 1019 + | Some lines -> (Some (line :: lines), cas)) 1020 + (None, []) lines 1007 1021 in 1008 1022 Ok (List.rev cas)) 1009 1023