1/*
2 * Copyright (c) 2005-2007,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25/*
26 * libDER.h - main header for libDER, a ROM-capable DER decoding library.
27 *
28 */
29
30#ifndef	_LIB_DER_H_
31#define _LIB_DER_H_
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#include <libDER/libDER_config.h>
38/*
39 * Error returns generated by this library.
40 */
41typedef enum {
42	DR_Success,
43	DR_EndOfSequence,	/* end of sequence or set */
44	DR_UnexpectedTag,	/* unexpected tag found while decoding */
45	DR_DecodeError,		/* misc. decoding error (badly formatted DER) */
46	DR_Unimplemented,	/* function not implemented in this configuration */
47	DR_IncompleteSeq,	/* incomplete sequence */
48	DR_ParamErr,		/* incoming parameter error */
49	DR_BufOverflow		/* buffer overflow */
50	/* etc. */
51} DERReturn;
52
53/*
54 * Primary representation of a block of memory.
55 */
56typedef struct {
57	DERByte		*data;
58	DERSize		length;
59} DERItem;
60
61/*
62 * The structure of a sequence during decode or encode is expressed as
63 * an array of DERItemSpecs. While decoding or encoding a sequence,
64 * each item in the sequence corresponds to one DERItemSpec.
65 */
66typedef struct {
67	DERSize			offset;			/* offset of destination DERItem */
68	DERTag			tag;			/* DER tag */
69	DERShort		options;		/* DER_DEC_xxx or DER_ENC_xxx */
70} DERItemSpec;
71
72/*
73 * Macro to obtain offset of a DERDecodedInfo within a struct.
74 * FIXME this is going to need reworking to avoid compiler warnings
75 * on 64-bit compiles. It'll work OK as long as an offset can't be larger
76 * than a DERSize, but the cast from a pointer to a DERSize may
77 * provoke compiler warnings.
78 */
79#define DER_OFFSET(type, field) ((DERSize)(&((type *)0)->field))
80
81#ifdef __cplusplus
82}
83#endif
84
85#endif	/* _LIB_DER_H_ */
86
87