]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/signclient.h
Security-164.1.tar.gz
[apple/security.git] / cdsa / cdsa_client / signclient.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 // signclient - client interface to CSSM sign/verify contexts
21 //
22 #ifndef _H_CDSA_CLIENT_SIGNCLIENT
23 #define _H_CDSA_CLIENT_SIGNCLIENT 1
24
25 #include <Security/cspclient.h>
26 #include <Security/keyclient.h>
27
28 namespace Security
29 {
30
31 namespace CssmClient
32 {
33
34 //
35 // A signing/verifying context
36 //
37 class SigningContext : public Context
38 {
39 public:
40 SigningContext(const CSP &csp, CSSM_ALGORITHMS alg, CSSM_ALGORITHMS signOnly = CSSM_ALGID_NONE)
41 : Context(csp, alg), mSignOnly(signOnly) { }
42
43 Key key() const { assert(mKey); return mKey; }
44 void key(const Key &k) { mKey = k; set(CSSM_ATTRIBUTE_KEY, mKey); }
45
46 CSSM_ALGORITHMS signOnlyAlgorithm() const { return mSignOnly; }
47 void signOnlyAlgorithm(CSSM_ALGORITHMS alg) { mSignOnly = alg; }
48
49 protected:
50 void activate();
51 CSSM_ALGORITHMS mSignOnly;
52 Key mKey;
53 };
54
55
56 class Sign : public SigningContext
57 {
58 public:
59 Sign(const CSP &csp, CSSM_ALGORITHMS alg, CSSM_ALGORITHMS signOnly = CSSM_ALGID_NONE)
60 : SigningContext(csp, alg, signOnly) { }
61
62 // integrated
63 void sign(const CssmData &data, CssmData &signature) { sign(&data, 1, signature); }
64 void sign(const CssmData *data, uint32 count, CssmData &signature);
65
66 // staged
67 void init(); // Optional
68 void sign(const CssmData &data) { sign(&data, 1); }
69 void sign(const CssmData *data, uint32 count);
70 void operator () (CssmData &signature);
71 CssmData operator () () { CssmData signature; (*this)(signature); return signature; }
72 };
73
74 class Verify : public SigningContext
75 {
76 public:
77 Verify(const CSP &csp, CSSM_ALGORITHMS alg, CSSM_ALGORITHMS verifyOnly = CSSM_ALGID_NONE)
78 : SigningContext(csp, alg, verifyOnly) { }
79
80 // integrated
81 void verify(const CssmData &data, const CssmData &signature) { verify(&data, 1, signature); }
82 void verify(const CssmData *data, uint32 count, const CssmData &signature);
83
84 // staged
85 void init(); // Optional
86 void verify(const CssmData &data) { verify(&data, 1); }
87 void verify(const CssmData *data, uint32 count);
88 void operator () (const CssmData &signature);
89 };
90
91 } // end namespace CssmClient
92
93 } // end namespace Security
94
95 #endif // _H_CDSA_CLIENT_SIGNCLIENT