]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/osxsigner.h
Security-30.1.tar.gz
[apple/security.git] / cdsa / cdsa_client / osxsigner.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 // osxsigner - MacOS X's standard code signing algorithm.
21 //
22 #ifndef _H_OSXSIGNER
23 #define _H_OSXSIGNER
24
25 #include <Security/osxsigning.h>
26 #include <Security/cspclient.h>
27 #include <string>
28
29 #ifdef _CPP_OSXSIGNER
30 #pragma export on
31 #endif
32
33 namespace Security
34 {
35
36 namespace CodeSigning
37 {
38
39 //
40 // The OSX standard signer object
41 //
42 class OSXSigner : public Signer {
43 class OSXSignature;
44 class Digester; friend class Digester;
45 public:
46 OSXSigner();
47 OSXSignature *sign(const Signable &target);
48 bool verify(const Signable &target, const Signature *signature);
49
50 OSXSignature *restore(uint32 type, const void *data, size_t length);
51
52 public:
53 class OSXSignature : public Signature {
54 public:
55 static const size_t hashLength = 20; // length of signature data
56 typedef uint8 Hash[hashLength];
57
58 OSXSignature(const void *src) { memcpy(mData, src, hashLength); }
59
60 bool operator == (const Signature &other) const
61 {
62 if (const OSXSignature *sig = dynamic_cast<const OSXSignature *>(&other))
63 return !memcmp(mData, sig->mData, hashLength);
64 else
65 return false;
66 }
67
68 bool operator == (void *bytes) const
69 { return !memcmp(mData, bytes, hashLength); }
70
71 uint32 type() const { return standardOSXSignature; }
72 const void *data() const { return mData; }
73 size_t length() const { return hashLength; }
74
75 private:
76 uint8 mData[hashLength];
77 };
78
79 private:
80 class Digester : public State, public CssmClient::Digest {
81 public:
82 Digester(OSXSigner &sgn) : State(sgn), CssmClient::Digest(sgn.csp, CSSM_ALGID_SHA1) { }
83
84 void enumerateContents(const void *addr, size_t length);
85 };
86
87 private:
88 // CDSA resources
89 CssmClient::CSP csp;
90 };
91
92 } // end namespace CodeSigning
93
94 } // end namespace Security
95
96 #ifdef _CPP_OSXSIGNER
97 #pragma export off
98 #endif
99
100
101 #endif //_H_OSXSIGNER