PageRenderTime 30ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/secder.h

http://firefox-mac-pdf.googlecode.com/
C Header | 211 lines | 45 code | 32 blank | 134 comment | 0 complexity | d3e1d91d8dac31fdda2d37d683702168 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. #ifndef _SECDER_H_
  37. #define _SECDER_H_
  38. #include "utilrename.h"
  39. /*
  40. * secder.h - public data structures and prototypes for the DER encoding and
  41. * decoding utilities library
  42. *
  43. * $Id: secder.h,v 1.11 2007/10/12 01:44:51 julien.pierre.boogz%sun.com Exp $
  44. */
  45. #if defined(_WIN32_WCE)
  46. #else
  47. #include <time.h>
  48. #endif
  49. #include "plarena.h"
  50. #include "prlong.h"
  51. #include "seccomon.h"
  52. #include "secdert.h"
  53. #include "prtime.h"
  54. SEC_BEGIN_PROTOS
  55. /*
  56. ** Encode a data structure into DER.
  57. ** "dest" will be filled in (and memory allocated) to hold the der
  58. ** encoded structure in "src"
  59. ** "t" is a template structure which defines the shape of the
  60. ** stored data
  61. ** "src" is a pointer to the structure that will be encoded
  62. */
  63. extern SECStatus DER_Encode(PRArenaPool *arena, SECItem *dest, DERTemplate *t,
  64. void *src);
  65. extern SECStatus DER_Lengths(SECItem *item, int *header_len_p,
  66. PRUint32 *contents_len_p);
  67. /*
  68. ** Lower level der subroutine that stores the standard header into "to".
  69. ** The header is of variable length, based on encodingLen.
  70. ** The return value is the new value of "to" after skipping over the header.
  71. ** "to" is where the header will be stored
  72. ** "code" is the der code to write
  73. ** "encodingLen" is the number of bytes of data that will follow
  74. ** the header
  75. */
  76. extern unsigned char *DER_StoreHeader(unsigned char *to, unsigned int code,
  77. PRUint32 encodingLen);
  78. /*
  79. ** Return the number of bytes it will take to hold a der encoded length.
  80. */
  81. extern int DER_LengthLength(PRUint32 len);
  82. /*
  83. ** Store a der encoded *signed* integer (whose value is "src") into "dst".
  84. ** XXX This should really be enhanced to take a long.
  85. */
  86. extern SECStatus DER_SetInteger(PRArenaPool *arena, SECItem *dst, PRInt32 src);
  87. /*
  88. ** Store a der encoded *unsigned* integer (whose value is "src") into "dst".
  89. ** XXX This should really be enhanced to take an unsigned long.
  90. */
  91. extern SECStatus DER_SetUInteger(PRArenaPool *arena, SECItem *dst, PRUint32 src);
  92. /*
  93. ** Decode a der encoded *signed* integer that is stored in "src".
  94. ** If "-1" is returned, then the caller should check the error in
  95. ** XP_GetError() to see if an overflow occurred (SEC_ERROR_BAD_DER).
  96. */
  97. extern long DER_GetInteger(SECItem *src);
  98. /*
  99. ** Decode a der encoded *unsigned* integer that is stored in "src".
  100. ** If the ULONG_MAX is returned, then the caller should check the error
  101. ** in XP_GetError() to see if an overflow occurred (SEC_ERROR_BAD_DER).
  102. */
  103. extern unsigned long DER_GetUInteger(SECItem *src);
  104. /*
  105. ** Convert a "UNIX" time value to a der encoded time value.
  106. ** "result" is the der encoded time (memory is allocated)
  107. ** "time" is the "UNIX" time value (Since Jan 1st, 1970).
  108. ** time must be on or after January 1, 1950, and
  109. ** before January 1, 2050
  110. ** The caller is responsible for freeing up the buffer which
  111. ** result->data points to upon a successful operation.
  112. */
  113. extern SECStatus DER_TimeToUTCTime(SECItem *result, int64 time);
  114. extern SECStatus DER_TimeToUTCTimeArena(PRArenaPool* arenaOpt,
  115. SECItem *dst, int64 gmttime);
  116. /*
  117. ** Convert an ascii encoded time value (according to DER rules) into
  118. ** a UNIX time value.
  119. ** "result" the resulting "UNIX" time
  120. ** "string" the der notation ascii value to decode
  121. */
  122. extern SECStatus DER_AsciiToTime(int64 *result, const char *string);
  123. /*
  124. ** Same as DER_AsciiToTime except takes an SECItem instead of a string
  125. */
  126. extern SECStatus DER_UTCTimeToTime(int64 *result, const SECItem *time);
  127. /*
  128. ** Convert a DER encoded UTC time to an ascii time representation
  129. ** "utctime" is the DER encoded UTC time to be converted. The
  130. ** caller is responsible for deallocating the returned buffer.
  131. */
  132. extern char *DER_UTCTimeToAscii(SECItem *utcTime);
  133. /*
  134. ** Convert a DER encoded UTC time to an ascii time representation, but only
  135. ** include the day, not the time.
  136. ** "utctime" is the DER encoded UTC time to be converted.
  137. ** The caller is responsible for deallocating the returned buffer.
  138. */
  139. extern char *DER_UTCDayToAscii(SECItem *utctime);
  140. /* same thing for DER encoded GeneralizedTime */
  141. extern char *DER_GeneralizedDayToAscii(SECItem *gentime);
  142. /* same thing for either DER UTCTime or GeneralizedTime */
  143. extern char *DER_TimeChoiceDayToAscii(SECItem *timechoice);
  144. /*
  145. ** Convert a int64 time to a DER encoded Generalized time
  146. ** gmttime must be on or after January 1, year 1 and
  147. ** before January 1, 10000.
  148. */
  149. extern SECStatus DER_TimeToGeneralizedTime(SECItem *dst, int64 gmttime);
  150. extern SECStatus DER_TimeToGeneralizedTimeArena(PRArenaPool* arenaOpt,
  151. SECItem *dst, int64 gmttime);
  152. /*
  153. ** Convert a DER encoded Generalized time value into a UNIX time value.
  154. ** "dst" the resulting "UNIX" time
  155. ** "string" the der notation ascii value to decode
  156. */
  157. extern SECStatus DER_GeneralizedTimeToTime(int64 *dst, const SECItem *time);
  158. /*
  159. ** Convert from a int64 UTC time value to a formatted ascii value. The
  160. ** caller is responsible for deallocating the returned buffer.
  161. */
  162. extern char *CERT_UTCTime2FormattedAscii (int64 utcTime, char *format);
  163. #define CERT_GeneralizedTime2FormattedAscii CERT_UTCTime2FormattedAscii
  164. /*
  165. ** Convert from a int64 Generalized time value to a formatted ascii value. The
  166. ** caller is responsible for deallocating the returned buffer.
  167. */
  168. extern char *CERT_GenTime2FormattedAscii (int64 genTime, char *format);
  169. /*
  170. ** decode a SECItem containing either a SEC_ASN1_GENERALIZED_TIME
  171. ** or a SEC_ASN1_UTC_TIME
  172. */
  173. extern SECStatus DER_DecodeTimeChoice(PRTime* output, const SECItem* input);
  174. /* encode a PRTime to an ASN.1 DER SECItem containing either a
  175. SEC_ASN1_GENERALIZED_TIME or a SEC_ASN1_UTC_TIME */
  176. extern SECStatus DER_EncodeTimeChoice(PRArenaPool* arena, SECItem* output,
  177. PRTime input);
  178. SEC_END_PROTOS
  179. #endif /* _SECDER_H_ */