2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Netscape security libraries.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1994-2000 Netscape Communications Corporation. All
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
35 * Support for encoding/decoding of ASN.1 using BER/DER (Basic/Distinguished
36 * Encoding Rules). The routines are found in and used extensively by the
37 * security library, but exported for other use.
39 * $Id: secasn1.h,v 1.8 2004/05/13 15:29:13 dmitch Exp $
45 #include <security_asn1/plarenas.h>
47 #include <security_asn1/seccomon.h>
48 #include <Security/secasn1t.h>
49 #include <Security/SecAsn1Templates.h>
52 /************************************************************************/
56 * XXX These function prototypes need full, explanatory comments.
63 extern SEC_ASN1DecoderContext
*SEC_ASN1DecoderStart(PRArenaPool
*pool
,
65 const SecAsn1Template
*t
,
69 * Only needed if first element will
74 /* XXX char or unsigned char? */
75 extern SECStatus
SEC_ASN1DecoderUpdate(SEC_ASN1DecoderContext
*cx
,
79 extern SECStatus
SEC_ASN1DecoderFinish(SEC_ASN1DecoderContext
*cx
);
81 /* Higher level code detected an error, abort the rest of the processing */
82 extern void SEC_ASN1DecoderAbort(SEC_ASN1DecoderContext
*cx
, int error
);
84 extern void SEC_ASN1DecoderSetFilterProc(SEC_ASN1DecoderContext
*cx
,
86 void *arg
, PRBool no_store
);
88 extern void SEC_ASN1DecoderClearFilterProc(SEC_ASN1DecoderContext
*cx
);
90 extern void SEC_ASN1DecoderSetNotifyProc(SEC_ASN1DecoderContext
*cx
,
91 SEC_ASN1NotifyProc fn
,
94 extern void SEC_ASN1DecoderClearNotifyProc(SEC_ASN1DecoderContext
*cx
);
96 extern SECStatus
SEC_ASN1Decode(PRArenaPool
*pool
, void *dest
,
97 const SecAsn1Template
*t
,
98 const char *buf
, size_t len
);
100 extern SECStatus
SEC_ASN1DecodeItem(PRArenaPool
*pool
, void *dest
,
101 const SecAsn1Template
*t
,
102 const SecAsn1Item
*item
);
104 extern SECStatus
SEC_QuickDERDecodeItem(PRArenaPool
* arena
, void* dest
,
105 const SecAsn1Template
* templateEntry
,
112 extern SEC_ASN1EncoderContext
*SEC_ASN1EncoderStart(const void *src
,
113 const SecAsn1Template
*t
,
114 SEC_ASN1WriteProc fn
,
117 /* XXX char or unsigned char? */
118 extern SECStatus
SEC_ASN1EncoderUpdate(SEC_ASN1EncoderContext
*cx
,
122 extern void SEC_ASN1EncoderFinish(SEC_ASN1EncoderContext
*cx
);
124 /* Higher level code detected an error, abort the rest of the processing */
125 extern void SEC_ASN1EncoderAbort(SEC_ASN1EncoderContext
*cx
, int error
);
127 extern void SEC_ASN1EncoderSetNotifyProc(SEC_ASN1EncoderContext
*cx
,
128 SEC_ASN1NotifyProc fn
,
131 extern void SEC_ASN1EncoderClearNotifyProc(SEC_ASN1EncoderContext
*cx
);
133 extern void SEC_ASN1EncoderSetStreaming(SEC_ASN1EncoderContext
*cx
);
135 extern void SEC_ASN1EncoderClearStreaming(SEC_ASN1EncoderContext
*cx
);
137 extern void sec_ASN1EncoderSetDER(SEC_ASN1EncoderContext
*cx
);
139 extern void sec_ASN1EncoderClearDER(SEC_ASN1EncoderContext
*cx
);
141 extern void SEC_ASN1EncoderSetTakeFromBuf(SEC_ASN1EncoderContext
*cx
);
143 extern void SEC_ASN1EncoderClearTakeFromBuf(SEC_ASN1EncoderContext
*cx
);
145 extern SECStatus
SEC_ASN1Encode(const void *src
,
146 const SecAsn1Template
*t
,
147 SEC_ASN1WriteProc output_proc
,
150 extern SecAsn1Item
* SEC_ASN1EncodeItem(PRArenaPool
*pool
, SecAsn1Item
*dest
,
151 const void *src
, const SecAsn1Template
*t
);
153 extern SecAsn1Item
* SEC_ASN1EncodeInteger(PRArenaPool
*pool
,
154 SecAsn1Item
*dest
, long value
);
156 extern SecAsn1Item
* SEC_ASN1EncodeUnsignedInteger(PRArenaPool
*pool
,
158 unsigned long value
);
160 extern SECStatus
SEC_ASN1DecodeInteger(SecAsn1Item
*src
,
161 unsigned long *value
);
168 * We have a length that needs to be encoded; how many bytes will the
171 extern int SEC_ASN1LengthLength (unsigned long len
);
173 /* encode the length and return the number of bytes we encoded. Buffer
174 * must be pre allocated */
175 extern int SEC_ASN1EncodeLength(unsigned char *buf
,unsigned long value
);
178 * Find the appropriate subtemplate for the given template.
179 * This may involve calling a "chooser" function, or it may just
180 * be right there. In either case, it is expected to *have* a
181 * subtemplate; this is asserted in debug builds (in non-debug
182 * builds, NULL will be returned).
184 * "thing" is a pointer to the structure being encoded/decoded
185 * "encoding", when true, means that we are in the process of encoding
186 * (as opposed to in the process of decoding)
188 extern const SecAsn1Template
*
189 SEC_ASN1GetSubtemplate (
190 const SecAsn1Template
*inTemplate
,
193 const char *buf
); /* __APPLE__ addenda: for decode only */
195 extern SecAsn1Item
*sec_asn1e_allocate_item (
201 * These two are exported for use by SecNssEncodeItem()
203 extern void sec_asn1e_encode_item_count (
208 SEC_ASN1EncodingPart data_kind
);
210 extern void sec_asn1e_encode_item_store (
215 SEC_ASN1EncodingPart data_kind
);
219 #endif /* _SECASN1_H_ */