]>
git.saurik.com Git - apple/security.git/blob - libsecurity_keychain/libDER/libDER/DER_Encode.h
1 /* Copyright (c) 2005-2007 Apple Inc. All Rights Reserved. */
4 * DER_Encode.h - DER encoding routines
6 * Created Dec. 2 2005 by dmitch
9 #ifndef _DER_ENCCODE_H_
10 #define _DER_ENCODE_H_
16 #include <libDER/libDER.h>
19 * Max size of an encoded item given its length.
20 * This includes a possible leading zero prepended to a signed integer
21 * (see DER_ENC_SIGNED_INT below).
23 #define DER_MAX_ENCODED_SIZE(len) \
25 5 + /* max length */ \
26 1 + /* possible prepended zero */ \
29 /* calculate size of encoded length */
30 DERSize
DERLengthOfLength(
34 DERReturn
DEREncodeLength(
36 DERByte
*buf
, /* encoded length goes here */
37 DERSize
*inOutLen
); /* IN/OUT */
39 /* calculate size of encoded length */
40 DERSize
DERLengthOfItem(
45 DERReturn
DEREncodeItem(
49 DERByte
*derOut
, /* encoded item goes here */
50 DERSize
*inOutLen
); /* IN/OUT */
53 * Per-item encode options.
56 /* explicit default, no options */
57 #define DER_ENC_NO_OPTS 0x0000
59 /* signed integer check: if incoming m.s. bit is 1, prepend a zero */
60 #define DER_ENC_SIGNED_INT 0x0100
62 /* DERItem contains fully encoded item - copy, don't encode */
63 #define DER_ENC_WRITE_DER 0x0200
67 * High-level sequence or set encode support.
69 * The outgoing sequence is expressed as an array of DERItemSpecs, each
70 * of which corresponds to one item in the encoded sequence.
72 * Normally the tag of the encoded item comes from the associated
73 * DERItemSpec, and the content comes from the DERItem whose address is
74 * the src arg plus the offset value in the associated DERItemSpec.
76 * If the DER_ENC_WRITE_DER option is true for a given DERItemSpec then
77 * no per-item encoding is done; the DER - with tag, length, and content -
78 * is taken en masse from the associated DERItem.
80 DERReturn
DEREncodeSequence(
81 DERTag topTag
, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
82 const void *src
, /* generally a ptr to a struct full of
84 DERShort numItems
, /* size of itemSpecs[] */
85 const DERItemSpec
*itemSpecs
,
86 DERByte
*derOut
, /* encoded data written here */
87 DERSize
*inOutLen
); /* IN/OUT */
89 /* precalculate the length of an encoded sequence. */
90 DERSize
DERLengthOfEncodedSequence(
91 DERTag topTag
, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
92 const void *src
, /* generally a ptr to a struct full of
94 DERShort numItems
, /* size of itemSpecs[] */
95 const DERItemSpec
*itemSpecs
);
102 #endif /* _DER_DECODE_H_ */