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