Skip to content
Browse files

Fixed non-idempotent unpack_state / pack_state in ReaderStateQuery. N…

…icer error display.
  • Loading branch information...
1 parent 752e0af commit 762a57163d8bad5a337e87794e697b74f0c2905f @pwnall pwnall committed Feb 9, 2012
View
6 .project
@@ -6,12 +6,18 @@
</projects>
<buildSpec>
<buildCommand>
+ <name>com.aptana.ide.core.unifiedBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
<name>org.rubypeople.rdt.core.rubybuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
+ <nature>com.aptana.ruby.core.rubynature</nature>
<nature>org.rubypeople.rdt.core.rubynature</nature>
</natures>
</projectDescription>
View
2 Rakefile
@@ -1,7 +1,7 @@
require 'rubygems'
require 'echoe'
-require 'tasks/ffi_codegen.rb'
+require './tasks/ffi_codegen.rb'
Echoe.new('smartcard') do |p|
p.project = 'smartcard' # rubyforge project
View
2 lib/smartcard.rb
@@ -4,11 +4,11 @@ module Smartcard
require 'smartcard/pcsc/card.rb'
require 'smartcard/pcsc/context.rb'
+require 'smartcard/pcsc/exception.rb'
require 'smartcard/pcsc/ffi_lib.rb'
require 'smartcard/pcsc/ffi_autogen.rb'
require 'smartcard/pcsc/ffi_structs.rb'
require 'smartcard/pcsc/ffi_functions.rb'
-require 'smartcard/pcsc/pcsc_exception.rb'
require 'smartcard/pcsc/reader_state_queries.rb'
require 'smartcard/iso/apdu_error.rb'
View
15 lib/smartcard/pcsc/exception.rb
@@ -0,0 +1,15 @@
+# Contains information about an exception at the PC/SC layer.
+class Smartcard::PCSC::Exception < RuntimeError
+ def initialize(error_status)
+ @pcsc_status_code = 2**32 + error_status
+ @pcsc_status = Smartcard::PCSC::FFILib::Status.find @pcsc_status_code
+
+ super "#{@pcsc_status} (0x#{@pcsc_status_code.to_s(16)})"
+ end
+
+ # Symbol for the PC/SC error status that caused this error.
+ attr_reader :pcsc_status
+
+ # The PC/SC error status that caused this error, as a number.
+ attr_reader :pcsc_status_code
+end
View
360 lib/smartcard/pcsc/ffi_autogen.rb
@@ -7,207 +7,207 @@ module Smartcard::PCSC
module FFILib
# Constant values extracted from headers.
module Consts
- SCARD_E_NOT_TRANSACTED = 0x80100016
- SCARD_E_FILE_NOT_FOUND = 0x80100024
- SCARD_E_WRITE_TOO_MANY = 0x80100028
- SCARD_E_NO_READERS_AVAILABLE = 0x8010002E
- SCARD_E_NOT_READY = 0x80100010
- SCARD_E_READER_UNAVAILABLE = 0x80100017
+ SCARD_E_INVALID_VALUE = 0x80100011
+ SCARD_E_NO_SERVICE = 0x8010001D
+ SCARD_E_UNSUPPORTED_FEATURE = 0x8010001F
+ SCARD_E_INVALID_ATR = 0x80100015
+ SCARD_E_DUPLICATE_READER = 0x8010001B
+ SCARD_W_UNSUPPORTED_CARD = 0x80100065
+ SCARD_E_UNKNOWN_CARD = 0x8010000D
+ SCARD_E_UNEXPECTED = 0x8010001F
SCARD_E_SERVER_TOO_BUSY = 0x80100031
- SCARD_W_REMOVED_CARD = 0x80100069
+ SCARD_W_UNPOWERED_CARD = 0x80100067
+ SCARD_W_CANCELLED_BY_USER = 0x8010006E
+ SCARD_E_CANCELLED = 0x80100002
+ SCARD_E_INVALID_CHV = 0x8010002A
+ SCARD_E_CERTIFICATE_UNAVAILABLE = 0x8010002D
SCARD_W_SECURITY_VIOLATION = 0x8010006A
SCARD_E_INVALID_PARAMETER = 0x80100004
- SCARD_E_NO_MEMORY = 0x80100006
- SCARD_E_TIMEOUT = 0x8010000A
- SCARD_W_EOF = 0x8010006D
- SCARD_E_SHARING_VIOLATION = 0x8010000B
SCARD_E_SYSTEM_CANCELLED = 0x80100012
- SCARD_E_INVALID_ATR = 0x80100015
- SCARD_E_DIR_NOT_FOUND = 0x80100023
- SCARD_E_NO_ACCESS = 0x80100027
- SCARD_E_INVALID_TARGET = 0x80100005
- SCARD_E_DUPLICATE_READER = 0x8010001B
- SCARD_E_NO_SERVICE = 0x8010001D
- SCARD_E_SERVICE_STOPPED = 0x8010001E
- SCARD_E_UNSUPPORTED_FEATURE = 0x8010001F
- SCARD_W_CARD_NOT_AUTHENTICATED = 0x8010006F
- SCARD_S_SUCCESS = 0x00000000
SCARD_E_NO_KEY_CONTAINER = 0x80100030
- SCARD_W_CANCELLED_BY_USER = 0x8010006E
- SCARD_E_CANT_DISPOSE = 0x8010000E
+ SCARD_E_NOT_READY = 0x80100010
+ SCARD_E_NOT_TRANSACTED = 0x80100016
+ SCARD_E_READER_UNAVAILABLE = 0x80100017
SCARD_E_READER_UNSUPPORTED = 0x8010001A
SCARD_E_CARD_UNSUPPORTED = 0x8010001C
- SCARD_W_CHV_BLOCKED = 0x8010006C
- SCARD_E_CANCELLED = 0x80100002
+ SCARD_E_INVALID_TARGET = 0x80100005
+ SCARD_E_NO_MEMORY = 0x80100006
SCARD_E_UNKNOWN_READER = 0x80100009
- SCARD_E_PROTO_MISMATCH = 0x8010000F
- SCARD_E_UNEXPECTED = 0x8010001F
- SCARD_E_CERTIFICATE_UNAVAILABLE = 0x8010002D
- SCARD_E_INVALID_HANDLE = 0x80100003
- SCARD_E_INSUFFICIENT_BUFFER = 0x80100008
SCARD_E_NO_SMARTCARD = 0x8010000C
- SCARD_E_INVALID_VALUE = 0x80100011
SCARD_E_ICC_INSTALLATION = 0x80100020
+ SCARD_E_FILE_NOT_FOUND = 0x80100024
+ SCARD_E_NO_SUCH_CERTIFICATE = 0x8010002C
+ SCARD_W_WRONG_CHV = 0x8010006B
+ SCARD_E_NO_ACCESS = 0x80100027
+ SCARD_E_WRITE_TOO_MANY = 0x80100028
+ SCARD_W_EOF = 0x8010006D
+ SCARD_E_INVALID_HANDLE = 0x80100003
+ SCARD_E_CANT_DISPOSE = 0x8010000E
+ SCARD_E_SERVICE_STOPPED = 0x8010001E
SCARD_E_ICC_CREATEORDER = 0x80100021
SCARD_E_NO_FILE = 0x80100026
- SCARD_E_BAD_SEEK = 0x80100029
- SCARD_E_UNKNOWN_RES_MNG = 0x8010002B
+ SCARD_E_NO_READERS_AVAILABLE = 0x8010002E
SCARD_E_COMM_DATA_LOST = 0x8010002F
- SCARD_W_UNPOWERED_CARD = 0x80100067
- SCARD_W_RESET_CARD = 0x80100068
- SCARD_E_UNKNOWN_CARD = 0x8010000D
+ SCARD_E_TIMEOUT = 0x8010000A
+ SCARD_E_SHARING_VIOLATION = 0x8010000B
+ SCARD_E_PROTO_MISMATCH = 0x8010000F
SCARD_E_PCI_TOO_SMALL = 0x80100019
+ SCARD_W_RESET_CARD = 0x80100068
+ SCARD_W_REMOVED_CARD = 0x80100069
+ SCARD_S_SUCCESS = 0x00000000
+ SCARD_E_INSUFFICIENT_BUFFER = 0x80100008
+ SCARD_E_DIR_NOT_FOUND = 0x80100023
SCARD_E_NO_DIR = 0x80100025
- SCARD_E_NO_SUCH_CERTIFICATE = 0x8010002C
- SCARD_W_WRONG_CHV = 0x8010006B
- SCARD_E_INVALID_CHV = 0x8010002A
- SCARD_W_UNSUPPORTED_CARD = 0x80100065
+ SCARD_E_BAD_SEEK = 0x80100029
+ SCARD_E_UNKNOWN_RES_MNG = 0x8010002B
SCARD_W_UNRESPONSIVE_CARD = 0x80100066
+ SCARD_W_CHV_BLOCKED = 0x8010006C
+ SCARD_W_CARD_NOT_AUTHENTICATED = 0x8010006F
SCARD_SCOPE_USER = 0x00000000
SCARD_SCOPE_SYSTEM = 0x00000002
SCARD_SCOPE_TERMINAL = 0x00000001
- SCARD_PROTOCOL_RAW = 0x00000004
+ SCARD_PROTOCOL_UNDEFINED = 0x00000000
+ SCARD_PROTOCOL_UNSET = 0x00000000
SCARD_PROTOCOL_T0 = 0x00000001
SCARD_PROTOCOL_T1 = 0x00000002
+ SCARD_PROTOCOL_RAW = 0x00000004
SCARD_PROTOCOL_ANY = 0x00000003
SCARD_PROTOCOL_T15 = 0x00000008
- SCARD_PROTOCOL_UNDEFINED = 0x00000000
- SCARD_PROTOCOL_UNSET = 0x00000000
- SCARD_SHARE_EXCLUSIVE = 0x00000001
SCARD_SHARE_SHARED = 0x00000002
SCARD_SHARE_DIRECT = 0x00000003
- SCARD_LEAVE_CARD = 0x00000000
- SCARD_RESET_CARD = 0x00000001
+ SCARD_SHARE_EXCLUSIVE = 0x00000001
SCARD_EJECT_CARD = 0x00000003
SCARD_UNPOWER_CARD = 0x00000002
- SCARD_ATTR_USER_AUTH_INPUT_DEVICE = 0x00050142
+ SCARD_LEAVE_CARD = 0x00000000
+ SCARD_RESET_CARD = 0x00000001
+ SCARD_ATTR_SYNC_PROTOCOL_TYPES = 0x00030126
+ SCARD_ATTR_CURRENT_CLK = 0x00080202
+ SCARD_ATTR_CURRENT_EBC_ENCODING = 0x0008020B
+ SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE = 0x00050140
+ SCARD_ATTR_CURRENT_F = 0x00080203
+ SCARD_ATTR_CURRENT_D = 0x00080204
+ SCARD_ATTR_CURRENT_N = 0x00080205
SCARD_ATTR_CURRENT_W = 0x00080206
- SCARD_ATTR_ICC_TYPE_PER_ATR = 0x00090304
- SCARD_ATTR_ESC_CANCEL = 0x0007A003
+ SCARD_ATTR_DEVICE_FRIENDLY_NAME = 0x7FFF0003
+ SCARD_ATTR_VENDOR_IFD_SERIAL_NO = 0x00010103
+ SCARD_ATTR_ESC_RESET = 0x0007A000
+ SCARD_ATTR_CHARACTERISTICS = 0x00060150
+ SCARD_ATTR_CURRENT_IFSC = 0x00080207
+ SCARD_ATTR_CURRENT_IFSD = 0x00080208
SCARD_ATTR_MAX_CLK = 0x00030122
- SCARD_ATTR_CHANNEL_ID = 0x00020110
+ SCARD_ATTR_MAX_DATA_RATE = 0x00030124
SCARD_ATTR_CURRENT_PROTOCOL_TYPE = 0x00080201
- SCARD_ATTR_CURRENT_N = 0x00080205
- SCARD_ATTR_CURRENT_BWT = 0x00080209
- SCARD_ATTR_EXTENDED_BWT = 0x0008020C
- SCARD_ATTR_ICC_INTERFACE_STATUS = 0x00090301
+ SCARD_ATTR_ATR_STRING = 0x00090303
SCARD_ATTR_ESC_AUTHREQUEST = 0x0007A005
- SCARD_ATTR_SUPRESS_T1_IFS_REQUEST = 0x7FFF0007
+ SCARD_ATTR_DEVICE_SYSTEM_NAME_A = 0x7FFF0004
+ SCARD_ATTR_DEVICE_SYSTEM_NAME_W = 0x7FFF0006
+ SCARD_ATTR_DEFAULT_CLK = 0x00030121
SCARD_ATTR_MAX_IFSD = 0x00030125
- SCARD_ATTR_CURRENT_D = 0x00080204
- SCARD_ATTR_CURRENT_CWT = 0x0008020A
- SCARD_ATTR_CURRENT_IO_STATE = 0x00090302
+ SCARD_ATTR_VENDOR_NAME = 0x00010100
+ SCARD_ATTR_ASYNC_PROTOCOL_TYPES = 0x00030120
+ SCARD_ATTR_DEVICE_UNIT = 0x7FFF0001
SCARD_ATTR_DEVICE_FRIENDLY_NAME_A = 0x7FFF0003
- SCARD_ATTR_SYNC_PROTOCOL_TYPES = 0x00030126
- SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE = 0x00050140
- SCARD_ATTR_MAXINPUT = 0x0007A007
SCARD_ATTR_DEVICE_FRIENDLY_NAME_W = 0x7FFF0005
- SCARD_ATTR_VENDOR_IFD_TYPE = 0x00010101
- SCARD_ATTR_VENDOR_IFD_VERSION = 0x00010102
- SCARD_ATTR_CURRENT_CLK = 0x00080202
- SCARD_ATTR_CURRENT_F = 0x00080203
+ SCARD_ATTR_SUPRESS_T1_IFS_REQUEST = 0x7FFF0007
+ SCARD_ATTR_CURRENT_BWT = 0x00080209
+ SCARD_ATTR_CURRENT_CWT = 0x0008020A
SCARD_ATTR_ICC_PRESENCE = 0x00090300
- SCARD_ATTR_DEVICE_UNIT = 0x7FFF0001
- SCARD_ATTR_VENDOR_IFD_SERIAL_NO = 0x00010103
- SCARD_ATTR_CHARACTERISTICS = 0x00060150
- SCARD_ATTR_CURRENT_EBC_ENCODING = 0x0008020B
+ SCARD_ATTR_ESC_CANCEL = 0x0007A003
SCARD_ATTR_DEVICE_IN_USE = 0x7FFF0002
+ SCARD_ATTR_USER_AUTH_INPUT_DEVICE = 0x00050142
+ SCARD_ATTR_CURRENT_IO_STATE = 0x00090302
SCARD_ATTR_DEVICE_SYSTEM_NAME = 0x7FFF0004
- SCARD_ATTR_VENDOR_NAME = 0x00010100
+ SCARD_ATTR_VENDOR_IFD_TYPE = 0x00010101
SCARD_ATTR_DEFAULT_DATA_RATE = 0x00030123
- SCARD_ATTR_ATR_STRING = 0x00090303
- SCARD_ATTR_MAX_DATA_RATE = 0x00030124
- SCARD_ATTR_DEVICE_SYSTEM_NAME_A = 0x7FFF0004
- SCARD_ATTR_DEVICE_SYSTEM_NAME_W = 0x7FFF0006
- SCARD_ATTR_ASYNC_PROTOCOL_TYPES = 0x00030120
- SCARD_ATTR_DEFAULT_CLK = 0x00030121
+ SCARD_ATTR_ICC_TYPE_PER_ATR = 0x00090304
+ SCARD_ATTR_VENDOR_IFD_VERSION = 0x00010102
+ SCARD_ATTR_CHANNEL_ID = 0x00020110
SCARD_ATTR_POWER_MGMT_SUPPORT = 0x00040131
- SCARD_ATTR_CURRENT_IFSC = 0x00080207
- SCARD_ATTR_CURRENT_IFSD = 0x00080208
- SCARD_ATTR_ESC_RESET = 0x0007A000
- SCARD_ATTR_DEVICE_FRIENDLY_NAME = 0x7FFF0003
- SCARD_STATE_UNKNOWN = 0x00000004
- SCARD_STATE_EXCLUSIVE = 0x00000080
+ SCARD_ATTR_EXTENDED_BWT = 0x0008020C
+ SCARD_ATTR_ICC_INTERFACE_STATUS = 0x00090301
+ SCARD_ATTR_MAXINPUT = 0x0007A007
SCARD_STATE_CHANGED = 0x00000002
- SCARD_STATE_EMPTY = 0x00000010
- SCARD_STATE_UNPOWERED = 0x00000400
- SCARD_STATE_INUSE = 0x00000100
- SCARD_STATE_UNAWARE = 0x00000000
- SCARD_STATE_ATRMATCH = 0x00000040
SCARD_STATE_MUTE = 0x00000200
SCARD_STATE_IGNORE = 0x00000001
SCARD_STATE_UNAVAILABLE = 0x00000008
+ SCARD_STATE_EMPTY = 0x00000010
+ SCARD_STATE_UNKNOWN = 0x00000004
+ SCARD_STATE_ATRMATCH = 0x00000040
SCARD_STATE_PRESENT = 0x00000020
+ SCARD_STATE_EXCLUSIVE = 0x00000080
+ SCARD_STATE_INUSE = 0x00000100
+ SCARD_STATE_UNPOWERED = 0x00000400
+ SCARD_STATE_UNAWARE = 0x00000000
SCARD_PRESENT = 0x00000004
- SCARD_SWALLOWED = 0x00000008
+ SCARD_AUTOALLOCATE = 0xFFFFFFFF
SCARD_ABSENT = 0x00000002
- SCARD_SPECIFIC = 0x00000040
+ SCARD_SWALLOWED = 0x00000008
SCARD_UNKNOWN = 0x00000001
- SCARD_AUTOALLOCATE = 0xFFFFFFFF
SCARD_POWERED = 0x00000010
+ SCARD_SPECIFIC = 0x00000040
SCARD_NEGOTIABLE = 0x00000020
MAX_ATR_SIZE = 0x00000021
INFINITE = 0xFFFFFFFF
end # module Smartcard::PCSC::FFILib::Consts
# Error codes returned by the PCSC functions.
Status = enum [
- :not_transacted, Consts::SCARD_E_NOT_TRANSACTED,
- :file_not_found, Consts::SCARD_E_FILE_NOT_FOUND,
- :write_too_many, Consts::SCARD_E_WRITE_TOO_MANY,
- :no_readers_available, Consts::SCARD_E_NO_READERS_AVAILABLE,
- :not_ready, Consts::SCARD_E_NOT_READY,
- :reader_unavailable, Consts::SCARD_E_READER_UNAVAILABLE,
+ :invalid_value, Consts::SCARD_E_INVALID_VALUE,
+ :no_service, Consts::SCARD_E_NO_SERVICE,
+ :unsupported_feature, Consts::SCARD_E_UNSUPPORTED_FEATURE,
+ :invalid_atr, Consts::SCARD_E_INVALID_ATR,
+ :duplicate_reader, Consts::SCARD_E_DUPLICATE_READER,
+ :unsupported_card, Consts::SCARD_W_UNSUPPORTED_CARD,
+ :unknown_card, Consts::SCARD_E_UNKNOWN_CARD,
+ :unexpected, Consts::SCARD_E_UNEXPECTED,
:server_too_busy, Consts::SCARD_E_SERVER_TOO_BUSY,
- :removed_card, Consts::SCARD_W_REMOVED_CARD,
+ :unpowered_card, Consts::SCARD_W_UNPOWERED_CARD,
+ :cancelled_by_user, Consts::SCARD_W_CANCELLED_BY_USER,
+ :cancelled, Consts::SCARD_E_CANCELLED,
+ :invalid_chv, Consts::SCARD_E_INVALID_CHV,
+ :certificate_unavailable, Consts::SCARD_E_CERTIFICATE_UNAVAILABLE,
:security_violation, Consts::SCARD_W_SECURITY_VIOLATION,
:invalid_parameter, Consts::SCARD_E_INVALID_PARAMETER,
- :no_memory, Consts::SCARD_E_NO_MEMORY,
- :timeout, Consts::SCARD_E_TIMEOUT,
- :eof, Consts::SCARD_W_EOF,
- :sharing_violation, Consts::SCARD_E_SHARING_VIOLATION,
:system_cancelled, Consts::SCARD_E_SYSTEM_CANCELLED,
- :invalid_atr, Consts::SCARD_E_INVALID_ATR,
- :dir_not_found, Consts::SCARD_E_DIR_NOT_FOUND,
- :no_access, Consts::SCARD_E_NO_ACCESS,
- :invalid_target, Consts::SCARD_E_INVALID_TARGET,
- :duplicate_reader, Consts::SCARD_E_DUPLICATE_READER,
- :no_service, Consts::SCARD_E_NO_SERVICE,
- :service_stopped, Consts::SCARD_E_SERVICE_STOPPED,
- :unsupported_feature, Consts::SCARD_E_UNSUPPORTED_FEATURE,
- :card_not_authenticated, Consts::SCARD_W_CARD_NOT_AUTHENTICATED,
- :success, Consts::SCARD_S_SUCCESS,
:no_key_container, Consts::SCARD_E_NO_KEY_CONTAINER,
- :cancelled_by_user, Consts::SCARD_W_CANCELLED_BY_USER,
- :cant_dispose, Consts::SCARD_E_CANT_DISPOSE,
+ :not_ready, Consts::SCARD_E_NOT_READY,
+ :not_transacted, Consts::SCARD_E_NOT_TRANSACTED,
+ :reader_unavailable, Consts::SCARD_E_READER_UNAVAILABLE,
:reader_unsupported, Consts::SCARD_E_READER_UNSUPPORTED,
:card_unsupported, Consts::SCARD_E_CARD_UNSUPPORTED,
- :chv_blocked, Consts::SCARD_W_CHV_BLOCKED,
- :cancelled, Consts::SCARD_E_CANCELLED,
+ :invalid_target, Consts::SCARD_E_INVALID_TARGET,
+ :no_memory, Consts::SCARD_E_NO_MEMORY,
:unknown_reader, Consts::SCARD_E_UNKNOWN_READER,
- :proto_mismatch, Consts::SCARD_E_PROTO_MISMATCH,
- :unexpected, Consts::SCARD_E_UNEXPECTED,
- :certificate_unavailable, Consts::SCARD_E_CERTIFICATE_UNAVAILABLE,
- :invalid_handle, Consts::SCARD_E_INVALID_HANDLE,
- :insufficient_buffer, Consts::SCARD_E_INSUFFICIENT_BUFFER,
:no_smartcard, Consts::SCARD_E_NO_SMARTCARD,
- :invalid_value, Consts::SCARD_E_INVALID_VALUE,
:icc_installation, Consts::SCARD_E_ICC_INSTALLATION,
+ :file_not_found, Consts::SCARD_E_FILE_NOT_FOUND,
+ :no_such_certificate, Consts::SCARD_E_NO_SUCH_CERTIFICATE,
+ :wrong_chv, Consts::SCARD_W_WRONG_CHV,
+ :no_access, Consts::SCARD_E_NO_ACCESS,
+ :write_too_many, Consts::SCARD_E_WRITE_TOO_MANY,
+ :eof, Consts::SCARD_W_EOF,
+ :invalid_handle, Consts::SCARD_E_INVALID_HANDLE,
+ :cant_dispose, Consts::SCARD_E_CANT_DISPOSE,
+ :service_stopped, Consts::SCARD_E_SERVICE_STOPPED,
:icc_createorder, Consts::SCARD_E_ICC_CREATEORDER,
:no_file, Consts::SCARD_E_NO_FILE,
- :bad_seek, Consts::SCARD_E_BAD_SEEK,
- :unknown_res_mng, Consts::SCARD_E_UNKNOWN_RES_MNG,
+ :no_readers_available, Consts::SCARD_E_NO_READERS_AVAILABLE,
:comm_data_lost, Consts::SCARD_E_COMM_DATA_LOST,
- :unpowered_card, Consts::SCARD_W_UNPOWERED_CARD,
- :reset_card, Consts::SCARD_W_RESET_CARD,
- :unknown_card, Consts::SCARD_E_UNKNOWN_CARD,
+ :timeout, Consts::SCARD_E_TIMEOUT,
+ :sharing_violation, Consts::SCARD_E_SHARING_VIOLATION,
+ :proto_mismatch, Consts::SCARD_E_PROTO_MISMATCH,
:pci_too_small, Consts::SCARD_E_PCI_TOO_SMALL,
+ :reset_card, Consts::SCARD_W_RESET_CARD,
+ :removed_card, Consts::SCARD_W_REMOVED_CARD,
+ :success, Consts::SCARD_S_SUCCESS,
+ :insufficient_buffer, Consts::SCARD_E_INSUFFICIENT_BUFFER,
+ :dir_not_found, Consts::SCARD_E_DIR_NOT_FOUND,
:no_dir, Consts::SCARD_E_NO_DIR,
- :no_such_certificate, Consts::SCARD_E_NO_SUCH_CERTIFICATE,
- :wrong_chv, Consts::SCARD_W_WRONG_CHV,
- :invalid_chv, Consts::SCARD_E_INVALID_CHV,
- :unsupported_card, Consts::SCARD_W_UNSUPPORTED_CARD,
+ :bad_seek, Consts::SCARD_E_BAD_SEEK,
+ :unknown_res_mng, Consts::SCARD_E_UNKNOWN_RES_MNG,
:unresponsive_card, Consts::SCARD_W_UNRESPONSIVE_CARD,
+ :chv_blocked, Consts::SCARD_W_CHV_BLOCKED,
+ :card_not_authenticated, Consts::SCARD_W_CARD_NOT_AUTHENTICATED,
]
# Values for the context's scope.
@@ -219,105 +219,105 @@ module Consts
# Smart-card communication protocols.
Protocol = enum [
- :raw, Consts::SCARD_PROTOCOL_RAW,
+ :undefined, Consts::SCARD_PROTOCOL_UNDEFINED,
+ :unset, Consts::SCARD_PROTOCOL_UNSET,
:t0, Consts::SCARD_PROTOCOL_T0,
:t1, Consts::SCARD_PROTOCOL_T1,
+ :raw, Consts::SCARD_PROTOCOL_RAW,
:any, Consts::SCARD_PROTOCOL_ANY,
:t15, Consts::SCARD_PROTOCOL_T15,
- :undefined, Consts::SCARD_PROTOCOL_UNDEFINED,
- :unset, Consts::SCARD_PROTOCOL_UNSET,
]
# Smart-card sharing modes.
Share = enum [
- :exclusive, Consts::SCARD_SHARE_EXCLUSIVE,
:shared, Consts::SCARD_SHARE_SHARED,
:direct, Consts::SCARD_SHARE_DIRECT,
+ :exclusive, Consts::SCARD_SHARE_EXCLUSIVE,
]
# Smart-card dispositions.
Disposition = enum [
- :leave, Consts::SCARD_LEAVE_CARD,
- :reset, Consts::SCARD_RESET_CARD,
:eject, Consts::SCARD_EJECT_CARD,
:unpower, Consts::SCARD_UNPOWER_CARD,
+ :leave, Consts::SCARD_LEAVE_CARD,
+ :reset, Consts::SCARD_RESET_CARD,
]
# Smart-card reader attributes.
Attribute = enum [
- :user_auth_input_device, Consts::SCARD_ATTR_USER_AUTH_INPUT_DEVICE,
+ :sync_protocol_types, Consts::SCARD_ATTR_SYNC_PROTOCOL_TYPES,
+ :current_clk, Consts::SCARD_ATTR_CURRENT_CLK,
+ :current_ebc_encoding, Consts::SCARD_ATTR_CURRENT_EBC_ENCODING,
+ :user_to_card_auth_device, Consts::SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE,
+ :current_f, Consts::SCARD_ATTR_CURRENT_F,
+ :current_d, Consts::SCARD_ATTR_CURRENT_D,
+ :current_n, Consts::SCARD_ATTR_CURRENT_N,
:current_w, Consts::SCARD_ATTR_CURRENT_W,
- :icc_type_per_atr, Consts::SCARD_ATTR_ICC_TYPE_PER_ATR,
- :esc_cancel, Consts::SCARD_ATTR_ESC_CANCEL,
+ :device_friendly_name, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME,
+ :vendor_ifd_serial_no, Consts::SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
+ :esc_reset, Consts::SCARD_ATTR_ESC_RESET,
+ :characteristics, Consts::SCARD_ATTR_CHARACTERISTICS,
+ :current_ifsc, Consts::SCARD_ATTR_CURRENT_IFSC,
+ :current_ifsd, Consts::SCARD_ATTR_CURRENT_IFSD,
:max_clk, Consts::SCARD_ATTR_MAX_CLK,
- :channel_id, Consts::SCARD_ATTR_CHANNEL_ID,
+ :max_data_rate, Consts::SCARD_ATTR_MAX_DATA_RATE,
:current_protocol_type, Consts::SCARD_ATTR_CURRENT_PROTOCOL_TYPE,
- :current_n, Consts::SCARD_ATTR_CURRENT_N,
- :current_bwt, Consts::SCARD_ATTR_CURRENT_BWT,
- :extended_bwt, Consts::SCARD_ATTR_EXTENDED_BWT,
- :icc_interface_status, Consts::SCARD_ATTR_ICC_INTERFACE_STATUS,
+ :atr_string, Consts::SCARD_ATTR_ATR_STRING,
:esc_authrequest, Consts::SCARD_ATTR_ESC_AUTHREQUEST,
- :supress_t1_ifs_request, Consts::SCARD_ATTR_SUPRESS_T1_IFS_REQUEST,
+ :device_system_name_a, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME_A,
+ :device_system_name_w, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME_W,
+ :default_clk, Consts::SCARD_ATTR_DEFAULT_CLK,
:max_ifsd, Consts::SCARD_ATTR_MAX_IFSD,
- :current_d, Consts::SCARD_ATTR_CURRENT_D,
- :current_cwt, Consts::SCARD_ATTR_CURRENT_CWT,
- :current_io_state, Consts::SCARD_ATTR_CURRENT_IO_STATE,
+ :vendor_name, Consts::SCARD_ATTR_VENDOR_NAME,
+ :async_protocol_types, Consts::SCARD_ATTR_ASYNC_PROTOCOL_TYPES,
+ :device_unit, Consts::SCARD_ATTR_DEVICE_UNIT,
:device_friendly_name_a, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME_A,
- :sync_protocol_types, Consts::SCARD_ATTR_SYNC_PROTOCOL_TYPES,
- :user_to_card_auth_device, Consts::SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE,
- :maxinput, Consts::SCARD_ATTR_MAXINPUT,
:device_friendly_name_w, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME_W,
- :vendor_ifd_type, Consts::SCARD_ATTR_VENDOR_IFD_TYPE,
- :vendor_ifd_version, Consts::SCARD_ATTR_VENDOR_IFD_VERSION,
- :current_clk, Consts::SCARD_ATTR_CURRENT_CLK,
- :current_f, Consts::SCARD_ATTR_CURRENT_F,
+ :supress_t1_ifs_request, Consts::SCARD_ATTR_SUPRESS_T1_IFS_REQUEST,
+ :current_bwt, Consts::SCARD_ATTR_CURRENT_BWT,
+ :current_cwt, Consts::SCARD_ATTR_CURRENT_CWT,
:icc_presence, Consts::SCARD_ATTR_ICC_PRESENCE,
- :device_unit, Consts::SCARD_ATTR_DEVICE_UNIT,
- :vendor_ifd_serial_no, Consts::SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
- :characteristics, Consts::SCARD_ATTR_CHARACTERISTICS,
- :current_ebc_encoding, Consts::SCARD_ATTR_CURRENT_EBC_ENCODING,
+ :esc_cancel, Consts::SCARD_ATTR_ESC_CANCEL,
:device_in_use, Consts::SCARD_ATTR_DEVICE_IN_USE,
+ :user_auth_input_device, Consts::SCARD_ATTR_USER_AUTH_INPUT_DEVICE,
+ :current_io_state, Consts::SCARD_ATTR_CURRENT_IO_STATE,
:device_system_name, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME,
- :vendor_name, Consts::SCARD_ATTR_VENDOR_NAME,
+ :vendor_ifd_type, Consts::SCARD_ATTR_VENDOR_IFD_TYPE,
:default_data_rate, Consts::SCARD_ATTR_DEFAULT_DATA_RATE,
- :atr_string, Consts::SCARD_ATTR_ATR_STRING,
- :max_data_rate, Consts::SCARD_ATTR_MAX_DATA_RATE,
- :device_system_name_a, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME_A,
- :device_system_name_w, Consts::SCARD_ATTR_DEVICE_SYSTEM_NAME_W,
- :async_protocol_types, Consts::SCARD_ATTR_ASYNC_PROTOCOL_TYPES,
- :default_clk, Consts::SCARD_ATTR_DEFAULT_CLK,
+ :icc_type_per_atr, Consts::SCARD_ATTR_ICC_TYPE_PER_ATR,
+ :vendor_ifd_version, Consts::SCARD_ATTR_VENDOR_IFD_VERSION,
+ :channel_id, Consts::SCARD_ATTR_CHANNEL_ID,
:power_mgmt_support, Consts::SCARD_ATTR_POWER_MGMT_SUPPORT,
- :current_ifsc, Consts::SCARD_ATTR_CURRENT_IFSC,
- :current_ifsd, Consts::SCARD_ATTR_CURRENT_IFSD,
- :esc_reset, Consts::SCARD_ATTR_ESC_RESET,
- :device_friendly_name, Consts::SCARD_ATTR_DEVICE_FRIENDLY_NAME,
+ :extended_bwt, Consts::SCARD_ATTR_EXTENDED_BWT,
+ :icc_interface_status, Consts::SCARD_ATTR_ICC_INTERFACE_STATUS,
+ :maxinput, Consts::SCARD_ATTR_MAXINPUT,
]
# Smart-card states.
CardState = enum [
- :unknown, Consts::SCARD_STATE_UNKNOWN,
- :exclusive, Consts::SCARD_STATE_EXCLUSIVE,
:changed, Consts::SCARD_STATE_CHANGED,
- :empty, Consts::SCARD_STATE_EMPTY,
- :unpowered, Consts::SCARD_STATE_UNPOWERED,
- :inuse, Consts::SCARD_STATE_INUSE,
- :unaware, Consts::SCARD_STATE_UNAWARE,
- :atrmatch, Consts::SCARD_STATE_ATRMATCH,
:mute, Consts::SCARD_STATE_MUTE,
:ignore, Consts::SCARD_STATE_IGNORE,
:unavailable, Consts::SCARD_STATE_UNAVAILABLE,
+ :empty, Consts::SCARD_STATE_EMPTY,
+ :unknown, Consts::SCARD_STATE_UNKNOWN,
+ :atrmatch, Consts::SCARD_STATE_ATRMATCH,
:present, Consts::SCARD_STATE_PRESENT,
+ :exclusive, Consts::SCARD_STATE_EXCLUSIVE,
+ :inuse, Consts::SCARD_STATE_INUSE,
+ :unpowered, Consts::SCARD_STATE_UNPOWERED,
+ :unaware, Consts::SCARD_STATE_UNAWARE,
]
# Smart-card reader states.
State = enum [
:present, Consts::SCARD_PRESENT,
- :swallowed, Consts::SCARD_SWALLOWED,
+ :autoallocate, Consts::SCARD_AUTOALLOCATE,
:absent, Consts::SCARD_ABSENT,
- :specific, Consts::SCARD_SPECIFIC,
+ :swallowed, Consts::SCARD_SWALLOWED,
:unknown, Consts::SCARD_UNKNOWN,
- :autoallocate, Consts::SCARD_AUTOALLOCATE,
:powered, Consts::SCARD_POWERED,
+ :specific, Consts::SCARD_SPECIFIC,
:negotiable, Consts::SCARD_NEGOTIABLE,
]
View
10 lib/smartcard/pcsc/pcsc_exception.rb
@@ -1,10 +0,0 @@
-# Contains information about an exception at the PC/SC layer.
-class Smartcard::PCSC::Exception < RuntimeError
- def initialize(error_status)
- @pcsc_status = error_status
- super '0x%x' % (2**32 + error_status)
- end
-
- # The PC/SC error status that caused this error.
- attr_reader :pcsc_status
-end
View
22 lib/smartcard/pcsc/reader_state_queries.rb
@@ -41,7 +41,7 @@ def length
# This is a convenience method intended to be called after
# Smartcard::PCSC::Context#wait_for_status_change.
def ack_changes
- @queries.each { |query| query.current_state = query.event_state }
+ @queries.each { |query| query[:current_state] = query[:event_state] }
end
# Called by FFI::AutoPointer to release the reader states array.
@@ -148,18 +148,32 @@ def reader_name=(new_name)
def self.pack_state(unpacked_state)
if unpacked_state.kind_of? Enumerable
state = 0
- unpacked_state.each { |bit| state |= FFILib::CardState[bit] }
+ unpacked_state.each do |symbol_bit_or_number|
+ if FFILib::CardState[symbol_bit_or_number]
+ state |= FFILib::CardState[symbol_bit_or_number]
+ else
+ state |= symbol_bit_or_number
+ end
+ end
return state
end
FFILib::CardState[unpacked_state]
end
# Unpacks a numeric card state into a Set of symbols.
+ #
+ # The returned Set may also have an Integer in it, if any of the bits set in
+ # the packed state are not covered by the mapping in FFILib::CardState.
def self.unpack_state(packed_state)
state = Set.new
- FFILib::CardState.to_h.each do |bit, mask|
- state << bit if (packed_state & mask) == mask and mask != 0
+ FFILib::CardState.to_h.each do |symbol, mask|
+ next if mask == 0
+ if (packed_state & mask) == mask
+ state << symbol
+ packed_state ^= mask
+ end
end
+ state << packed_state if packed_state != 0
state
end
end
View
1 test/pcsc/card_test.rb
@@ -7,7 +7,6 @@
require 'test/unit'
-require 'rubygems'
require 'flexmock/test_unit'
View
30 test/pcsc/exception_test.rb
@@ -0,0 +1,30 @@
+# Author:: Victor Costan
+# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
+# License:: MIT
+
+
+require 'rubygems'
+require 'smartcard'
+
+require 'test/unit'
+
+
+class ExceptionTest < Test::Unit::TestCase
+ def test_exception_with_known_status
+ status = 0x8010002E
+ win32_status = status - 2 ** 32
+
+ exception = Smartcard::PCSC::Exception.new win32_status
+ assert_equal status, exception.pcsc_status_code
+ assert_equal :no_readers_available, exception.pcsc_status
+ end
+
+ def test_exception_with_bogus_status
+ status = 0x88888888
+ win32_status = status - 2 ** 32
+
+ exception = Smartcard::PCSC::Exception.new win32_status
+ assert_equal status, exception.pcsc_status_code
+ assert_nil exception.pcsc_status
+ end
+end
View
10 test/pcsc/reader_state_queries_test.rb
@@ -51,6 +51,16 @@ def test_states
'event_state'
end
+ def test_high_order_bits_in_states
+ packed_state = 0xFFFFFFFF
+ unpacked_state = Smartcard::PCSC::FFILib::ReaderStateQuery.
+ unpack_state packed_state
+ repacked_state = Smartcard::PCSC::FFILib::ReaderStateQuery.
+ pack_state unpacked_state
+ assert_equal repacked_state, packed_state
+ assert_operator unpacked_state, :include?, :atrmatch
+ end
+
def test_reader_names
assert_equal 'PC/SC Reader 0', @queries[0].reader_name
assert_equal 'CCID Reader 1', @queries[1].reader_name

0 comments on commit 762a571

Please sign in to comment.
Something went wrong with that request. Please try again.