]>
git.saurik.com Git - apple/security.git/blob - libsecurity_utilities/lib/muscle++.h
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 // C++ gate to "Muscle" smartcard interface layer
29 // Note: This is written to go together with <pcsc++.h>, rather than stand on
30 // its own. It doesn't represent a "all Muscle" view of the card world.
35 #include <security_utilities/refcount.h>
36 #include <security_utilities/pcsc++.h>
37 #include <PCSC/musclecard.h>
46 // Muscle-domain error exceptions
48 class Error
: public CommonError
{
53 OSStatus
osStatus() const;
54 int unixError() const;
55 const char *what () const throw ();
57 static void check(MSC_RV err
) { if (err
!= MSC_SUCCESS
) throwMe(err
); }
58 static void throwMe(MSC_RV err
);
63 // Unified ACLs of the Muscle kind
67 typedef MSCUShort16 Value
;
69 ACL(Value write
= MSC_AUT_ALL
, Value read
= MSC_AUT_ALL
, Value erase
= MSC_AUT_ALL
);
71 ACL() { mRead
= mWrite
= mErase
= MSC_AUT_ALL
; }
73 operator MSCKeyACL () const;
74 operator MSCObjectACL () const;
76 Value
read() const { return mRead
; }
77 bool read(Value mask
) const { return mRead
& mask
; }
78 Value
&read() { return mRead
; }
79 Value
write() const { return mWrite
; }
80 bool write(Value mask
) const { return mWrite
& mask
; }
81 Value
&write() { return mWrite
; }
82 Value
erase() const { return mErase
; }
83 bool erase(Value mask
) const { return mErase
& mask
; }
84 Value
&erase() { return mErase
; }
85 // erase is "use" on keys; they're synonymous
86 Value
use() const { return mErase
; }
87 bool use(Value mask
) const { return mErase
& mask
; }
88 Value
&use() { return mErase
; }
90 string
form(char ue
) const;
100 // Muscle item representations (keys and objects unified, the cheap way)
102 class CardItem
: public RefCount
{
109 virtual unsigned size() const = 0;
110 virtual const char *name() const = 0;
112 virtual const ACL
&acl() const = 0;
113 virtual ACL
&acl() = 0;
115 virtual void debugDump() = 0;
117 bool operator < (const CardItem
&other
) const { return this < &other
; }
120 class Key
: public CardItem
, public MSCKeyInfo
{
122 Key(const MSCKeyInfo
&info
);
124 unsigned id() const { return this->keyNum
; }
125 const char *name() const;
126 unsigned type() const { return this->keyType
; }
127 unsigned size() const;
128 unsigned mode() const { return this->keyPolicy
.cipherMode
; }
129 unsigned operations() const { return this->keyPolicy
.cipherDirection
; }
131 const ACL
&acl() const;
137 char mKeyName
[8]; // made-up name "Kn"
140 class Object
: public CardItem
, public MSCObjectInfo
{
142 Object(const MSCObjectInfo
&info
) : MSCObjectInfo(info
) { }
144 const char *name() const;
145 unsigned size() const;
147 const ACL
&acl() const;
155 // A Muscle connection to a card.
156 // This is NOT a PodWrapper (for MSCTokenConnection or anything else).
160 class Connection
: public MSCTokenConnection
, public MSCStatusInfo
{
165 void open(const PCSC::ReaderState
&reader
, unsigned share
= MSC_SHARE_EXCLUSIVE
);
168 operator bool () const { return mIsOpen
; }
170 void begin(Transaction
*trans
= NULL
);
171 void end(Transaction
*trans
= NULL
);
172 Transaction
*currentTransaction() const;
174 typedef set
<RefPointer
<CardItem
> > ItemSet
;
175 void getItems(ItemSet
&items
, bool getKeys
= true, bool getOthers
= true);
181 Transaction
*mCurrentTransaction
;
187 Transaction(Connection
&con
);
190 Connection
&connection
;
194 } // namespace Muscle
195 } // namespace Security
198 #endif //_H_MUSCLE_PP