]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/inc/cdsaUtils.h
Security-28.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-lib / inc / cdsaUtils.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 * cdsaUtils.h - utility functions for CDSA-related code
21 */
22
23 #ifndef _SNACC_CDSA_UTILS_H_
24 #define _SNACC_CDSA_UTILS_H_
25
26 #include <Security/asn-incl.h>
27 #include <Security/utilities.h>
28 #include <Security/cssmdata.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /* all decoding errors throw CSSMERR_CL_UNKNOWN_FORMAT */
35
36 /* malloc/copy AsnBits.bits -->CssmOwnedData */
37 void SC_asnBitsToCssmData(
38 const AsnBits &bits,
39 CssmOwnedData &oData);
40
41 /* given DER-encoded bit string, decoded it and malloc/copy results
42 * back to a CssmOwnedData */
43 void SC_decodeAsnBitsToCssmData(
44 const CssmData encodedBits,
45 CssmOwnedData &oData);
46
47 /* DER-decode any AsnType object */
48 void SC_decodeAsnObj(
49 const CssmData &derEncoded,
50 AsnType &asnObj);
51
52 /* DER-encode any AsnType object. */
53 void SC_encodeAsnObj(
54 AsnType &asnObj,
55 CssmOwnedData &derEncoded,
56 size_t maxEncodedSize);
57
58 /*
59 * Given a contentLength, obtain the length of the DER length encoding.
60 */
61 size_t SC_lengthOfLength(
62 size_t contentLen);
63
64 /*
65 * Encode a DER length field. Pass in the lengthOfLength if you've obtained
66 * it in a previous call to CL_lengthOfLength.
67 */
68 void SC_encodeLength(
69 size_t contentLen,
70 void *cp,
71 size_t lengthOfLength = 0);
72
73 #ifdef __cplusplus
74 }
75 #endif
76
77 #endif /* _SNACC_CDSA_UTILS_H_ */