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// keyclient 21// 22#ifndef _H_CDSA_CLIENT_KEYCLIENT 23#define _H_CDSA_CLIENT_KEYCLIENT 1 24 25#include <security_cdsa_client/aclclient.h> 26#include <security_cdsa_client/cspclient.h> 27 28namespace Security 29{ 30 31namespace CssmClient 32{ 33 34// 35// Key 36// 37class KeyImpl : public ObjectImpl, public AclBearer, public CssmKey 38{ 39public: 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); 43 virtual ~KeyImpl(); 44 45 CSP csp() const { return parent<CSP>(); } 46 void deleteKey(const CSSM_ACCESS_CREDENTIALS *cred); 47 48 CssmKeySize sizeInBits() const; 49 50 // Acl manipulation 51 void getAcl(AutoAclEntryInfoList &aclInfos, const char *selectionTag = NULL) const; 52 void changeAcl(const CSSM_ACL_EDIT &aclEdit, 53 const CSSM_ACCESS_CREDENTIALS *accessCred); 54 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); 59 60 // Call this after completing the CSSM API call after having called Key::makeNewKey() 61 void activate(); 62 63protected: 64 void deactivate(); 65}; 66 67class Key : public Object 68{ 69public: 70 typedef KeyImpl Impl; 71 explicit Key(Impl *impl) : Object(impl) {} 72 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)) {} 76 77 // Creates an inactive key, client must call activate() after this. 78 Key(const CSP &csp) : Object(new Impl(csp)) {} 79 80 Impl *operator ->() const { return (*this) ? &impl<Impl>() : NULL; } 81 Impl &operator *() const { return impl<Impl>(); } 82 83 // Conversion operators to CssmKey baseclass. 84 operator const CssmKey * () const { return (*this) ? &(**this) : NULL; } 85 operator const CssmKey & () const { return **this; } 86 87 // a few shortcuts to make life easier 88 CssmKey::Header &header() const { return (*this)->header(); } 89 90 // Creates an inactive key, client must call activate() after this. 91 CssmKey *makeNewKey(const CSP &csp) { (*this) = Key(csp); return &(**this); } 92 93 // inquiries 94 CssmKeySize sizeInBits() const { return (*this)->sizeInBits(); } 95}; 96 97 98struct KeySpec { 99 CSSM_KEYUSE usage; 100 CSSM_KEYATTR_FLAGS attributes; 101 const CssmData *label; 102 //add rc context 103 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) { } 106}; 107 108} // end namespace CssmClient 109 110} // end namespace Security 111 112 113#endif // _H_CDSA_CLIENT_KEYCLIENT 114