]>
git.saurik.com Git - apple/security.git/blob - libsecurity_asn1/lib/SecAsn1Coder.h
2 * Copyright (c) 2003-2006,2008-2010 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@
23 * SecAsn1Coder.h: ANS1 encode/decode object.
25 * A SecAsn1Coder is capable of encoding and decoding both DER and BER data
26 * streams, based on caller-supplied templates which in turn are based
27 * upon ASN.1 specifications. A SecAsn1Coder allocates memory during encode
28 * and decode using a memory pool which is owned and managed by the SecAsn1Coder
29 * object, and which is freed when the SecAsn1Coder object os released.
32 #ifndef _SEC_ASN1_CODER_H_
33 #define _SEC_ASN1_CODER_H_
35 #include <sys/types.h>
36 #include <Security/SecAsn1Types.h>
37 #include <TargetConditionals.h>
38 #include <Security/SecBase.h> /* error codes */
45 * Opaque reference to a SecAsn1Coder object.
47 typedef struct SecAsn1Coder
*SecAsn1CoderRef
;
50 * Create/destroy SecAsn1Coder object.
52 OSStatus
SecAsn1CoderCreate(
53 SecAsn1CoderRef
*coder
);
55 OSStatus
SecAsn1CoderRelease(
56 SecAsn1CoderRef coder
);
59 * DER decode an untyped item per the specified template array.
60 * The result is allocated in this SecAsn1Coder's memory pool and
61 * is freed when this object is released.
63 * The templates argument points to a an array of SecAsn1Templates
64 * defining the object to be decoded; the end of the array is
65 * indicated by a SecAsn1Template with file kind equalling 0.
67 * The dest pointer is a template-specific struct allocated by the caller
68 * and must be zeroed by the caller.
70 * Returns errSecUnknownFormat on decode-specific error.
72 OSStatus
SecAsn1Decode(
73 SecAsn1CoderRef coder
,
74 const void *src
, // DER-encoded source
76 const SecAsn1Template
*templates
,
80 * Convenience routine, decode from a SecAsn1Item.
82 OSStatus
SecAsn1DecodeData(
83 SecAsn1CoderRef coder
,
84 const SecAsn1Item
*src
,
85 const SecAsn1Template
*templ
,
89 * DER encode. The encoded data (in dest.Data) is allocated in this
90 * SecAsn1Coder's memory pool and is freed when this object is released.
92 * The src pointer is a template-specific struct.
94 * The templates argument points to a an array of SecAsn1Templates
95 * defining the object to be decoded; the end of the array is
96 * indicated by a SecAsn1Template with file kind equalling 0.
98 OSStatus
SecAsn1EncodeItem(
99 SecAsn1CoderRef coder
,
101 const SecAsn1Template
*templates
,
105 * Some alloc-related methods which come in handy when using
106 * this object. All memory is allocated using this object's
107 * memory pool. Caller never has to free it. Used for
108 * temp allocs of memory which only needs a scope which is the
109 * same as this object.
111 * All except SecAsn1Malloc return a memFullErr in the highly
112 * unlikely event of a malloc failure.
114 * SecAsn1Malloc() returns a pointer to allocated memory, like
118 SecAsn1CoderRef coder
,
121 /* Allocate item.Data, set item.Length */
122 OSStatus
SecAsn1AllocItem(
123 SecAsn1CoderRef coder
,
127 /* Allocate and copy, various forms */
128 OSStatus
SecAsn1AllocCopy(
129 SecAsn1CoderRef coder
,
130 const void *src
, /* memory copied from here */
131 size_t len
, /* length to allocate & copy */
132 SecAsn1Item
*dest
); /* dest->Data allocated and copied to;
133 * dest->Length := len */
135 OSStatus
SecAsn1AllocCopyItem(
136 SecAsn1CoderRef coder
,
137 const SecAsn1Item
*src
, /* src->Length bytes allocated and copied from
139 SecAsn1Item
*dest
); /* dest->Data allocated and copied to;
140 * dest->Length := src->Length */
142 /* Compare two decoded OIDs. Returns true iff they are equivalent. */
143 bool SecAsn1OidCompare(const SecAsn1Oid
*oid1
, const SecAsn1Oid
*oid2
);
149 #endif /* _SEC_ASN1_CODER_H_ */