Base64.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*******************************************************************************
  2. * Copyright (c) 2018 Wind River Systems, Inc. All Rights Reserved.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Keith Holman - initial implementation and documentation
  15. *******************************************************************************/
  16. #if !defined(BASE64_H)
  17. #define BASE64_H
  18. /** type for size of a buffer, it saves passing around @p size_t (unsigned long long or unsigned long int) */
  19. typedef unsigned int b64_size_t;
  20. /** type for raw base64 data */
  21. typedef unsigned char b64_data_t;
  22. /**
  23. * Decodes base64 data
  24. *
  25. * @param[out] out decoded data
  26. * @param[in] out_len length of output buffer
  27. * @param[in] in base64 string to decode
  28. * @param[in] in_len length of input buffer
  29. *
  30. * @return the amount of data decoded
  31. *
  32. * @see Base64_decodeLength
  33. * @see Base64_encode
  34. */
  35. b64_size_t Base64_decode( b64_data_t *out, b64_size_t out_len,
  36. const char *in, b64_size_t in_len );
  37. /**
  38. * Size of buffer required to decode base64 data
  39. *
  40. * @param[in] in base64 string to decode
  41. * @param[in] in_len length of input buffer
  42. *
  43. * @return the size of buffer the decoded string would require
  44. *
  45. * @see Base64_decode
  46. * @see Base64_encodeLength
  47. */
  48. b64_size_t Base64_decodeLength( const char *in, b64_size_t in_len );
  49. /**
  50. * Encodes base64 data
  51. *
  52. * @param[out] out encode base64 string
  53. * @param[in] out_len length of output buffer
  54. * @param[in] in raw data to encode
  55. * @param[in] in_len length of input buffer
  56. *
  57. * @return the amount of data encoded
  58. *
  59. * @see Base64_decode
  60. * @see Base64_encodeLength
  61. */
  62. b64_size_t Base64_encode( char *out, b64_size_t out_len,
  63. const b64_data_t *in, b64_size_t in_len );
  64. /**
  65. * Size of buffer required to encode base64 data
  66. *
  67. * @param[in] in raw data to encode
  68. * @param[in] in_len length of input buffer
  69. *
  70. * @return the size of buffer the encoded string would require
  71. *
  72. * @see Base64_decodeLength
  73. * @see Base64_encode
  74. */
  75. b64_size_t Base64_encodeLength( const b64_data_t *in, b64_size_t in_len );
  76. #endif /* BASE64_H */