]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/libDER/libDER/DER_Encode.h
6dc3d6360d079c7e1ed46392c85cb82cc5534110
2 * Copyright (c) 2005-2007,2011,2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 * DER_Encode.h - DER encoding routines
30 #ifndef _DER_ENCODE_H_
31 #define _DER_ENCODE_H_
37 #include <libDER/libDER.h>
40 * Max size of an encoded item given its length.
41 * This includes a possible leading zero prepended to a signed integer
42 * (see DER_ENC_SIGNED_INT below).
44 #define DER_MAX_ENCODED_SIZE(len) \
46 5 + /* max length */ \
47 1 + /* possible prepended zero */ \
50 /* calculate size of encoded length */
51 DERSize
DERLengthOfLength(
55 DERReturn
DEREncodeLength(
57 DERByte
*buf
, /* encoded length goes here */
58 DERSize
*inOutLen
); /* IN/OUT */
60 /* calculate size of encoded length */
61 DERSize
DERLengthOfItem(
66 DERReturn
DEREncodeItem(
70 DERByte
*derOut
, /* encoded item goes here */
71 DERSize
*inOutLen
); /* IN/OUT */
74 * Per-item encode options.
77 /* explicit default, no options */
78 #define DER_ENC_NO_OPTS 0x0000
80 /* signed integer check: if incoming m.s. bit is 1, prepend a zero */
81 #define DER_ENC_SIGNED_INT 0x0100
83 /* DERItem contains fully encoded item - copy, don't encode */
84 #define DER_ENC_WRITE_DER 0x0200
88 * High-level sequence or set encode support.
90 * The outgoing sequence is expressed as an array of DERItemSpecs, each
91 * of which corresponds to one item in the encoded sequence.
93 * Normally the tag of the encoded item comes from the associated
94 * DERItemSpec, and the content comes from the DERItem whose address is
95 * the src arg plus the offset value in the associated DERItemSpec.
97 * If the DER_ENC_WRITE_DER option is true for a given DERItemSpec then
98 * no per-item encoding is done; the DER - with tag, length, and content -
99 * is taken en masse from the associated DERItem.
101 DERReturn
DEREncodeSequence(
102 DERTag topTag
, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
103 const void *src
, /* generally a ptr to a struct full of
105 DERShort numItems
, /* size of itemSpecs[] */
106 const DERItemSpec
*itemSpecs
,
107 DERByte
*derOut
, /* encoded data written here */
108 DERSize
*inOutLen
); /* IN/OUT */
110 /* precalculate the length of an encoded sequence. */
111 DERSize
DERLengthOfEncodedSequence(
112 DERTag topTag
, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
113 const void *src
, /* generally a ptr to a struct full of
115 DERShort numItems
, /* size of itemSpecs[] */
116 const DERItemSpec
*itemSpecs
);
123 #endif /* _DER_ENCODE_H_ */