PageRenderTime 28ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/nssb64.h

http://firefox-mac-pdf.googlecode.com/
C Header | 128 lines | 31 code | 16 blank | 81 comment | 0 complexity | ddf2e3a3527c1100a77d5ef6a8a2cae4 MD5 | raw file
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the Netscape security libraries.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 1994-2000
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. *
  23. * Alternatively, the contents of this file may be used under the terms of
  24. * either the GNU General Public License Version 2 or later (the "GPL"), or
  25. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26. * in which case the provisions of the GPL or the LGPL are applicable instead
  27. * of those above. If you wish to allow use of your version of this file only
  28. * under the terms of either the GPL or the LGPL, and not to allow others to
  29. * use your version of this file under the terms of the MPL, indicate your
  30. * decision by deleting the provisions above and replace them with the notice
  31. * and other provisions required by the GPL or the LGPL. If you do not delete
  32. * the provisions above, a recipient may use your version of this file under
  33. * the terms of any one of the MPL, the GPL or the LGPL.
  34. *
  35. * ***** END LICENSE BLOCK ***** */
  36. /*
  37. * Public prototypes for base64 encoding/decoding.
  38. *
  39. * $Id: nssb64.h,v 1.4 2007/10/12 01:44:51 julien.pierre.boogz%sun.com Exp $
  40. */
  41. #ifndef _NSSB64_H_
  42. #define _NSSB64_H_
  43. #include "utilrename.h"
  44. #include "seccomon.h"
  45. #include "nssb64t.h"
  46. SEC_BEGIN_PROTOS
  47. /*
  48. * Functions to start a base64 decoding/encoding context.
  49. */
  50. extern NSSBase64Decoder *
  51. NSSBase64Decoder_Create (PRInt32 (*output_fn) (void *, const unsigned char *,
  52. PRInt32),
  53. void *output_arg);
  54. extern NSSBase64Encoder *
  55. NSSBase64Encoder_Create (PRInt32 (*output_fn) (void *, const char *, PRInt32),
  56. void *output_arg);
  57. /*
  58. * Push data through the decoder/encoder, causing the output_fn (provided
  59. * to Create) to be called with the decoded/encoded data.
  60. */
  61. extern SECStatus
  62. NSSBase64Decoder_Update (NSSBase64Decoder *data, const char *buffer,
  63. PRUint32 size);
  64. extern SECStatus
  65. NSSBase64Encoder_Update (NSSBase64Encoder *data, const unsigned char *buffer,
  66. PRUint32 size);
  67. /*
  68. * When you're done processing, call this to close the context.
  69. * If "abort_p" is false, then calling this may cause the output_fn
  70. * to be called one last time (as the last buffered data is flushed out).
  71. */
  72. extern SECStatus
  73. NSSBase64Decoder_Destroy (NSSBase64Decoder *data, PRBool abort_p);
  74. extern SECStatus
  75. NSSBase64Encoder_Destroy (NSSBase64Encoder *data, PRBool abort_p);
  76. /*
  77. * Perform base64 decoding from an ascii string "inStr" to an Item.
  78. * The length of the input must be provided as "inLen". The Item
  79. * may be provided (as "outItemOpt"); you can also pass in a NULL
  80. * and the Item will be allocated for you.
  81. *
  82. * In any case, the data within the Item will be allocated for you.
  83. * All allocation will happen out of the passed-in "arenaOpt", if non-NULL.
  84. * If "arenaOpt" is NULL, standard allocation (heap) will be used and
  85. * you will want to free the result via SECITEM_FreeItem.
  86. *
  87. * Return value is NULL on error, the Item (allocated or provided) otherwise.
  88. */
  89. extern SECItem *
  90. NSSBase64_DecodeBuffer (PRArenaPool *arenaOpt, SECItem *outItemOpt,
  91. const char *inStr, unsigned int inLen);
  92. /*
  93. * Perform base64 encoding of binary data "inItem" to an ascii string.
  94. * The output buffer may be provided (as "outStrOpt"); you can also pass
  95. * in a NULL and the buffer will be allocated for you. The result will
  96. * be null-terminated, and if the buffer is provided, "maxOutLen" must
  97. * specify the maximum length of the buffer and will be checked to
  98. * supply sufficient space space for the encoded result. (If "outStrOpt"
  99. * is NULL, "maxOutLen" is ignored.)
  100. *
  101. * If "outStrOpt" is NULL, allocation will happen out of the passed-in
  102. * "arenaOpt", if *it* is non-NULL, otherwise standard allocation (heap)
  103. * will be used.
  104. *
  105. * Return value is NULL on error, the output buffer (allocated or provided)
  106. * otherwise.
  107. */
  108. extern char *
  109. NSSBase64_EncodeItem (PRArenaPool *arenaOpt, char *outStrOpt,
  110. unsigned int maxOutLen, SECItem *inItem);
  111. SEC_END_PROTOS
  112. #endif /* _NSSB64_H_ */