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