Skip to content

Commit

Permalink
Return string alphabet
Browse files Browse the repository at this point in the history
Change [Base64.alphabet] to return the string representation of the
alphabet instead of leaking the internal array.
  • Loading branch information
reynir committed Nov 30, 2020
1 parent 69da8f9 commit 4f1b55c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/base64.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let make_alphabet alphabet =

let length_alphabet { emap; _ } = Array.length emap

let alphabet { emap; _ } = emap
let alphabet { emap; _ } = String.init (Array.length emap) (fun i -> Char.chr emap.(i))

let default_alphabet =
make_alphabet
Expand Down
2 changes: 1 addition & 1 deletion src/base64.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ val make_alphabet : string -> alphabet
val length_alphabet : alphabet -> int
(** Returns length of the alphabet, should be 64. *)

val alphabet : alphabet -> int array
val alphabet : alphabet -> string
(** Returns the alphabet. *)

val decode_exn :
Expand Down
8 changes: 0 additions & 8 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,6 @@ let test_nocrypto () =
Alcotest.(check (option string)) (sprintf "decode %S" input) res' res)
nocrypto_tests

let test_reynir () =
let r = "Hello, World!" in
let a = Base64.(alphabet default_alphabet) in
let () = Array.iteri (fun i _ -> a.(i) <- int_of_char 'A') a in
Alcotest.(check string) "decode encode after mutating default_alphabet"
r Base64.(decode_exn (encode_string r))

exception Malformed

exception Wrong_padding
Expand Down Expand Up @@ -316,7 +309,6 @@ let test_codec =
("Cfcs test vectors", `Quick, test_cfcs);
("PHP test vectors", `Quick, test_php);
("Nocrypto test vectors", `Quick, test_nocrypto);
("Reynir test vectors", `Quick, test_reynir);
]

let () =
Expand Down

0 comments on commit 4f1b55c

Please sign in to comment.