2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved.
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
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.
22 #ifndef _H_CDSA_CLIENT_KEYCLIENT
23 #define _H_CDSA_CLIENT_KEYCLIENT 1
25 #include <security_cdsa_client/aclclient.h>
26 #include <security_cdsa_client/cspclient.h>
37 class KeyImpl
: public ObjectImpl
, public AclBearer
, public CssmKey
40 KeyImpl(const CSP
&csp
);
41 KeyImpl(const CSP
&csp
, const CSSM_KEY
&key
, bool copy
= false);
42 KeyImpl(const CSP
&csp
, const CSSM_DATA
&keyData
);
45 CSP
csp() const { return parent
<CSP
>(); }
46 void deleteKey(const CSSM_ACCESS_CREDENTIALS
*cred
);
48 CssmKeySize
sizeInBits() const;
51 void getAcl(AutoAclEntryInfoList
&aclInfos
, const char *selectionTag
= NULL
) const;
52 void changeAcl(const CSSM_ACL_EDIT
&aclEdit
,
53 const CSSM_ACCESS_CREDENTIALS
*accessCred
);
55 // Acl owner manipulation
56 void getOwner(AutoAclOwnerPrototype
&owner
) const;
57 void changeOwner(const CSSM_ACL_OWNER_PROTOTYPE
&newOwner
,
58 const CSSM_ACCESS_CREDENTIALS
*accessCred
= NULL
);
60 // Call this after completing the CSSM API call after having called Key::makeNewKey()
67 class Key
: public Object
71 explicit Key(Impl
*impl
) : Object(impl
) {}
73 Key() : Object(NULL
) {}
74 Key(const CSP
&csp
, const CSSM_KEY
&key
, bool copy
= false) : Object(new Impl(csp
, key
, copy
)) {}
75 Key(const CSP
&csp
, const CSSM_DATA
&keyData
) : Object(new Impl(csp
, keyData
)) {}
77 // Creates an inactive key, client must call activate() after this.
78 Key(const CSP
&csp
) : Object(new Impl(csp
)) {}
80 Impl
*operator ->() const { return (*this) ? &impl
<Impl
>() : NULL
; }
81 Impl
&operator *() const { return impl
<Impl
>(); }
83 // Conversion operators to CssmKey baseclass.
84 operator const CssmKey
* () const { return (*this) ? &(**this) : NULL
; }
85 operator const CssmKey
& () const { return **this; }
87 // a few shortcuts to make life easier
88 CssmKey::Header
&header() const { return (*this)->header(); }
90 // Creates an inactive key, client must call activate() after this.
91 CssmKey
*makeNewKey(const CSP
&csp
) { (*this) = Key(csp
); return &(**this); }
94 CssmKeySize
sizeInBits() const { return (*this)->sizeInBits(); }
100 CSSM_KEYATTR_FLAGS attributes
;
101 const CssmData
*label
;
104 KeySpec(CSSM_KEYUSE u
, CSSM_KEYATTR_FLAGS a
) : usage(u
), attributes(a
), label(NULL
) { }
105 KeySpec(CSSM_KEYUSE u
, CSSM_KEYATTR_FLAGS a
, const CssmData
&l
) : usage(u
), attributes(a
), label(&l
) { }
108 } // end namespace CssmClient
110 } // end namespace Security
113 #endif // _H_CDSA_CLIENT_KEYCLIENT