nssb64.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /*
  5. * Public prototypes for base64 encoding/decoding.
  6. */
  7. #ifndef _NSSB64_H_
  8. #define _NSSB64_H_
  9. #include "utilrename.h"
  10. #include "seccomon.h"
  11. #include "nssb64t.h"
  12. SEC_BEGIN_PROTOS
  13. /*
  14. * Functions to start a base64 decoding/encoding context.
  15. */
  16. extern NSSBase64Decoder *
  17. NSSBase64Decoder_Create(PRInt32 (*output_fn)(void *, const unsigned char *,
  18. PRInt32),
  19. void *output_arg);
  20. extern NSSBase64Encoder *
  21. NSSBase64Encoder_Create(PRInt32 (*output_fn)(void *, const char *, PRInt32),
  22. void *output_arg);
  23. /*
  24. * Push data through the decoder/encoder, causing the output_fn (provided
  25. * to Create) to be called with the decoded/encoded data.
  26. */
  27. extern SECStatus
  28. NSSBase64Decoder_Update(NSSBase64Decoder *data, const char *buffer,
  29. PRUint32 size);
  30. extern SECStatus
  31. NSSBase64Encoder_Update(NSSBase64Encoder *data, const unsigned char *buffer,
  32. PRUint32 size);
  33. /*
  34. * When you're done processing, call this to close the context.
  35. * If "abort_p" is false, then calling this may cause the output_fn
  36. * to be called one last time (as the last buffered data is flushed out).
  37. */
  38. extern SECStatus
  39. NSSBase64Decoder_Destroy(NSSBase64Decoder *data, PRBool abort_p);
  40. extern SECStatus
  41. NSSBase64Encoder_Destroy(NSSBase64Encoder *data, PRBool abort_p);
  42. /*
  43. * Perform base64 decoding from an ascii string "inStr" to an Item.
  44. * The length of the input must be provided as "inLen". The Item
  45. * may be provided (as "outItemOpt"); you can also pass in a NULL
  46. * and the Item will be allocated for you.
  47. *
  48. * In any case, the data within the Item will be allocated for you.
  49. * All allocation will happen out of the passed-in "arenaOpt", if non-NULL.
  50. * If "arenaOpt" is NULL, standard allocation (heap) will be used and
  51. * you will want to free the result via SECITEM_FreeItem.
  52. *
  53. * Return value is NULL on error, the Item (allocated or provided) otherwise.
  54. */
  55. extern SECItem *
  56. NSSBase64_DecodeBuffer(PLArenaPool *arenaOpt, SECItem *outItemOpt,
  57. const char *inStr, unsigned int inLen);
  58. /*
  59. * Perform base64 encoding of binary data "inItem" to an ascii string.
  60. * The output buffer may be provided (as "outStrOpt"); you can also pass
  61. * in a NULL and the buffer will be allocated for you. The result will
  62. * be null-terminated, and if the buffer is provided, "maxOutLen" must
  63. * specify the maximum length of the buffer and will be checked to
  64. * supply sufficient space space for the encoded result. (If "outStrOpt"
  65. * is NULL, "maxOutLen" is ignored.)
  66. *
  67. * If "outStrOpt" is NULL, allocation will happen out of the passed-in
  68. * "arenaOpt", if *it* is non-NULL, otherwise standard allocation (heap)
  69. * will be used.
  70. *
  71. * Return value is NULL on error, the output buffer (allocated or provided)
  72. * otherwise.
  73. */
  74. extern char *
  75. NSSBase64_EncodeItem(PLArenaPool *arenaOpt, char *outStrOpt,
  76. unsigned int maxOutLen, SECItem *inItem);
  77. SEC_END_PROTOS
  78. #endif /* _NSSB64_H_ */