]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/osxsigner.h
Security-54.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 Digester; friend class Digester;
44 public:
45 class OSXSignature;
46
47 OSXSigner();
48 OSXSignature *sign(const Signable &target);
49 bool verify(const Signable &target, const Signature *signature);
50
51 OSXSignature *restore(uint32 type, const void *data, size_t length);
52
53 public:
54 class OSXSignature : public Signature {
55 public:
56 static const size_t hashLength = 20; // length of signature data
57 typedef uint8 Hash[hashLength];
58
59 OSXSignature(const void *src) { memcpy(mData, src, hashLength); }
60
61 bool operator == (const Signature &other) const
62 {
63 if (const OSXSignature *sig = dynamic_cast<const OSXSignature *>(&other))
64 return !memcmp(mData, sig->mData, hashLength);
65 else
66 return false;
67 }
68
69 bool operator == (void *bytes) const
70 { return !memcmp(mData, bytes, hashLength); }
71
72 uint32 type() const { return standardOSXSignature; }
73 const void *data() const { return mData; }
74 size_t length() const { return hashLength; }
75
76 private:
77 uint8 mData[hashLength];
78 };
79
80 private:
81 class Digester : public State, public CssmClient::Digest {
82 public:
83 Digester(OSXSigner &sgn) : State(sgn), CssmClient::Digest(sgn.csp, CSSM_ALGID_SHA1) { }
84
85 void enumerateContents(const void *addr, size_t length);
86 };
87
88 private:
89 // CDSA resources
90 CssmClient::CSP csp;
91 };
92
93 } // end namespace CodeSigning
94
95 } // end namespace Security
96
97 #ifdef _CPP_OSXSIGNER
98 #pragma export off
99 #endif
100
101
102 #endif //_H_OSXSIGNER