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

Configure Feed

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

Replace custom hex/percent-encoding with Ohex and Uri

- ocaml-cbort/fuzz: custom hex_decode → Ohex.decode
- space-ground/web: custom hex_digit + hex_to_bytes → Ohex.decode
- space-ground/lib: custom hex_of_string → Ohex.encode
- ocaml-atp/test: custom hex_of_string → Ohex.encode
- ocaml-crypto/test: custom hex_of_string → Ohex.decode + Ohex.encode
- ocaml-atp/xrpc-server: custom decode_percent → Uri.pct_decode

~100 lines of custom encoding code removed.

+4 -34
+2 -1
test/ec/wycheproof/dune
··· 7 7 jsont.bytesrw 8 8 crypto-ec 9 9 asn1-combinators 10 - digestif) 10 + digestif 11 + ohex) 11 12 (optional))
+2 -33
test/ec/wycheproof/wycheproof.ml
··· 17 17 Fmt.pf fmt "%02x" byte 18 18 done 19 19 20 - let hex_of_string s = 21 - let fold f acc str = 22 - let st = ref acc in 23 - String.iter (fun c -> st := f !st c) str; 24 - !st 25 - and digit c = 26 - match c with 27 - | '0' .. '9' -> int_of_char c - 0x30 28 - | 'A' .. 'F' -> int_of_char c - 0x41 + 10 29 - | 'a' .. 'f' -> int_of_char c - 0x61 + 10 30 - | _ -> invalid_arg "bad character" 31 - in 32 - let out = Bytes.create (String.length s / 2) in 33 - let _idx, leftover = 34 - fold 35 - (fun (idx, leftover) c -> 36 - let c = digit c in 37 - match leftover with 38 - | None -> (idx, Some (c lsl 4)) 39 - | Some c' -> 40 - Bytes.set_uint8 out idx (c' lor c); 41 - (succ idx, None)) 42 - (0, None) s 43 - in 44 - assert (leftover = None); 45 - Bytes.unsafe_to_string out 20 + let hex_of_string s = Ohex.decode s 46 21 47 22 let hex_jsont = 48 23 let padded s = if String.length s mod 2 = 0 then s else "0" ^ s in 49 24 Jsont.map ~kind:"hex" 50 25 ~dec:(fun s -> hex_of_string (padded s)) 51 - ~enc:(fun h -> 52 - (* Encode hex back to string - reverse of hex_of_string *) 53 - let buf = Buffer.create (String.length h * 2) in 54 - String.iter 55 - (fun c -> Buffer.add_string buf (Fmt.str "%02x" (Char.code c))) 56 - h; 57 - Buffer.contents buf) 26 + ~enc:(fun h -> Ohex.encode h) 58 27 Jsont.string 59 28 60 29 type test_result = Valid | Acceptable | Invalid