upstream: https://github.com/mirage/mirage-crypto
0
fork

Configure Feed

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

claude: complete Err -> Error module rename across call sites

Follow up to the module rename: update the remaining callers that
still referenced [Err] (library [claude.ml{,i}], [client.ml], the test
driver [test.ml]), and fix one stray [^ e] string concatenation in
hermest's CLI that needed [Json.Error.to_string e] now that
[Json.of_string] yields a structured error.

+93 -102
-1
bench/dune
··· 1 1 (executables 2 2 (names speed) 3 - (modules speed) 4 3 (libraries crypto crypto-rng crypto-rng.unix crypto-pk crypto-ec))
-1
fuzz/dune
··· 5 5 6 6 (executable 7 7 (name fuzz) 8 - (modules fuzz fuzz_crypto) 9 8 (libraries crypto alcobar)) 10 9 11 10 (rule
+1 -9
test/ec/wycheproof/dune
··· 1 1 (library 2 2 (name wycheproof) 3 - (libraries 4 - alcotest 5 - fmt 6 - jsont 7 - jsont.bytesrw 8 - crypto-ec 9 - asn1-combinators 10 - digestif 11 - ohex) 3 + (libraries alcotest fmt json crypto-ec asn1-combinators digestif ohex) 12 4 (optional))
+92 -91
test/ec/wycheproof/wycheproof.ml
··· 1 - type json = Jsont.json 1 + type json = Json.t 2 2 3 - let pp_json ppf json = 4 - match Jsont_bytesrw.encode_string Jsont.json json with 5 - | Ok s -> Format.pp_print_string ppf s 6 - | Error _ -> Format.pp_print_string ppf "<json>" 3 + let pp_json ppf json = Format.pp_print_string ppf (Json.Value.to_string json) 7 4 8 5 type hex = string 9 6 ··· 21 18 22 19 let hex_jsont = 23 20 let padded s = if String.length s mod 2 = 0 then s else "0" ^ s in 24 - Jsont.map ~kind:"hex" 21 + Json.Codec.map ~kind:"hex" 25 22 ~dec:(fun s -> hex_of_string (padded s)) 26 23 ~enc:(fun h -> Ohex.encode h) 27 - Jsont.string 24 + Json.Codec.string 28 25 29 26 type test_result = Valid | Acceptable | Invalid 30 27 ··· 39 36 | Invalid -> "Invalid" 40 37 41 38 let test_result_jsont = 42 - Jsont.map ~kind:"test_result" 39 + Json.Codec.map ~kind:"test_result" 43 40 ~dec:(function 44 41 | "valid" -> Valid 45 42 | "acceptable" -> Acceptable ··· 47 44 | _ -> failwith "test_result: expected valid, acceptable, or invalid") 48 45 ~enc:(function 49 46 | Valid -> "valid" | Acceptable -> "acceptable" | Invalid -> "invalid") 50 - Jsont.string 47 + Json.Codec.string 51 48 52 49 type ecdh_test = { 53 50 tc_id : int; ··· 73 70 let show_ecdh_test t = Fmt.str "%a" pp_ecdh_test t 74 71 75 72 let ecdh_test_jsont = 76 - Jsont.Object.map ~kind:"ecdh_test" 73 + Json.Codec.Object.map ~kind:"ecdh_test" 77 74 (fun tc_id comment curve public private_ shared result flags -> 78 75 { 79 76 tc_id; ··· 85 82 result; 86 83 flags = Option.value ~default:[] flags; 87 84 }) 88 - |> Jsont.Object.mem "tcId" Jsont.int ~enc:(fun t -> t.tc_id) 89 - |> Jsont.Object.mem "comment" Jsont.string ~enc:(fun t -> t.comment) 90 - |> Jsont.Object.opt_mem "curve" Jsont.json ~enc:(fun t -> t.curve) 91 - |> Jsont.Object.mem "public" hex_jsont ~enc:(fun t -> t.public) 92 - |> Jsont.Object.mem "private" hex_jsont ~enc:(fun t -> t.private_) 93 - |> Jsont.Object.mem "shared" hex_jsont ~enc:(fun t -> t.shared) 94 - |> Jsont.Object.mem "result" test_result_jsont ~enc:(fun t -> t.result) 95 - |> Jsont.Object.opt_mem "flags" (Jsont.list Jsont.string) ~enc:(fun t -> 96 - if t.flags = [] then None else Some t.flags) 97 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 85 + |> Json.Codec.Object.mem "tcId" Json.Codec.int ~enc:(fun t -> t.tc_id) 86 + |> Json.Codec.Object.mem "comment" Json.Codec.string ~enc:(fun t -> t.comment) 87 + |> Json.Codec.Object.opt_mem "curve" Json.Codec.Value.t ~enc:(fun t -> 88 + t.curve) 89 + |> Json.Codec.Object.mem "public" hex_jsont ~enc:(fun t -> t.public) 90 + |> Json.Codec.Object.mem "private" hex_jsont ~enc:(fun t -> t.private_) 91 + |> Json.Codec.Object.mem "shared" hex_jsont ~enc:(fun t -> t.shared) 92 + |> Json.Codec.Object.mem "result" test_result_jsont ~enc:(fun t -> t.result) 93 + |> Json.Codec.Object.opt_mem "flags" (Json.Codec.list Json.Codec.string) 94 + ~enc:(fun t -> if t.flags = [] then None else Some t.flags) 95 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 98 96 99 97 let has_ignored_flag test ~ignored_flags = 100 98 List.exists ··· 119 117 let show_ecdh_test_group t = Fmt.str "%a" pp_ecdh_test_group t 120 118 121 119 let ecdh_test_group_jsont = 122 - Jsont.Object.map ~kind:"ecdh_test_group" (fun curve tests encoding type_ -> 123 - { curve; tests; encoding; type_ }) 124 - |> Jsont.Object.mem "curve" Jsont.string ~enc:(fun t -> t.curve) 125 - |> Jsont.Object.mem "tests" (Jsont.list ecdh_test_jsont) ~enc:(fun t -> 126 - t.tests) 127 - |> Jsont.Object.opt_mem "encoding" Jsont.json ~enc:(fun t -> t.encoding) 128 - |> Jsont.Object.opt_mem "type" Jsont.json ~enc:(fun t -> t.type_) 129 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 120 + Json.Codec.Object.map ~kind:"ecdh_test_group" 121 + (fun curve tests encoding type_ -> { curve; tests; encoding; type_ }) 122 + |> Json.Codec.Object.mem "curve" Json.Codec.string ~enc:(fun t -> t.curve) 123 + |> Json.Codec.Object.mem "tests" (Json.Codec.list ecdh_test_jsont) 124 + ~enc:(fun t -> t.tests) 125 + |> Json.Codec.Object.opt_mem "encoding" Json.Codec.Value.t ~enc:(fun t -> 126 + t.encoding) 127 + |> Json.Codec.Object.opt_mem "type" Json.Codec.Value.t ~enc:(fun t -> t.type_) 128 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 130 129 131 130 type ecdsa_key = { 132 131 curve : string; ··· 147 146 let show_ecdsa_key t = Fmt.str "%a" pp_ecdsa_key t 148 147 149 148 let ecdsa_key_jsont = 150 - Jsont.Object.map ~kind:"ecdsa_key" 149 + Json.Codec.Object.map ~kind:"ecdsa_key" 151 150 (fun curve key_size type_ uncompressed wx wy -> 152 151 { curve; key_size; type_; uncompressed; wx; wy }) 153 - |> Jsont.Object.mem "curve" Jsont.string ~enc:(fun t -> t.curve) 154 - |> Jsont.Object.mem "keySize" Jsont.int ~enc:(fun t -> t.key_size) 155 - |> Jsont.Object.mem "type" Jsont.json ~enc:(fun t -> t.type_) 156 - |> Jsont.Object.mem "uncompressed" hex_jsont ~enc:(fun t -> t.uncompressed) 157 - |> Jsont.Object.mem "wx" hex_jsont ~enc:(fun t -> t.wx) 158 - |> Jsont.Object.mem "wy" hex_jsont ~enc:(fun t -> t.wy) 159 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 152 + |> Json.Codec.Object.mem "curve" Json.Codec.string ~enc:(fun t -> t.curve) 153 + |> Json.Codec.Object.mem "keySize" Json.Codec.int ~enc:(fun t -> t.key_size) 154 + |> Json.Codec.Object.mem "type" Json.Codec.Value.t ~enc:(fun t -> t.type_) 155 + |> Json.Codec.Object.mem "uncompressed" hex_jsont ~enc:(fun t -> 156 + t.uncompressed) 157 + |> Json.Codec.Object.mem "wx" hex_jsont ~enc:(fun t -> t.wx) 158 + |> Json.Codec.Object.mem "wy" hex_jsont ~enc:(fun t -> t.wy) 159 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 160 160 161 161 type dsa_test = { 162 162 tc_id : int; ··· 177 177 let show_dsa_test t = Fmt.str "%a" pp_dsa_test t 178 178 179 179 let dsa_test_jsont = 180 - Jsont.Object.map ~kind:"dsa_test" (fun tc_id comment msg sig_ result flags -> 180 + Json.Codec.Object.map ~kind:"dsa_test" 181 + (fun tc_id comment msg sig_ result flags -> 181 182 { 182 183 tc_id; 183 184 comment; ··· 186 187 result; 187 188 flags = Option.value ~default:[] flags; 188 189 }) 189 - |> Jsont.Object.mem "tcId" Jsont.int ~enc:(fun t -> t.tc_id) 190 - |> Jsont.Object.mem "comment" Jsont.string ~enc:(fun t -> t.comment) 191 - |> Jsont.Object.mem "msg" hex_jsont ~enc:(fun t -> t.msg) 192 - |> Jsont.Object.mem "sig" hex_jsont ~enc:(fun t -> t.sig_) 193 - |> Jsont.Object.mem "result" test_result_jsont ~enc:(fun t -> t.result) 194 - |> Jsont.Object.opt_mem "flags" (Jsont.list Jsont.string) ~enc:(fun t -> 195 - if t.flags = [] then None else Some t.flags) 196 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 190 + |> Json.Codec.Object.mem "tcId" Json.Codec.int ~enc:(fun t -> t.tc_id) 191 + |> Json.Codec.Object.mem "comment" Json.Codec.string ~enc:(fun t -> t.comment) 192 + |> Json.Codec.Object.mem "msg" hex_jsont ~enc:(fun t -> t.msg) 193 + |> Json.Codec.Object.mem "sig" hex_jsont ~enc:(fun t -> t.sig_) 194 + |> Json.Codec.Object.mem "result" test_result_jsont ~enc:(fun t -> t.result) 195 + |> Json.Codec.Object.opt_mem "flags" (Json.Codec.list Json.Codec.string) 196 + ~enc:(fun t -> if t.flags = [] then None else Some t.flags) 197 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 197 198 198 199 type ecdsa_test_group = { 199 200 key : ecdsa_key; ··· 215 216 let show_ecdsa_test_group t = Fmt.str "%a" pp_ecdsa_test_group t 216 217 217 218 let ecdsa_test_group_jsont = 218 - Jsont.Object.map ~kind:"ecdsa_test_group" 219 + Json.Codec.Object.map ~kind:"ecdsa_test_group" 219 220 (fun key key_der key_pem sha tests type_ -> 220 221 { key; key_der; key_pem; sha; tests; type_ }) 221 - |> Jsont.Object.mem "key" ecdsa_key_jsont ~enc:(fun t -> t.key) 222 - |> Jsont.Object.mem "keyDer" Jsont.string ~enc:(fun t -> t.key_der) 223 - |> Jsont.Object.mem "keyPem" Jsont.string ~enc:(fun t -> t.key_pem) 224 - |> Jsont.Object.mem "sha" Jsont.string ~enc:(fun t -> t.sha) 225 - |> Jsont.Object.mem "tests" (Jsont.list dsa_test_jsont) ~enc:(fun t -> 226 - t.tests) 227 - |> Jsont.Object.opt_mem "type" Jsont.json ~enc:(fun t -> t.type_) 228 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 222 + |> Json.Codec.Object.mem "key" ecdsa_key_jsont ~enc:(fun t -> t.key) 223 + |> Json.Codec.Object.mem "keyDer" Json.Codec.string ~enc:(fun t -> t.key_der) 224 + |> Json.Codec.Object.mem "keyPem" Json.Codec.string ~enc:(fun t -> t.key_pem) 225 + |> Json.Codec.Object.mem "sha" Json.Codec.string ~enc:(fun t -> t.sha) 226 + |> Json.Codec.Object.mem "tests" (Json.Codec.list dsa_test_jsont) 227 + ~enc:(fun t -> t.tests) 228 + |> Json.Codec.Object.opt_mem "type" Json.Codec.Value.t ~enc:(fun t -> t.type_) 229 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 229 230 230 231 type eddsa_key = { 231 232 curve : string; ··· 242 243 let show_eddsa_key t = Fmt.str "%a" pp_eddsa_key t 243 244 244 245 let eddsa_key_jsont = 245 - Jsont.Object.map ~kind:"eddsa_key" (fun curve key_size pk sk type_ -> 246 + Json.Codec.Object.map ~kind:"eddsa_key" (fun curve key_size pk sk type_ -> 246 247 { curve; key_size; pk; sk; type_ }) 247 - |> Jsont.Object.mem "curve" Jsont.string ~enc:(fun t -> t.curve) 248 - |> Jsont.Object.mem "keySize" Jsont.int ~enc:(fun t -> t.key_size) 249 - |> Jsont.Object.mem "pk" hex_jsont ~enc:(fun t -> t.pk) 250 - |> Jsont.Object.mem "sk" hex_jsont ~enc:(fun t -> t.sk) 251 - |> Jsont.Object.mem "type" Jsont.json ~enc:(fun t -> t.type_) 252 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 248 + |> Json.Codec.Object.mem "curve" Json.Codec.string ~enc:(fun t -> t.curve) 249 + |> Json.Codec.Object.mem "keySize" Json.Codec.int ~enc:(fun t -> t.key_size) 250 + |> Json.Codec.Object.mem "pk" hex_jsont ~enc:(fun t -> t.pk) 251 + |> Json.Codec.Object.mem "sk" hex_jsont ~enc:(fun t -> t.sk) 252 + |> Json.Codec.Object.mem "type" Json.Codec.Value.t ~enc:(fun t -> t.type_) 253 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 253 254 254 255 type eddsa_test_group = { 255 256 jwk : json; ··· 270 271 let show_eddsa_test_group t = Fmt.str "%a" pp_eddsa_test_group t 271 272 272 273 let eddsa_test_group_jsont = 273 - Jsont.Object.map ~kind:"eddsa_test_group" 274 + Json.Codec.Object.map ~kind:"eddsa_test_group" 274 275 (fun jwk key key_der key_pem type_ tests -> 275 276 { jwk; key; key_der; key_pem; type_; tests }) 276 - |> Jsont.Object.mem "jwk" Jsont.json ~enc:(fun t -> t.jwk) 277 - |> Jsont.Object.mem "key" eddsa_key_jsont ~enc:(fun t -> t.key) 278 - |> Jsont.Object.mem "keyDer" Jsont.string ~enc:(fun t -> t.key_der) 279 - |> Jsont.Object.mem "keyPem" Jsont.string ~enc:(fun t -> t.key_pem) 280 - |> Jsont.Object.mem "type" Jsont.json ~enc:(fun t -> t.type_) 281 - |> Jsont.Object.mem "tests" (Jsont.list dsa_test_jsont) ~enc:(fun t -> 282 - t.tests) 283 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 277 + |> Json.Codec.Object.mem "jwk" Json.Codec.Value.t ~enc:(fun t -> t.jwk) 278 + |> Json.Codec.Object.mem "key" eddsa_key_jsont ~enc:(fun t -> t.key) 279 + |> Json.Codec.Object.mem "keyDer" Json.Codec.string ~enc:(fun t -> t.key_der) 280 + |> Json.Codec.Object.mem "keyPem" Json.Codec.string ~enc:(fun t -> t.key_pem) 281 + |> Json.Codec.Object.mem "type" Json.Codec.Value.t ~enc:(fun t -> t.type_) 282 + |> Json.Codec.Object.mem "tests" (Json.Codec.list dsa_test_jsont) 283 + ~enc:(fun t -> t.tests) 284 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 284 285 285 286 type test_file = { 286 287 algorithm : json; ··· 303 304 let show_test_file t = Fmt.str "%a" pp_test_file t 304 305 305 306 let test_file_jsont = 306 - Jsont.Object.map ~kind:"test_file" 307 + Json.Codec.Object.map ~kind:"test_file" 307 308 (fun 308 309 algorithm 309 310 generator_version ··· 322 323 schema; 323 324 test_groups; 324 325 }) 325 - |> Jsont.Object.mem "algorithm" Jsont.json ~enc:(fun t -> t.algorithm) 326 - |> Jsont.Object.mem "generatorVersion" Jsont.json ~enc:(fun t -> 326 + |> Json.Codec.Object.mem "algorithm" Json.Codec.Value.t ~enc:(fun t -> 327 + t.algorithm) 328 + |> Json.Codec.Object.mem "generatorVersion" Json.Codec.Value.t ~enc:(fun t -> 327 329 t.generator_version) 328 - |> Jsont.Object.mem "header" Jsont.json ~enc:(fun t -> t.header) 329 - |> Jsont.Object.mem "notes" Jsont.json ~enc:(fun t -> t.notes) 330 - |> Jsont.Object.mem "numberOfTests" Jsont.json ~enc:(fun t -> 330 + |> Json.Codec.Object.mem "header" Json.Codec.Value.t ~enc:(fun t -> t.header) 331 + |> Json.Codec.Object.mem "notes" Json.Codec.Value.t ~enc:(fun t -> t.notes) 332 + |> Json.Codec.Object.mem "numberOfTests" Json.Codec.Value.t ~enc:(fun t -> 331 333 t.number_of_tests) 332 - |> Jsont.Object.mem "schema" Jsont.json ~enc:(fun t -> t.schema) 333 - |> Jsont.Object.mem "testGroups" (Jsont.list Jsont.json) ~enc:(fun t -> 334 - t.test_groups) 335 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 334 + |> Json.Codec.Object.mem "schema" Json.Codec.Value.t ~enc:(fun t -> t.schema) 335 + |> Json.Codec.Object.mem "testGroups" (Json.Codec.list Json.Codec.Value.t) 336 + ~enc:(fun t -> t.test_groups) 337 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 336 338 337 - let result = function Ok x -> x | Error s -> failwith s 339 + let json_result = function 340 + | Ok x -> x 341 + | Error e -> failwith (Json.Error.to_string e) 338 342 339 343 let load_file_exn path = 340 344 let content = In_channel.with_open_bin path In_channel.input_all in 341 - Jsont_bytesrw.decode_string test_file_jsont content |> result 345 + Json.of_string test_file_jsont content |> json_result 342 346 343 347 let ecdh_test_group_exn json = 344 - match Jsont_bytesrw.encode_string Jsont.json json with 345 - | Error _ -> failwith "ecdh_test_group_exn: encode failed" 346 - | Ok s -> Jsont_bytesrw.decode_string ecdh_test_group_jsont s |> result 348 + Json.of_string ecdh_test_group_jsont (Json.Value.to_string json) 349 + |> json_result 347 350 348 351 let ecdsa_test_group_exn json = 349 - match Jsont_bytesrw.encode_string Jsont.json json with 350 - | Error _ -> failwith "ecdsa_test_group_exn: encode failed" 351 - | Ok s -> Jsont_bytesrw.decode_string ecdsa_test_group_jsont s |> result 352 + Json.of_string ecdsa_test_group_jsont (Json.Value.to_string json) 353 + |> json_result 352 354 353 355 let eddsa_test_group_exn json = 354 - match Jsont_bytesrw.encode_string Jsont.json json with 355 - | Error _ -> failwith "eddsa_test_group_exn: encode failed" 356 - | Ok s -> Jsont_bytesrw.decode_string eddsa_test_group_jsont s |> result 356 + Json.of_string eddsa_test_group_jsont (Json.Value.to_string json) 357 + |> json_result 357 358 358 359 (* -- EC test vectors ---------------------------------------------------- *) 359 360