]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/libDER/libDER/DER_Encode.h
bcde9757119e1714a679af50480183c02758ade9
2 * Copyright (c) 2005-2016 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_
33 #include <libDER/libDER.h>
38 * Max size of an encoded item given its length.
39 * This includes a possible leading zero prepended to a signed integer
40 * (see DER_ENC_SIGNED_INT below).
42 #define DER_MAX_ENCODED_SIZE(len) \
44 5 + /* max length */ \
45 1 + /* possible prepended zero */ \
48 /* calculate size of encoded length */
49 DERSize
DERLengthOfLength(
53 DERReturn
DEREncodeLength(
55 DERByte
*buf
, /* encoded length goes here */
56 DERSize
*inOutLen
); /* IN/OUT */
58 /* calculate size of encoded length */
59 DERSize
DERLengthOfItem(
64 DERReturn
DEREncodeItem(
68 DERByte
*derOut
, /* encoded item goes here */
69 DERSize
*inOutLen
); /* IN/OUT */
72 * Per-item encode options.
75 /* explicit default, no options */
76 #define DER_ENC_NO_OPTS 0x0000
78 /* signed integer check: if incoming m.s. bit is 1, prepend a zero */
79 #define DER_ENC_SIGNED_INT 0x0100
81 /* DERItem contains fully encoded item - copy, don't encode */
82 #define DER_ENC_WRITE_DER 0x0200
86 * High-level sequence or set encode support.
88 * The outgoing sequence is expressed as an array of DERItemSpecs, each
89 * of which corresponds to one item in the encoded sequence.
91 * Normally the tag of the encoded item comes from the associated
92 * DERItemSpec, and the content comes from the DERItem whose address is
93 * the src arg plus the offset value in the associated DERItemSpec.
95 * If the DER_ENC_WRITE_DER option is true for a given DERItemSpec then
96 * no per-item encoding is done; the DER - with tag, length, and content -
97 * is taken en masse from the associated DERItem.
99 DERReturn
DEREncodeSequence(
100 DERTag topTag
, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
101 const void *src
, /* generally a ptr to a struct full of
103 DERShort numItems
, /* size of itemSpecs[] */
104 const DERItemSpec
*itemSpecs
,
105 DERByte
*derOut
, /* encoded data written here */
106 DERSize
*inOutLen
); /* IN/OUT */
108 /* precalculate the length of an encoded sequence. */
109 DERSize
DERLengthOfEncodedSequence(
110 DERTag topTag
, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
111 const void *src
, /* generally a ptr to a struct full of
113 DERShort numItems
, /* size of itemSpecs[] */
114 const DERItemSpec
*itemSpecs
);
119 #endif /* _DER_ENCODE_H_ */