OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
DER_Encode.h
Go to the documentation of this file.
1/* Copyright (c) 2005-2007 Apple Inc. All Rights Reserved. */
2
3/*
4 * DER_Encode.h - DER encoding routines
5 *
6 * Created Dec. 2 2005 by dmitch
7 */
8
9#ifndef _DER_ENCODE_H_
10#define _DER_ENCODE_H_
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include "libDER.h"
17
18/*
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).
22 */
23#define DER_MAX_ENCODED_SIZE(len) \
24 ( 1 + /* tag */ \
25 5 + /* max length */ \
26 1 + /* possible prepended zero */ \
27 len)
28
29/* calculate size of encoded length */
31 DERSize length);
32
33/* encode length */
35 DERSize length,
36 DERByte *buf, /* encoded length goes here */
37 DERSize *inOutLen); /* IN/OUT */
38
39/* calculate size of encoded length */
41 DERTag tag,
42 DERSize length);
43
44/* encode item */
46 DERTag tag,
47 DERSize length,
48 const DERByte *src,
49 DERByte *derOut, /* encoded item goes here */
50 DERSize *inOutLen); /* IN/OUT */
51
52/*
53 * Per-item encode options.
54 */
55
56/* explicit default, no options */
57#define DER_ENC_NO_OPTS 0x0000
58
59/* signed integer check: if incoming m.s. bit is 1, prepend a zero */
60#define DER_ENC_SIGNED_INT 0x0100
61
62/* DERItem contains fully encoded item - copy, don't encode */
63#define DER_ENC_WRITE_DER 0x0200
64
65
66/*
67 * High-level sequence or set encode support.
68 *
69 * The outgoing sequence is expressed as an array of DERItemSpecs, each
70 * of which corresponds to one item in the encoded sequence.
71 *
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.
75 *
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.
79 */
81 DERTag topTag, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
82 const void *src, /* generally a ptr to a struct full of
83 * DERItems */
84 DERShort numItems, /* size of itemSpecs[] */
85 const DERItemSpec *itemSpecs,
86 DERByte *derOut, /* encoded data written here */
87 DERSize *inOutLen); /* IN/OUT */
88
89/* precalculate the length of an encoded sequence. */
91 DERTag topTag, /* ASN1_CONSTR_SEQUENCE, ASN1_CONSTR_SET */
92 const void *src, /* generally a ptr to a struct full of
93 * DERItems */
94 DERShort numItems, /* size of itemSpecs[] */
95 const DERItemSpec *itemSpecs);
96
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* _DER_DECODE_H_ */
103
DERReturn DEREncodeSequence(DERTag topTag, const void *src, DERShort numItems, const DERItemSpec *itemSpecs, DERByte *derOut, DERSize *inOutLen)
DERReturn DEREncodeLength(DERSize length, DERByte *buf, DERSize *inOutLen)
DERSize DERLengthOfEncodedSequence(DERTag topTag, const void *src, DERShort numItems, const DERItemSpec *itemSpecs)
DERReturn DEREncodeItem(DERTag tag, DERSize length, const DERByte *src, DERByte *derOut, DERSize *inOutLen)
DERSize DERLengthOfItem(DERTag tag, DERSize length)
DERSize DERLengthOfLength(DERSize length)
DERReturn
Definition libDER.h:20
size_t DERSize
uint16_t DERShort
uint64_t DERTag
uint8_t DERByte