Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
### v3.1.0

* Add `Base64.encode_string` that doesn't raise or return an error.
This makes it easier to port pre-3.0 code to the new interface (@avsm)

### v3.0.0 (2018-01-21)

* Implemenation of Base64 according to RFC 2045 (available on base64.rfc2045)
* Implementation of Base64 according to RFC 2045 (available on base64.rfc2045)
* New implementation of Base64 according to RFC 4648 from nocrypto's implementation
* Fix bad access with `String.iter` on the old implementation of Base64 (@dinosaure, #23)
* Check isomorphism between `encode` & `decode` function (@hannesm, @dinosaure, #20)
Expand Down
5 changes: 5 additions & 0 deletions src/base64.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ let encode ?(pad = true) ?(alphabet = default_alphabet) ?off ?len input =
| Ok (res, off, len) -> Ok (String.sub res off len)
| Error _ as err -> err

let encode_string ?pad ?alphabet input =
match encode ?pad ?alphabet input with
| Ok res -> res
| Error _ -> assert false

let encode_sub ?(pad = true) ?(alphabet = default_alphabet) ?off ?len input =
encode_sub pad alphabet ?off ?len input

Expand Down
5 changes: 5 additions & 0 deletions src/base64.mli
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ val encode : ?pad:bool -> ?alphabet:alphabet -> ?off:int -> ?len:int -> string -

[encode] fails when [off] and [len] do not designate a valid range of [s]. *)

val encode_string : ?pad:bool -> ?alphabet:alphabet -> string -> string
(** [encode_string s] encodes the string [s] into base64. If [pad] is false, no
trailing padding is added. [pad] defaults to [true], and [alphabet] to
{!default_alphabet}. *)

val encode_sub : ?pad:bool -> ?alphabet:alphabet -> ?off:int -> ?len:int -> string -> (sub, [ `Msg of string]) result
(** Same as {!encode} but return a {!sub}-string instead a plain result. By this
way, we ensure to allocate only one time result. *)
Expand Down