base64.mli 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (*
  2. * Base64 - Base64 codec
  3. * Copyright (C) 2003 Nicolas Cannasse
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version,
  9. * with the special exception on linking described in file LICENSE.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *)
  20. (** Base64 codec.
  21. 8-bit characters are encoded into 6-bit ones using ASCII lookup tables.
  22. Default tables maps 0..63 values on characters A-Z, a-z, 0-9, '+' and '/'
  23. (in that order).
  24. *)
  25. open ExtBytes
  26. (** This exception is raised when reading an invalid character
  27. from a base64 input. *)
  28. exception Invalid_char
  29. (** This exception is raised if the encoding or decoding table
  30. size is not correct. *)
  31. exception Invalid_table
  32. (** An encoding table maps integers 0..63 to the corresponding char. *)
  33. type encoding_table = char array
  34. (** A decoding table maps chars 0..255 to the corresponding 0..63 value
  35. or -1 if the char is not accepted. *)
  36. type decoding_table = int array
  37. (** erroneous interface, kept for compatibility use [encode_string] instead *)
  38. val str_encode : ?tbl:encoding_table -> string -> Bytes.t
  39. (** erroneous interface, kept for compatibility use [decode_string] instead *)
  40. val str_decode : ?tbl:decoding_table -> Bytes.t -> string
  41. (** Encode a string into Base64. *)
  42. val encode_string : ?tbl:encoding_table -> string -> string
  43. (** Decode a string encoded into Base64, raise [Invalid_char] if a
  44. character in the input string is not a valid one. *)
  45. val decode_string : ?tbl:decoding_table -> string -> string
  46. (** Generic base64 encoding over an output. *)
  47. val encode : ?tbl:encoding_table -> 'a IO.output -> 'a IO.output
  48. (** Generic base64 decoding over an input. *)
  49. val decode : ?tbl:decoding_table -> IO.input -> IO.input
  50. (** Create a valid decoding table from an encoding one. *)
  51. val make_decoding_table : encoding_table -> decoding_table