]>
git.saurik.com Git - apple/securityd.git/blob - src/pcsc++.h
6c839aa532c1ff2df9e757bbb5d2cb96e8d09e58
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 // pcsc++ - PCSC client interface layer in C++
30 // NOTE: TO BE MOVED TO security_utilities LAYER.
35 #include <security_utilities/utilities.h>
36 #include <security_utilities/errors.h>
37 #include <security_utilities/debugging.h>
38 #include <PCSC/winscard.h>
50 // PCSC-domain error exceptions
52 class Error
: public CommonError
{
57 OSStatus
osStatus() const;
58 int unixError() const;
59 const char *what () const throw ();
61 static void check(long err
) { if (err
!= SCARD_S_SUCCESS
) throwMe(err
); }
62 static void throwMe(long err
);
65 IFDEBUG(void debugDiagnose(const void *id
) const);
70 // A PODWrapper for the PCSC READERSTATE structure
72 class ReaderState
: public PodWrapper
<ReaderState
, SCARD_READERSTATE
> {
74 void set(const char *name
, unsigned long known
= SCARD_STATE_UNAWARE
);
76 const char *name() const { return szReader
; }
77 void name(const char *s
) { szReader
= s
; }
79 unsigned long lastKnown() const { return dwCurrentState
; }
80 void lastKnown(unsigned long s
);
82 unsigned long state() const { return dwEventState
; }
83 bool state(unsigned long it
) const { return state() & it
; }
84 bool changed() const { return state(SCARD_STATE_CHANGED
); }
87 T
* &userData() { return reinterpret_cast<T
* &>(pvUserData
); }
89 // DataOid access to the ATR data
90 const void *data() const { return rgbAtr
; }
91 size_t length() const { return cbAtr
; }
98 // A Session represents the entire process state for the PCSC protocol
107 bool isOpen() const { return mIsOpen
; }
109 void listReaders(vector
<string
> &readers
, const char *groups
= NULL
);
111 void statusChange(ReaderState
*readers
, unsigned int nReaders
,
113 void statusChange(vector
<ReaderState
> &readers
, long timeout
= 0)
114 { statusChange(&readers
[0], readers
.size(), timeout
); }
121 SCARDCONTEXT mContext
;
122 std::vector
<char> mReaderBuffer
;
127 // A Card represents a PCSC-managed card slot
131 static const unsigned long defaultProtocols
= SCARD_PROTOCOL_T0
| SCARD_PROTOCOL_T1
;
136 void open(Session
&session
, const char *reader
,
137 unsigned long share
= SCARD_SHARE_SHARED
,
138 unsigned long protocols
= defaultProtocols
);
139 void close(unsigned long disposition
= SCARD_LEAVE_CARD
);
144 unsigned long mProtocol
;
149 } // namespace Security