Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide alphabet internals #48

Merged
merged 3 commits into from
Feb 8, 2021
Merged

Hide alphabet internals #48

merged 3 commits into from
Feb 8, 2021

Conversation

reynir
Copy link
Member

@reynir reynir commented Nov 30, 2020

Base64.alphabet leaks the internal emap array. This PR makes Base64.alphabet return a string instead. The following snippet shows how to break encode |> decode using `default_alphabet.

let a = Base64.(alphabet default_alphabet) in
let () = Array.iteri (fun i _ -> a.(i) <- int_of_char 'A') a in
Base64.(decode_exn (encode_string "Hello, World!"))

This is obviously a breaking change since the interface is altered. As an alternative, I fixed the problem by calling Array.copy. The code is available in my branch hide-internals2 (with a test).

I think it makes the most sense to have Base64.alphabet return a string. Base64.make_alphabet takes a string, and it's annoying for the user that the alphabet characters are returned as an int array.

@dinosaure dinosaure self-requested a review February 8, 2021 09:52
reynir and others added 3 commits February 8, 2021 11:38
Change [Base64.alphabet] to return the string representation of the
alphabet instead of leaking the internal array.
@dinosaure
Copy link
Member

dinosaure commented Feb 8, 2021

Thanks, I force-pushed an ocamlformat pass, it will be integrated into the next release.

PS: sorry for the delay.

@dinosaure dinosaure merged commit 9af342c into mirage:master Feb 8, 2021
dinosaure added a commit to dinosaure/opam-repository that referenced this pull request Feb 8, 2021
CHANGES:

- Fix support for `x-compilation` (@samoht, mirage/ocaml-base64#44)
- Update to `dune.2.0` and apply `ocamlformat` (@samoht, mirage/ocaml-base64#45)
- Select `unsafe.ml` only with `dune` (@emillon, mirage/ocaml-base64#46)
- Remove indirect dependecy to `ocamlfind` (@kit-ty-kate, mirage/ocaml-base64#49)
- Hide internals of `base64` and return a `string` as the alphabet (@reynir, mirage/ocaml-base64#48)
  **breaking chnages** `Base64.alphabet` is updated and return a simple `string` now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants