smartcard 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +2 -1
- data/Rakefile +7 -3
- data/lib/smartcard.rb +1 -1
- data/lib/smartcard/pcsc/exception.rb +15 -0
- data/lib/smartcard/pcsc/ffi_autogen.rb +180 -180
- data/lib/smartcard/pcsc/reader_state_queries.rb +18 -4
- data/smartcard.gemspec +12 -12
- data/test/pcsc/card_test.rb +0 -1
- data/test/pcsc/exception_test.rb +30 -0
- data/test/pcsc/reader_state_queries_test.rb +10 -0
- metadata +9 -7
- data/lib/smartcard/pcsc/pcsc_exception.rb +0 -10
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -19,11 +19,11 @@ lib/smartcard/iso/pcsc_transport.rb
|
|
19
19
|
lib/smartcard/iso/transport.rb
|
20
20
|
lib/smartcard/pcsc/card.rb
|
21
21
|
lib/smartcard/pcsc/context.rb
|
22
|
+
lib/smartcard/pcsc/exception.rb
|
22
23
|
lib/smartcard/pcsc/ffi_autogen.rb
|
23
24
|
lib/smartcard/pcsc/ffi_functions.rb
|
24
25
|
lib/smartcard/pcsc/ffi_lib.rb
|
25
26
|
lib/smartcard/pcsc/ffi_structs.rb
|
26
|
-
lib/smartcard/pcsc/pcsc_exception.rb
|
27
27
|
lib/smartcard/pcsc/reader_state_queries.rb
|
28
28
|
tasks/ffi_codegen.rb
|
29
29
|
test/gp/asn1_ber_test.rb
|
@@ -39,4 +39,5 @@ test/iso/iso_exception_test.rb
|
|
39
39
|
test/iso/jcop_remote_test.rb
|
40
40
|
test/pcsc/card_test.rb
|
41
41
|
test/pcsc/context_test.rb
|
42
|
+
test/pcsc/exception_test.rb
|
42
43
|
test/pcsc/reader_state_queries_test.rb
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'echoe'
|
3
3
|
|
4
|
-
require 'tasks/ffi_codegen.rb'
|
4
|
+
require './tasks/ffi_codegen.rb'
|
5
5
|
|
6
6
|
Echoe.new('smartcard') do |p|
|
7
7
|
p.project = 'smartcard' # rubyforge project
|
@@ -23,9 +23,13 @@ Echoe.new('smartcard') do |p|
|
|
23
23
|
/^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
24
24
|
end
|
25
25
|
|
26
|
+
file 'lib/smartcard/pcsc/ffi_autogen.rb' => 'tasks/ffi_codegen.rb' do
|
27
|
+
Smartcard::Tasks.generate_ffi_header
|
28
|
+
end
|
29
|
+
|
26
30
|
unless FFI::Platform.windows?
|
27
|
-
task :package =>
|
28
|
-
task :test =>
|
31
|
+
task :package => 'lib/smartcard/pcsc/ffi_autogen.rb'
|
32
|
+
task :test => 'lib/smartcard/pcsc/ffi_autogen.rb'
|
29
33
|
end
|
30
34
|
|
31
35
|
if $0 == __FILE__
|
data/lib/smartcard.rb
CHANGED
@@ -4,11 +4,11 @@ end
|
|
4
4
|
|
5
5
|
require 'smartcard/pcsc/card.rb'
|
6
6
|
require 'smartcard/pcsc/context.rb'
|
7
|
+
require 'smartcard/pcsc/exception.rb'
|
7
8
|
require 'smartcard/pcsc/ffi_lib.rb'
|
8
9
|
require 'smartcard/pcsc/ffi_autogen.rb'
|
9
10
|
require 'smartcard/pcsc/ffi_structs.rb'
|
10
11
|
require 'smartcard/pcsc/ffi_functions.rb'
|
11
|
-
require 'smartcard/pcsc/pcsc_exception.rb'
|
12
12
|
require 'smartcard/pcsc/reader_state_queries.rb'
|
13
13
|
|
14
14
|
require 'smartcard/iso/apdu_error.rb'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Contains information about an exception at the PC/SC layer.
|
2
|
+
class Smartcard::PCSC::Exception < RuntimeError
|
3
|
+
def initialize(error_status)
|
4
|
+
@pcsc_status_code = 2**32 + error_status
|
5
|
+
@pcsc_status = Smartcard::PCSC::FFILib::Status.find @pcsc_status_code
|
6
|
+
|
7
|
+
super "#{@pcsc_status} (0x#{@pcsc_status_code.to_s(16)})"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Symbol for the PC/SC error status that caused this error.
|
11
|
+
attr_reader :pcsc_status
|
12
|
+
|
13
|
+
# The PC/SC error status that caused this error, as a number.
|
14
|
+
attr_reader :pcsc_status_code
|
15
|
+
end
|
@@ -7,144 +7,144 @@ module Smartcard::PCSC
|
|
7
7
|
module FFILib
|
8
8
|
# Constant values extracted from headers.
|
9
9
|
module Consts
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
SCARD_E_INVALID_VALUE = 0x80100011
|
11
|
+
SCARD_E_NO_SERVICE = 0x8010001D
|
12
|
+
SCARD_E_UNSUPPORTED_FEATURE = 0x8010001F
|
13
|
+
SCARD_E_INVALID_ATR = 0x80100015
|
14
|
+
SCARD_E_DUPLICATE_READER = 0x8010001B
|
15
|
+
SCARD_W_UNSUPPORTED_CARD = 0x80100065
|
16
|
+
SCARD_E_UNKNOWN_CARD = 0x8010000D
|
17
|
+
SCARD_E_UNEXPECTED = 0x8010001F
|
16
18
|
SCARD_E_SERVER_TOO_BUSY = 0x80100031
|
17
|
-
|
19
|
+
SCARD_W_UNPOWERED_CARD = 0x80100067
|
20
|
+
SCARD_W_CANCELLED_BY_USER = 0x8010006E
|
21
|
+
SCARD_E_CANCELLED = 0x80100002
|
22
|
+
SCARD_E_INVALID_CHV = 0x8010002A
|
23
|
+
SCARD_E_CERTIFICATE_UNAVAILABLE = 0x8010002D
|
18
24
|
SCARD_W_SECURITY_VIOLATION = 0x8010006A
|
19
25
|
SCARD_E_INVALID_PARAMETER = 0x80100004
|
20
|
-
SCARD_E_NO_MEMORY = 0x80100006
|
21
|
-
SCARD_E_TIMEOUT = 0x8010000A
|
22
|
-
SCARD_W_EOF = 0x8010006D
|
23
|
-
SCARD_E_SHARING_VIOLATION = 0x8010000B
|
24
26
|
SCARD_E_SYSTEM_CANCELLED = 0x80100012
|
25
|
-
SCARD_E_INVALID_ATR = 0x80100015
|
26
|
-
SCARD_E_DIR_NOT_FOUND = 0x80100023
|
27
|
-
SCARD_E_NO_ACCESS = 0x80100027
|
28
|
-
SCARD_E_INVALID_TARGET = 0x80100005
|
29
|
-
SCARD_E_DUPLICATE_READER = 0x8010001B
|
30
|
-
SCARD_E_NO_SERVICE = 0x8010001D
|
31
|
-
SCARD_E_SERVICE_STOPPED = 0x8010001E
|
32
|
-
SCARD_E_UNSUPPORTED_FEATURE = 0x8010001F
|
33
|
-
SCARD_W_CARD_NOT_AUTHENTICATED = 0x8010006F
|
34
|
-
SCARD_S_SUCCESS = 0x00000000
|
35
27
|
SCARD_E_NO_KEY_CONTAINER = 0x80100030
|
36
|
-
|
37
|
-
|
28
|
+
SCARD_E_NOT_READY = 0x80100010
|
29
|
+
SCARD_E_NOT_TRANSACTED = 0x80100016
|
30
|
+
SCARD_E_READER_UNAVAILABLE = 0x80100017
|
38
31
|
SCARD_E_READER_UNSUPPORTED = 0x8010001A
|
39
32
|
SCARD_E_CARD_UNSUPPORTED = 0x8010001C
|
40
|
-
|
41
|
-
|
33
|
+
SCARD_E_INVALID_TARGET = 0x80100005
|
34
|
+
SCARD_E_NO_MEMORY = 0x80100006
|
42
35
|
SCARD_E_UNKNOWN_READER = 0x80100009
|
43
|
-
SCARD_E_PROTO_MISMATCH = 0x8010000F
|
44
|
-
SCARD_E_UNEXPECTED = 0x8010001F
|
45
|
-
SCARD_E_CERTIFICATE_UNAVAILABLE = 0x8010002D
|
46
|
-
SCARD_E_INVALID_HANDLE = 0x80100003
|
47
|
-
SCARD_E_INSUFFICIENT_BUFFER = 0x80100008
|
48
36
|
SCARD_E_NO_SMARTCARD = 0x8010000C
|
49
|
-
SCARD_E_INVALID_VALUE = 0x80100011
|
50
37
|
SCARD_E_ICC_INSTALLATION = 0x80100020
|
38
|
+
SCARD_E_FILE_NOT_FOUND = 0x80100024
|
39
|
+
SCARD_E_NO_SUCH_CERTIFICATE = 0x8010002C
|
40
|
+
SCARD_W_WRONG_CHV = 0x8010006B
|
41
|
+
SCARD_E_NO_ACCESS = 0x80100027
|
42
|
+
SCARD_E_WRITE_TOO_MANY = 0x80100028
|
43
|
+
SCARD_W_EOF = 0x8010006D
|
44
|
+
SCARD_E_INVALID_HANDLE = 0x80100003
|
45
|
+
SCARD_E_CANT_DISPOSE = 0x8010000E
|
46
|
+
SCARD_E_SERVICE_STOPPED = 0x8010001E
|
51
47
|
SCARD_E_ICC_CREATEORDER = 0x80100021
|
52
48
|
SCARD_E_NO_FILE = 0x80100026
|
53
|
-
|
54
|
-
SCARD_E_UNKNOWN_RES_MNG = 0x8010002B
|
49
|
+
SCARD_E_NO_READERS_AVAILABLE = 0x8010002E
|
55
50
|
SCARD_E_COMM_DATA_LOST = 0x8010002F
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
SCARD_E_TIMEOUT = 0x8010000A
|
52
|
+
SCARD_E_SHARING_VIOLATION = 0x8010000B
|
53
|
+
SCARD_E_PROTO_MISMATCH = 0x8010000F
|
59
54
|
SCARD_E_PCI_TOO_SMALL = 0x80100019
|
55
|
+
SCARD_W_RESET_CARD = 0x80100068
|
56
|
+
SCARD_W_REMOVED_CARD = 0x80100069
|
57
|
+
SCARD_S_SUCCESS = 0x00000000
|
58
|
+
SCARD_E_INSUFFICIENT_BUFFER = 0x80100008
|
59
|
+
SCARD_E_DIR_NOT_FOUND = 0x80100023
|
60
60
|
SCARD_E_NO_DIR = 0x80100025
|
61
|
-
|
62
|
-
|
63
|
-
SCARD_E_INVALID_CHV = 0x8010002A
|
64
|
-
SCARD_W_UNSUPPORTED_CARD = 0x80100065
|
61
|
+
SCARD_E_BAD_SEEK = 0x80100029
|
62
|
+
SCARD_E_UNKNOWN_RES_MNG = 0x8010002B
|
65
63
|
SCARD_W_UNRESPONSIVE_CARD = 0x80100066
|
64
|
+
SCARD_W_CHV_BLOCKED = 0x8010006C
|
65
|
+
SCARD_W_CARD_NOT_AUTHENTICATED = 0x8010006F
|
66
66
|
SCARD_SCOPE_USER = 0x00000000
|
67
67
|
SCARD_SCOPE_SYSTEM = 0x00000002
|
68
68
|
SCARD_SCOPE_TERMINAL = 0x00000001
|
69
|
-
|
69
|
+
SCARD_PROTOCOL_UNDEFINED = 0x00000000
|
70
|
+
SCARD_PROTOCOL_UNSET = 0x00000000
|
70
71
|
SCARD_PROTOCOL_T0 = 0x00000001
|
71
72
|
SCARD_PROTOCOL_T1 = 0x00000002
|
73
|
+
SCARD_PROTOCOL_RAW = 0x00000004
|
72
74
|
SCARD_PROTOCOL_ANY = 0x00000003
|
73
75
|
SCARD_PROTOCOL_T15 = 0x00000008
|
74
|
-
SCARD_PROTOCOL_UNDEFINED = 0x00000000
|
75
|
-
SCARD_PROTOCOL_UNSET = 0x00000000
|
76
|
-
SCARD_SHARE_EXCLUSIVE = 0x00000001
|
77
76
|
SCARD_SHARE_SHARED = 0x00000002
|
78
77
|
SCARD_SHARE_DIRECT = 0x00000003
|
79
|
-
|
80
|
-
SCARD_RESET_CARD = 0x00000001
|
78
|
+
SCARD_SHARE_EXCLUSIVE = 0x00000001
|
81
79
|
SCARD_EJECT_CARD = 0x00000003
|
82
80
|
SCARD_UNPOWER_CARD = 0x00000002
|
83
|
-
|
81
|
+
SCARD_LEAVE_CARD = 0x00000000
|
82
|
+
SCARD_RESET_CARD = 0x00000001
|
83
|
+
SCARD_ATTR_SYNC_PROTOCOL_TYPES = 0x00030126
|
84
|
+
SCARD_ATTR_CURRENT_CLK = 0x00080202
|
85
|
+
SCARD_ATTR_CURRENT_EBC_ENCODING = 0x0008020B
|
86
|
+
SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE = 0x00050140
|
87
|
+
SCARD_ATTR_CURRENT_F = 0x00080203
|
88
|
+
SCARD_ATTR_CURRENT_D = 0x00080204
|
89
|
+
SCARD_ATTR_CURRENT_N = 0x00080205
|
84
90
|
SCARD_ATTR_CURRENT_W = 0x00080206
|
85
|
-
|
86
|
-
|
91
|
+
SCARD_ATTR_DEVICE_FRIENDLY_NAME = 0x7FFF0003
|
92
|
+
SCARD_ATTR_VENDOR_IFD_SERIAL_NO = 0x00010103
|
93
|
+
SCARD_ATTR_ESC_RESET = 0x0007A000
|
94
|
+
SCARD_ATTR_CHARACTERISTICS = 0x00060150
|
95
|
+
SCARD_ATTR_CURRENT_IFSC = 0x00080207
|
96
|
+
SCARD_ATTR_CURRENT_IFSD = 0x00080208
|
87
97
|
SCARD_ATTR_MAX_CLK = 0x00030122
|
88
|
-
|
98
|
+
SCARD_ATTR_MAX_DATA_RATE = 0x00030124
|
89
99
|
SCARD_ATTR_CURRENT_PROTOCOL_TYPE = 0x00080201
|
90
|
-
|
91
|
-
SCARD_ATTR_CURRENT_BWT = 0x00080209
|
92
|
-
SCARD_ATTR_EXTENDED_BWT = 0x0008020C
|
93
|
-
SCARD_ATTR_ICC_INTERFACE_STATUS = 0x00090301
|
100
|
+
SCARD_ATTR_ATR_STRING = 0x00090303
|
94
101
|
SCARD_ATTR_ESC_AUTHREQUEST = 0x0007A005
|
95
|
-
|
102
|
+
SCARD_ATTR_DEVICE_SYSTEM_NAME_A = 0x7FFF0004
|
103
|
+
SCARD_ATTR_DEVICE_SYSTEM_NAME_W = 0x7FFF0006
|
104
|
+
SCARD_ATTR_DEFAULT_CLK = 0x00030121
|
96
105
|
SCARD_ATTR_MAX_IFSD = 0x00030125
|
97
|
-
|
98
|
-
|
99
|
-
|
106
|
+
SCARD_ATTR_VENDOR_NAME = 0x00010100
|
107
|
+
SCARD_ATTR_ASYNC_PROTOCOL_TYPES = 0x00030120
|
108
|
+
SCARD_ATTR_DEVICE_UNIT = 0x7FFF0001
|
100
109
|
SCARD_ATTR_DEVICE_FRIENDLY_NAME_A = 0x7FFF0003
|
101
|
-
SCARD_ATTR_SYNC_PROTOCOL_TYPES = 0x00030126
|
102
|
-
SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE = 0x00050140
|
103
|
-
SCARD_ATTR_MAXINPUT = 0x0007A007
|
104
110
|
SCARD_ATTR_DEVICE_FRIENDLY_NAME_W = 0x7FFF0005
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
SCARD_ATTR_CURRENT_F = 0x00080203
|
111
|
+
SCARD_ATTR_SUPRESS_T1_IFS_REQUEST = 0x7FFF0007
|
112
|
+
SCARD_ATTR_CURRENT_BWT = 0x00080209
|
113
|
+
SCARD_ATTR_CURRENT_CWT = 0x0008020A
|
109
114
|
SCARD_ATTR_ICC_PRESENCE = 0x00090300
|
110
|
-
|
111
|
-
SCARD_ATTR_VENDOR_IFD_SERIAL_NO = 0x00010103
|
112
|
-
SCARD_ATTR_CHARACTERISTICS = 0x00060150
|
113
|
-
SCARD_ATTR_CURRENT_EBC_ENCODING = 0x0008020B
|
115
|
+
SCARD_ATTR_ESC_CANCEL = 0x0007A003
|
114
116
|
SCARD_ATTR_DEVICE_IN_USE = 0x7FFF0002
|
117
|
+
SCARD_ATTR_USER_AUTH_INPUT_DEVICE = 0x00050142
|
118
|
+
SCARD_ATTR_CURRENT_IO_STATE = 0x00090302
|
115
119
|
SCARD_ATTR_DEVICE_SYSTEM_NAME = 0x7FFF0004
|
116
|
-
|
120
|
+
SCARD_ATTR_VENDOR_IFD_TYPE = 0x00010101
|
117
121
|
SCARD_ATTR_DEFAULT_DATA_RATE = 0x00030123
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
SCARD_ATTR_DEVICE_SYSTEM_NAME_W = 0x7FFF0006
|
122
|
-
SCARD_ATTR_ASYNC_PROTOCOL_TYPES = 0x00030120
|
123
|
-
SCARD_ATTR_DEFAULT_CLK = 0x00030121
|
122
|
+
SCARD_ATTR_ICC_TYPE_PER_ATR = 0x00090304
|
123
|
+
SCARD_ATTR_VENDOR_IFD_VERSION = 0x00010102
|
124
|
+
SCARD_ATTR_CHANNEL_ID = 0x00020110
|
124
125
|
SCARD_ATTR_POWER_MGMT_SUPPORT = 0x00040131
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
SCARD_ATTR_DEVICE_FRIENDLY_NAME = 0x7FFF0003
|
129
|
-
SCARD_STATE_UNKNOWN = 0x00000004
|
130
|
-
SCARD_STATE_EXCLUSIVE = 0x00000080
|
126
|
+
SCARD_ATTR_EXTENDED_BWT = 0x0008020C
|
127
|
+
SCARD_ATTR_ICC_INTERFACE_STATUS = 0x00090301
|
128
|
+
SCARD_ATTR_MAXINPUT = 0x0007A007
|
131
129
|
SCARD_STATE_CHANGED = 0x00000002
|
132
|
-
SCARD_STATE_EMPTY = 0x00000010
|
133
|
-
SCARD_STATE_UNPOWERED = 0x00000400
|
134
|
-
SCARD_STATE_INUSE = 0x00000100
|
135
|
-
SCARD_STATE_UNAWARE = 0x00000000
|
136
|
-
SCARD_STATE_ATRMATCH = 0x00000040
|
137
130
|
SCARD_STATE_MUTE = 0x00000200
|
138
131
|
SCARD_STATE_IGNORE = 0x00000001
|
139
132
|
SCARD_STATE_UNAVAILABLE = 0x00000008
|
133
|
+
SCARD_STATE_EMPTY = 0x00000010
|
134
|
+
SCARD_STATE_UNKNOWN = 0x00000004
|
135
|
+
SCARD_STATE_ATRMATCH = 0x00000040
|
140
136
|
SCARD_STATE_PRESENT = 0x00000020
|
137
|
+
SCARD_STATE_EXCLUSIVE = 0x00000080
|
138
|
+
SCARD_STATE_INUSE = 0x00000100
|
139
|
+
SCARD_STATE_UNPOWERED = 0x00000400
|
140
|
+
SCARD_STATE_UNAWARE = 0x00000000
|
141
141
|
SCARD_PRESENT = 0x00000004
|
142
|
-
|
142
|
+
SCARD_AUTOALLOCATE = 0xFFFFFFFF
|
143
143
|
SCARD_ABSENT = 0x00000002
|
144
|
-
|
144
|
+
SCARD_SWALLOWED = 0x00000008
|
145
145
|
SCARD_UNKNOWN = 0x00000001
|
146
|
-
SCARD_AUTOALLOCATE = 0xFFFFFFFF
|
147
146
|
SCARD_POWERED = 0x00000010
|
147
|
+
SCARD_SPECIFIC = 0x00000040
|
148
148
|
SCARD_NEGOTIABLE = 0x00000020
|
149
149
|
MAX_ATR_SIZE = 0x00000021
|
150
150
|
INFINITE = 0xFFFFFFFF
|
@@ -152,62 +152,62 @@ module FFILib
|
|
152
152
|
|
153
153
|
# Error codes returned by the PCSC functions.
|
154
154
|
Status = enum [
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
160
|
-
:
|
155
|
+
:invalid_value, Consts::SCARD_E_INVALID_VALUE,
|
156
|
+
:no_service, Consts::SCARD_E_NO_SERVICE,
|
157
|
+
:unsupported_feature, Consts::SCARD_E_UNSUPPORTED_FEATURE,
|
158
|
+
:invalid_atr, Consts::SCARD_E_INVALID_ATR,
|
159
|
+
:duplicate_reader, Consts::SCARD_E_DUPLICATE_READER,
|
160
|
+
:unsupported_card, Consts::SCARD_W_UNSUPPORTED_CARD,
|
161
|
+
:unknown_card, Consts::SCARD_E_UNKNOWN_CARD,
|
162
|
+
:unexpected, Consts::SCARD_E_UNEXPECTED,
|
161
163
|
:server_too_busy, Consts::SCARD_E_SERVER_TOO_BUSY,
|
162
|
-
:
|
164
|
+
:unpowered_card, Consts::SCARD_W_UNPOWERED_CARD,
|
165
|
+
:cancelled_by_user, Consts::SCARD_W_CANCELLED_BY_USER,
|
166
|
+
:cancelled, Consts::SCARD_E_CANCELLED,
|
167
|
+
:invalid_chv, Consts::SCARD_E_INVALID_CHV,
|
168
|
+
:certificate_unavailable, Consts::SCARD_E_CERTIFICATE_UNAVAILABLE,
|
163
169
|
:security_violation, Consts::SCARD_W_SECURITY_VIOLATION,
|
164
170
|
:invalid_parameter, Consts::SCARD_E_INVALID_PARAMETER,
|
165
|
-
:no_memory, Consts::SCARD_E_NO_MEMORY,
|
166
|
-
:timeout, Consts::SCARD_E_TIMEOUT,
|
167
|
-
:eof, Consts::SCARD_W_EOF,
|
168
|
-
:sharing_violation, Consts::SCARD_E_SHARING_VIOLATION,
|
169
171
|
:system_cancelled, Consts::SCARD_E_SYSTEM_CANCELLED,
|
170
|
-
:invalid_atr, Consts::SCARD_E_INVALID_ATR,
|
171
|
-
:dir_not_found, Consts::SCARD_E_DIR_NOT_FOUND,
|
172
|
-
:no_access, Consts::SCARD_E_NO_ACCESS,
|
173
|
-
:invalid_target, Consts::SCARD_E_INVALID_TARGET,
|
174
|
-
:duplicate_reader, Consts::SCARD_E_DUPLICATE_READER,
|
175
|
-
:no_service, Consts::SCARD_E_NO_SERVICE,
|
176
|
-
:service_stopped, Consts::SCARD_E_SERVICE_STOPPED,
|
177
|
-
:unsupported_feature, Consts::SCARD_E_UNSUPPORTED_FEATURE,
|
178
|
-
:card_not_authenticated, Consts::SCARD_W_CARD_NOT_AUTHENTICATED,
|
179
|
-
:success, Consts::SCARD_S_SUCCESS,
|
180
172
|
:no_key_container, Consts::SCARD_E_NO_KEY_CONTAINER,
|
181
|
-
:
|
182
|
-
:
|
173
|
+
:not_ready, Consts::SCARD_E_NOT_READY,
|
174
|
+
:not_transacted, Consts::SCARD_E_NOT_TRANSACTED,
|
175
|
+
:reader_unavailable, Consts::SCARD_E_READER_UNAVAILABLE,
|
183
176
|
:reader_unsupported, Consts::SCARD_E_READER_UNSUPPORTED,
|
184
177
|
:card_unsupported, Consts::SCARD_E_CARD_UNSUPPORTED,
|
185
|
-
:
|
186
|
-
:
|
178
|
+
:invalid_target, Consts::SCARD_E_INVALID_TARGET,
|
179
|
+
:no_memory, Consts::SCARD_E_NO_MEMORY,
|
187
180
|
:unknown_reader, Consts::SCARD_E_UNKNOWN_READER,
|
188
|
-
:proto_mismatch, Consts::SCARD_E_PROTO_MISMATCH,
|
189
|
-
:unexpected, Consts::SCARD_E_UNEXPECTED,
|
190
|
-
:certificate_unavailable, Consts::SCARD_E_CERTIFICATE_UNAVAILABLE,
|
191
|
-
:invalid_handle, Consts::SCARD_E_INVALID_HANDLE,
|
192
|
-
:insufficient_buffer, Consts::SCARD_E_INSUFFICIENT_BUFFER,
|
193
181
|
:no_smartcard, Consts::SCARD_E_NO_SMARTCARD,
|
194
|
-
:invalid_value, Consts::SCARD_E_INVALID_VALUE,
|
195
182
|
:icc_installation, Consts::SCARD_E_ICC_INSTALLATION,
|
183
|
+
:file_not_found, Consts::SCARD_E_FILE_NOT_FOUND,
|
184
|
+
:no_such_certificate, Consts::SCARD_E_NO_SUCH_CERTIFICATE,
|
185
|
+
:wrong_chv, Consts::SCARD_W_WRONG_CHV,
|
186
|
+
:no_access, Consts::SCARD_E_NO_ACCESS,
|
187
|
+
:write_too_many, Consts::SCARD_E_WRITE_TOO_MANY,
|
188
|
+
:eof, Consts::SCARD_W_EOF,
|
189
|
+
:invalid_handle, Consts::SCARD_E_INVALID_HANDLE,
|
190
|
+
:cant_dispose, Consts::SCARD_E_CANT_DISPOSE,
|
191
|
+
:service_stopped, Consts::SCARD_E_SERVICE_STOPPED,
|
196
192
|
:icc_createorder, Consts::SCARD_E_ICC_CREATEORDER,
|
197
193
|
:no_file, Consts::SCARD_E_NO_FILE,
|
198
|
-
:
|
199
|
-
:unknown_res_mng, Consts::SCARD_E_UNKNOWN_RES_MNG,
|
194
|
+
:no_readers_available, Consts::SCARD_E_NO_READERS_AVAILABLE,
|
200
195
|
:comm_data_lost, Consts::SCARD_E_COMM_DATA_LOST,
|
201
|
-
:
|
202
|
-
:
|
203
|
-
:
|
196
|
+
:timeout, Consts::SCARD_E_TIMEOUT,
|
197
|
+
:sharing_violation, Consts::SCARD_E_SHARING_VIOLATION,
|
198
|
+
:proto_mismatch, Consts::SCARD_E_PROTO_MISMATCH,
|
204
199
|
:pci_too_small, Consts::SCARD_E_PCI_TOO_SMALL,
|
200
|
+
:reset_card, Consts::SCARD_W_RESET_CARD,
|
201
|
+
:removed_card, Consts::SCARD_W_REMOVED_CARD,
|
202
|
+
:success, Consts::SCARD_S_SUCCESS,
|
203
|
+
:insufficient_buffer, Consts::SCARD_E_INSUFFICIENT_BUFFER,
|
204
|
+
:dir_not_found, Consts::SCARD_E_DIR_NOT_FOUND,
|
205
205
|
:no_dir, Consts::SCARD_E_NO_DIR,
|
206
|
-
:
|
207
|
-
:
|
208
|
-
:invalid_chv, Consts::SCARD_E_INVALID_CHV,
|
209
|
-
:unsupported_card, Consts::SCARD_W_UNSUPPORTED_CARD,
|
206
|
+
:bad_seek, Consts::SCARD_E_BAD_SEEK,
|
207
|
+
:unknown_res_mng, Consts::SCARD_E_UNKNOWN_RES_MNG,
|
210
208
|
:unresponsive_card, Consts::SCARD_W_UNRESPONSIVE_CARD,
|
209
|
+
:chv_blocked, Consts::SCARD_W_CHV_BLOCKED,
|
210
|
+
:card_not_authenticated, Consts::SCARD_W_CARD_NOT_AUTHENTICATED,
|
211
211
|
]
|
212
212
|
|
213
213
|
# Values for the context's scope.
|
@@ -219,105 +219,105 @@ module FFILib
|
|
219
219
|
|
220
220
|
# Smart-card communication protocols.
|
221
221
|
Protocol = enum [
|
222
|
-
:
|
222
|
+
:undefined, Consts::SCARD_PROTOCOL_UNDEFINED,
|
223
|
+
:unset, Consts::SCARD_PROTOCOL_UNSET,
|
223
224
|
:t0, Consts::SCARD_PROTOCOL_T0,
|
224
225
|
:t1, Consts::SCARD_PROTOCOL_T1,
|
226
|
+
:raw, Consts::SCARD_PROTOCOL_RAW,
|
225
227
|
:any, Consts::SCARD_PROTOCOL_ANY,
|
226
228
|
:t15, Consts::SCARD_PROTOCOL_T15,
|
227
|
-
:undefined, Consts::SCARD_PROTOCOL_UNDEFINED,
|
228
|
-
:unset, Consts::SCARD_PROTOCOL_UNSET,
|
229
229
|
]
|
230
230
|
|
231
231
|
# Smart-card sharing modes.
|
232
232
|
Share = enum [
|
233
|
-
:exclusive, Consts::SCARD_SHARE_EXCLUSIVE,
|
234
233
|
:shared, Consts::SCARD_SHARE_SHARED,
|
235
234
|
:direct, Consts::SCARD_SHARE_DIRECT,
|
235
|
+
:exclusive, Consts::SCARD_SHARE_EXCLUSIVE,
|
236
236
|
]
|
237
237
|
|
238
238
|
# Smart-card dispositions.
|
239
239
|
Disposition = enum [
|
240
|
-
:leave, Consts::SCARD_LEAVE_CARD,
|
241
|
-
:reset, Consts::SCARD_RESET_CARD,
|
242
240
|
:eject, Consts::SCARD_EJECT_CARD,
|
243
241
|
:unpower, Consts::SCARD_UNPOWER_CARD,
|
242
|
+
:leave, Consts::SCARD_LEAVE_CARD,
|
243
|
+
:reset, Consts::SCARD_RESET_CARD,
|
244
244
|
]
|
245
245
|
|
246
246
|
# Smart-card reader attributes.
|
247
247
|
Attribute = enum [
|
248
|
-
:
|
248
|
+
:sync_protocol_types, Consts::SCARD_ATTR_SYNC_PROTOCOL_TYPES,
|
249
|
+
:current_clk, Consts::SCARD_ATTR_CURRENT_CLK,
|
250
|
+
:current_ebc_encoding, Consts::SCARD_ATTR_CURRENT_EBC_ENCODING,
|
251
|
+
:user_to_card_auth_device, Consts::SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE,
|
252
|
+
:current_f, Consts::SCARD_ATTR_CURRENT_F,
|
253
|
+
:current_d, Consts::SCARD_ATTR_CURRENT_D,
|
254
|
+
:current_n, Consts::SCARD_ATTR_CURRENT_N,
|
249
255
|
:current_w, Consts::SCARD_ATTR_CURRENT_W,
|
250
|
-
:
|
251
|
-
:
|
256
|
+
:device_friendly_name, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME,
|
257
|
+
:vendor_ifd_serial_no, Consts::SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
|
258
|
+
:esc_reset, Consts::SCARD_ATTR_ESC_RESET,
|
259
|
+
:characteristics, Consts::SCARD_ATTR_CHARACTERISTICS,
|
260
|
+
:current_ifsc, Consts::SCARD_ATTR_CURRENT_IFSC,
|
261
|
+
:current_ifsd, Consts::SCARD_ATTR_CURRENT_IFSD,
|
252
262
|
:max_clk, Consts::SCARD_ATTR_MAX_CLK,
|
253
|
-
:
|
263
|
+
:max_data_rate, Consts::SCARD_ATTR_MAX_DATA_RATE,
|
254
264
|
:current_protocol_type, Consts::SCARD_ATTR_CURRENT_PROTOCOL_TYPE,
|
255
|
-
:
|
256
|
-
:current_bwt, Consts::SCARD_ATTR_CURRENT_BWT,
|
257
|
-
:extended_bwt, Consts::SCARD_ATTR_EXTENDED_BWT,
|
258
|
-
:icc_interface_status, Consts::SCARD_ATTR_ICC_INTERFACE_STATUS,
|
265
|
+
:atr_string, Consts::SCARD_ATTR_ATR_STRING,
|
259
266
|
:esc_authrequest, Consts::SCARD_ATTR_ESC_AUTHREQUEST,
|
260
|
-
:
|
267
|
+
:device_system_name_a, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME_A,
|
268
|
+
:device_system_name_w, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME_W,
|
269
|
+
:default_clk, Consts::SCARD_ATTR_DEFAULT_CLK,
|
261
270
|
:max_ifsd, Consts::SCARD_ATTR_MAX_IFSD,
|
262
|
-
:
|
263
|
-
:
|
264
|
-
:
|
271
|
+
:vendor_name, Consts::SCARD_ATTR_VENDOR_NAME,
|
272
|
+
:async_protocol_types, Consts::SCARD_ATTR_ASYNC_PROTOCOL_TYPES,
|
273
|
+
:device_unit, Consts::SCARD_ATTR_DEVICE_UNIT,
|
265
274
|
:device_friendly_name_a, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME_A,
|
266
|
-
:sync_protocol_types, Consts::SCARD_ATTR_SYNC_PROTOCOL_TYPES,
|
267
|
-
:user_to_card_auth_device, Consts::SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE,
|
268
|
-
:maxinput, Consts::SCARD_ATTR_MAXINPUT,
|
269
275
|
:device_friendly_name_w, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME_W,
|
270
|
-
:
|
271
|
-
:
|
272
|
-
:
|
273
|
-
:current_f, Consts::SCARD_ATTR_CURRENT_F,
|
276
|
+
:supress_t1_ifs_request, Consts::SCARD_ATTR_SUPRESS_T1_IFS_REQUEST,
|
277
|
+
:current_bwt, Consts::SCARD_ATTR_CURRENT_BWT,
|
278
|
+
:current_cwt, Consts::SCARD_ATTR_CURRENT_CWT,
|
274
279
|
:icc_presence, Consts::SCARD_ATTR_ICC_PRESENCE,
|
275
|
-
:
|
276
|
-
:vendor_ifd_serial_no, Consts::SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
|
277
|
-
:characteristics, Consts::SCARD_ATTR_CHARACTERISTICS,
|
278
|
-
:current_ebc_encoding, Consts::SCARD_ATTR_CURRENT_EBC_ENCODING,
|
280
|
+
:esc_cancel, Consts::SCARD_ATTR_ESC_CANCEL,
|
279
281
|
:device_in_use, Consts::SCARD_ATTR_DEVICE_IN_USE,
|
282
|
+
:user_auth_input_device, Consts::SCARD_ATTR_USER_AUTH_INPUT_DEVICE,
|
283
|
+
:current_io_state, Consts::SCARD_ATTR_CURRENT_IO_STATE,
|
280
284
|
:device_system_name, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME,
|
281
|
-
:
|
285
|
+
:vendor_ifd_type, Consts::SCARD_ATTR_VENDOR_IFD_TYPE,
|
282
286
|
:default_data_rate, Consts::SCARD_ATTR_DEFAULT_DATA_RATE,
|
283
|
-
:
|
284
|
-
:
|
285
|
-
:
|
286
|
-
:device_system_name_w, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME_W,
|
287
|
-
:async_protocol_types, Consts::SCARD_ATTR_ASYNC_PROTOCOL_TYPES,
|
288
|
-
:default_clk, Consts::SCARD_ATTR_DEFAULT_CLK,
|
287
|
+
:icc_type_per_atr, Consts::SCARD_ATTR_ICC_TYPE_PER_ATR,
|
288
|
+
:vendor_ifd_version, Consts::SCARD_ATTR_VENDOR_IFD_VERSION,
|
289
|
+
:channel_id, Consts::SCARD_ATTR_CHANNEL_ID,
|
289
290
|
:power_mgmt_support, Consts::SCARD_ATTR_POWER_MGMT_SUPPORT,
|
290
|
-
:
|
291
|
-
:
|
292
|
-
:
|
293
|
-
:device_friendly_name, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME,
|
291
|
+
:extended_bwt, Consts::SCARD_ATTR_EXTENDED_BWT,
|
292
|
+
:icc_interface_status, Consts::SCARD_ATTR_ICC_INTERFACE_STATUS,
|
293
|
+
:maxinput, Consts::SCARD_ATTR_MAXINPUT,
|
294
294
|
]
|
295
295
|
|
296
296
|
# Smart-card states.
|
297
297
|
CardState = enum [
|
298
|
-
:unknown, Consts::SCARD_STATE_UNKNOWN,
|
299
|
-
:exclusive, Consts::SCARD_STATE_EXCLUSIVE,
|
300
298
|
:changed, Consts::SCARD_STATE_CHANGED,
|
301
|
-
:empty, Consts::SCARD_STATE_EMPTY,
|
302
|
-
:unpowered, Consts::SCARD_STATE_UNPOWERED,
|
303
|
-
:inuse, Consts::SCARD_STATE_INUSE,
|
304
|
-
:unaware, Consts::SCARD_STATE_UNAWARE,
|
305
|
-
:atrmatch, Consts::SCARD_STATE_ATRMATCH,
|
306
299
|
:mute, Consts::SCARD_STATE_MUTE,
|
307
300
|
:ignore, Consts::SCARD_STATE_IGNORE,
|
308
301
|
:unavailable, Consts::SCARD_STATE_UNAVAILABLE,
|
302
|
+
:empty, Consts::SCARD_STATE_EMPTY,
|
303
|
+
:unknown, Consts::SCARD_STATE_UNKNOWN,
|
304
|
+
:atrmatch, Consts::SCARD_STATE_ATRMATCH,
|
309
305
|
:present, Consts::SCARD_STATE_PRESENT,
|
306
|
+
:exclusive, Consts::SCARD_STATE_EXCLUSIVE,
|
307
|
+
:inuse, Consts::SCARD_STATE_INUSE,
|
308
|
+
:unpowered, Consts::SCARD_STATE_UNPOWERED,
|
309
|
+
:unaware, Consts::SCARD_STATE_UNAWARE,
|
310
310
|
]
|
311
311
|
|
312
312
|
# Smart-card reader states.
|
313
313
|
State = enum [
|
314
314
|
:present, Consts::SCARD_PRESENT,
|
315
|
-
:
|
315
|
+
:autoallocate, Consts::SCARD_AUTOALLOCATE,
|
316
316
|
:absent, Consts::SCARD_ABSENT,
|
317
|
-
:
|
317
|
+
:swallowed, Consts::SCARD_SWALLOWED,
|
318
318
|
:unknown, Consts::SCARD_UNKNOWN,
|
319
|
-
:autoallocate, Consts::SCARD_AUTOALLOCATE,
|
320
319
|
:powered, Consts::SCARD_POWERED,
|
320
|
+
:specific, Consts::SCARD_SPECIFIC,
|
321
321
|
:negotiable, Consts::SCARD_NEGOTIABLE,
|
322
322
|
]
|
323
323
|
|
@@ -41,7 +41,7 @@ class ReaderStateQueries
|
|
41
41
|
# This is a convenience method intended to be called after
|
42
42
|
# Smartcard::PCSC::Context#wait_for_status_change.
|
43
43
|
def ack_changes
|
44
|
-
@queries.each { |query| query
|
44
|
+
@queries.each { |query| query[:current_state] = query[:event_state] }
|
45
45
|
end
|
46
46
|
|
47
47
|
# Called by FFI::AutoPointer to release the reader states array.
|
@@ -148,18 +148,32 @@ class FFILib::ReaderStateQuery
|
|
148
148
|
def self.pack_state(unpacked_state)
|
149
149
|
if unpacked_state.kind_of? Enumerable
|
150
150
|
state = 0
|
151
|
-
unpacked_state.each
|
151
|
+
unpacked_state.each do |symbol_bit_or_number|
|
152
|
+
if FFILib::CardState[symbol_bit_or_number]
|
153
|
+
state |= FFILib::CardState[symbol_bit_or_number]
|
154
|
+
else
|
155
|
+
state |= symbol_bit_or_number
|
156
|
+
end
|
157
|
+
end
|
152
158
|
return state
|
153
159
|
end
|
154
160
|
FFILib::CardState[unpacked_state]
|
155
161
|
end
|
156
162
|
|
157
163
|
# Unpacks a numeric card state into a Set of symbols.
|
164
|
+
#
|
165
|
+
# The returned Set may also have an Integer in it, if any of the bits set in
|
166
|
+
# the packed state are not covered by the mapping in FFILib::CardState.
|
158
167
|
def self.unpack_state(packed_state)
|
159
168
|
state = Set.new
|
160
|
-
FFILib::CardState.to_h.each do |
|
161
|
-
|
169
|
+
FFILib::CardState.to_h.each do |symbol, mask|
|
170
|
+
next if mask == 0
|
171
|
+
if (packed_state & mask) == mask
|
172
|
+
state << symbol
|
173
|
+
packed_state ^= mask
|
174
|
+
end
|
162
175
|
end
|
176
|
+
state << packed_state if packed_state != 0
|
163
177
|
state
|
164
178
|
end
|
165
179
|
end
|
data/smartcard.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.5.
|
4
|
+
s.name = "smartcard"
|
5
|
+
s.version = "0.5.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Victor Costan"]
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extra_rdoc_files = ["BUILD", "CHANGELOG", "LICENSE", "README", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/apdu_error.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/card.rb", "lib/smartcard/pcsc/context.rb", "lib/smartcard/pcsc/
|
13
|
-
s.files = ["BUILD", "CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/apdu_error.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/card.rb", "lib/smartcard/pcsc/context.rb", "lib/smartcard/pcsc/
|
14
|
-
s.homepage =
|
9
|
+
s.date = "2012-02-09"
|
10
|
+
s.description = "Interface with ISO 7816 smart cards."
|
11
|
+
s.email = "victor@costan.us"
|
12
|
+
s.extra_rdoc_files = ["BUILD", "CHANGELOG", "LICENSE", "README", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/apdu_error.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/card.rb", "lib/smartcard/pcsc/context.rb", "lib/smartcard/pcsc/exception.rb", "lib/smartcard/pcsc/ffi_autogen.rb", "lib/smartcard/pcsc/ffi_functions.rb", "lib/smartcard/pcsc/ffi_lib.rb", "lib/smartcard/pcsc/ffi_structs.rb", "lib/smartcard/pcsc/reader_state_queries.rb", "tasks/ffi_codegen.rb"]
|
13
|
+
s.files = ["BUILD", "CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/apdu_error.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/card.rb", "lib/smartcard/pcsc/context.rb", "lib/smartcard/pcsc/exception.rb", "lib/smartcard/pcsc/ffi_autogen.rb", "lib/smartcard/pcsc/ffi_functions.rb", "lib/smartcard/pcsc/ffi_lib.rb", "lib/smartcard/pcsc/ffi_structs.rb", "lib/smartcard/pcsc/reader_state_queries.rb", "tasks/ffi_codegen.rb", "test/gp/asn1_ber_test.rb", "test/gp/cap_loader_test.rb", "test/gp/des_test.rb", "test/gp/gp_card_mixin_compat_test.rb", "test/gp/gp_card_mixin_test.rb", "test/gp/hello.apdu", "test/gp/hello.cap", "test/iso/auto_configurator_test.rb", "test/iso/iso_card_mixin_test.rb", "test/iso/iso_exception_test.rb", "test/iso/jcop_remote_test.rb", "test/pcsc/card_test.rb", "test/pcsc/context_test.rb", "test/pcsc/exception_test.rb", "test/pcsc/reader_state_queries_test.rb", "smartcard.gemspec"]
|
14
|
+
s.homepage = "http://www.costan.us/smartcard"
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Smartcard", "--main", "README"]
|
16
16
|
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project =
|
18
|
-
s.rubygems_version =
|
19
|
-
s.summary =
|
20
|
-
s.test_files = ["test/gp/asn1_ber_test.rb", "test/gp/cap_loader_test.rb", "test/gp/des_test.rb", "test/gp/gp_card_mixin_compat_test.rb", "test/gp/gp_card_mixin_test.rb", "test/iso/auto_configurator_test.rb", "test/iso/iso_card_mixin_test.rb", "test/iso/iso_exception_test.rb", "test/iso/jcop_remote_test.rb", "test/pcsc/card_test.rb", "test/pcsc/context_test.rb", "test/pcsc/reader_state_queries_test.rb"]
|
17
|
+
s.rubyforge_project = "smartcard"
|
18
|
+
s.rubygems_version = "1.8.15"
|
19
|
+
s.summary = "Interface with ISO 7816 smart cards."
|
20
|
+
s.test_files = ["test/gp/asn1_ber_test.rb", "test/gp/cap_loader_test.rb", "test/gp/des_test.rb", "test/gp/gp_card_mixin_compat_test.rb", "test/gp/gp_card_mixin_test.rb", "test/iso/auto_configurator_test.rb", "test/iso/iso_card_mixin_test.rb", "test/iso/iso_exception_test.rb", "test/iso/jcop_remote_test.rb", "test/pcsc/card_test.rb", "test/pcsc/context_test.rb", "test/pcsc/exception_test.rb", "test/pcsc/reader_state_queries_test.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 3
|
data/test/pcsc/card_test.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Author:: Victor Costan
|
2
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
3
|
+
# License:: MIT
|
4
|
+
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'smartcard'
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
|
11
|
+
|
12
|
+
class ExceptionTest < Test::Unit::TestCase
|
13
|
+
def test_exception_with_known_status
|
14
|
+
status = 0x8010002E
|
15
|
+
win32_status = status - 2 ** 32
|
16
|
+
|
17
|
+
exception = Smartcard::PCSC::Exception.new win32_status
|
18
|
+
assert_equal status, exception.pcsc_status_code
|
19
|
+
assert_equal :no_readers_available, exception.pcsc_status
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_exception_with_bogus_status
|
23
|
+
status = 0x88888888
|
24
|
+
win32_status = status - 2 ** 32
|
25
|
+
|
26
|
+
exception = Smartcard::PCSC::Exception.new win32_status
|
27
|
+
assert_equal status, exception.pcsc_status_code
|
28
|
+
assert_nil exception.pcsc_status
|
29
|
+
end
|
30
|
+
end
|
@@ -51,6 +51,16 @@ class ReaderStatesTest < Test::Unit::TestCase
|
|
51
51
|
'event_state'
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_high_order_bits_in_states
|
55
|
+
packed_state = 0xFFFFFFFF
|
56
|
+
unpacked_state = Smartcard::PCSC::FFILib::ReaderStateQuery.
|
57
|
+
unpack_state packed_state
|
58
|
+
repacked_state = Smartcard::PCSC::FFILib::ReaderStateQuery.
|
59
|
+
pack_state unpacked_state
|
60
|
+
assert_equal repacked_state, packed_state
|
61
|
+
assert_operator unpacked_state, :include?, :atrmatch
|
62
|
+
end
|
63
|
+
|
54
64
|
def test_reader_names
|
55
65
|
assert_equal 'PC/SC Reader 0', @queries[0].reader_name
|
56
66
|
assert_equal 'CCID Reader 1', @queries[1].reader_name
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartcard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 4
|
10
|
+
version: 0.5.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Victor Costan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-02-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: ffi
|
@@ -122,11 +122,11 @@ extra_rdoc_files:
|
|
122
122
|
- lib/smartcard/iso/transport.rb
|
123
123
|
- lib/smartcard/pcsc/card.rb
|
124
124
|
- lib/smartcard/pcsc/context.rb
|
125
|
+
- lib/smartcard/pcsc/exception.rb
|
125
126
|
- lib/smartcard/pcsc/ffi_autogen.rb
|
126
127
|
- lib/smartcard/pcsc/ffi_functions.rb
|
127
128
|
- lib/smartcard/pcsc/ffi_lib.rb
|
128
129
|
- lib/smartcard/pcsc/ffi_structs.rb
|
129
|
-
- lib/smartcard/pcsc/pcsc_exception.rb
|
130
130
|
- lib/smartcard/pcsc/reader_state_queries.rb
|
131
131
|
- tasks/ffi_codegen.rb
|
132
132
|
files:
|
@@ -151,11 +151,11 @@ files:
|
|
151
151
|
- lib/smartcard/iso/transport.rb
|
152
152
|
- lib/smartcard/pcsc/card.rb
|
153
153
|
- lib/smartcard/pcsc/context.rb
|
154
|
+
- lib/smartcard/pcsc/exception.rb
|
154
155
|
- lib/smartcard/pcsc/ffi_autogen.rb
|
155
156
|
- lib/smartcard/pcsc/ffi_functions.rb
|
156
157
|
- lib/smartcard/pcsc/ffi_lib.rb
|
157
158
|
- lib/smartcard/pcsc/ffi_structs.rb
|
158
|
-
- lib/smartcard/pcsc/pcsc_exception.rb
|
159
159
|
- lib/smartcard/pcsc/reader_state_queries.rb
|
160
160
|
- tasks/ffi_codegen.rb
|
161
161
|
- test/gp/asn1_ber_test.rb
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- test/iso/jcop_remote_test.rb
|
172
172
|
- test/pcsc/card_test.rb
|
173
173
|
- test/pcsc/context_test.rb
|
174
|
+
- test/pcsc/exception_test.rb
|
174
175
|
- test/pcsc/reader_state_queries_test.rb
|
175
176
|
- smartcard.gemspec
|
176
177
|
homepage: http://www.costan.us/smartcard
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
requirements: []
|
209
210
|
|
210
211
|
rubyforge_project: smartcard
|
211
|
-
rubygems_version: 1.
|
212
|
+
rubygems_version: 1.8.15
|
212
213
|
signing_key:
|
213
214
|
specification_version: 3
|
214
215
|
summary: Interface with ISO 7816 smart cards.
|
@@ -224,4 +225,5 @@ test_files:
|
|
224
225
|
- test/iso/jcop_remote_test.rb
|
225
226
|
- test/pcsc/card_test.rb
|
226
227
|
- test/pcsc/context_test.rb
|
228
|
+
- test/pcsc/exception_test.rb
|
227
229
|
- test/pcsc/reader_state_queries_test.rb
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# Contains information about an exception at the PC/SC layer.
|
2
|
-
class Smartcard::PCSC::Exception < RuntimeError
|
3
|
-
def initialize(error_status)
|
4
|
-
@pcsc_status = error_status
|
5
|
-
super '0x%x' % (2**32 + error_status)
|
6
|
-
end
|
7
|
-
|
8
|
-
# The PC/SC error status that caused this error.
|
9
|
-
attr_reader :pcsc_status
|
10
|
-
end
|