]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/muscle++.h
2 * Copyright (c) 2004,2011,2014 Apple 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 <TargetConditionals.h>
39 #include <security_utilities/refcount.h>
40 #include <security_utilities/pcsc++.h>
41 #include <PCSC/musclecard.h>
50 // Muscle-domain error exceptions
52 class Error
: public CommonError
{
57 OSStatus
osStatus() const;
58 int unixError() const;
59 const char *what () const _NOEXCEPT
;
61 static void check(MSC_RV err
) { if (err
!= MSC_SUCCESS
) throwMe(err
); }
62 static void throwMe(MSC_RV err
);
67 // Unified ACLs of the Muscle kind
71 typedef MSCUShort16 Value
;
73 ACL(Value write
= MSC_AUT_ALL
, Value read
= MSC_AUT_ALL
, Value erase
= MSC_AUT_ALL
);
75 ACL() { mRead
= mWrite
= mErase
= MSC_AUT_ALL
; }
77 operator MSCKeyACL () const;
78 operator MSCObjectACL () const;
80 Value
read() const { return mRead
; }
81 bool read(Value mask
) const { return mRead
& mask
; }
82 Value
&read() { return mRead
; }
83 Value
write() const { return mWrite
; }
84 bool write(Value mask
) const { return mWrite
& mask
; }
85 Value
&write() { return mWrite
; }
86 Value
erase() const { return mErase
; }
87 bool erase(Value mask
) const { return mErase
& mask
; }
88 Value
&erase() { return mErase
; }
89 // erase is "use" on keys; they're synonymous
90 Value
use() const { return mErase
; }
91 bool use(Value mask
) const { return mErase
& mask
; }
92 Value
&use() { return mErase
; }
94 string
form(char ue
) const;
104 // Muscle item representations (keys and objects unified, the cheap way)
106 class CardItem
: public RefCount
{
113 virtual unsigned size() const = 0;
114 virtual const char *name() const = 0;
116 virtual const ACL
&acl() const = 0;
117 virtual ACL
&acl() = 0;
119 virtual void debugDump() = 0;
121 bool operator < (const CardItem
&other
) const { return this < &other
; }
124 class Key
: public CardItem
, public MSCKeyInfo
{
126 Key(const MSCKeyInfo
&info
);
128 unsigned id() const { return this->keyNum
; }
129 const char *name() const;
130 unsigned type() const { return this->keyType
; }
131 unsigned size() const;
132 unsigned mode() const { return this->keyPolicy
.cipherMode
; }
133 unsigned operations() const { return this->keyPolicy
.cipherDirection
; }
135 const ACL
&acl() const;
141 char mKeyName
[8]; // made-up name "Kn"
144 class Object
: public CardItem
, public MSCObjectInfo
{
146 Object(const MSCObjectInfo
&info
) : MSCObjectInfo(info
) { }
148 const char *name() const;
149 unsigned size() const;
151 const ACL
&acl() const;
159 // A Muscle connection to a card.
160 // This is NOT a PodWrapper (for MSCTokenConnection or anything else).
164 class Connection
: public MSCTokenConnection
, public MSCStatusInfo
{
169 void open(const PCSC::ReaderState
&reader
, unsigned share
= MSC_SHARE_EXCLUSIVE
);
172 operator bool () const { return mIsOpen
; }
174 void begin(Transaction
*trans
= NULL
);
175 void end(Transaction
*trans
= NULL
);
176 Transaction
*currentTransaction() const;
178 typedef set
<RefPointer
<CardItem
> > ItemSet
;
179 void getItems(ItemSet
&items
, bool getKeys
= true, bool getOthers
= true);
185 Transaction
*mCurrentTransaction
;
191 Transaction(Connection
&con
);
194 Connection
&connection
;
198 } // namespace Muscle
199 } // namespace Security
201 #endif //TARGET_OS_OSX
202 #endif //_H_MUSCLE_PP