smartcard 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,25 +1,29 @@
1
- v0.2.3 Fixed minor bug in error string for PCSC::Card.transmit
1
+ v0.3.1. Fixed documentation for the new PcscException class.
2
2
 
3
- v0.2.2 Fixed APDU exchange bugs on Windows
3
+ v0.3.0. Added PcscException class used to wrap PC/SC exceptions.
4
+
5
+ v0.2.3. Fixed minor bug in error string for PCSC::Card.transmit
6
+
7
+ v0.2.2. Fixed APDU exchange bugs on Windows
4
8
  Restructured PCSC::IoRequest to allow PCI_ consts
5
9
  Added PCI_ consts
6
10
  Changed test suite to reflect proper way to do transmits
7
11
 
8
- v0.2.1 Added OSX Tiger support
12
+ v0.2.1. Added OSX Tiger support
9
13
  Many workarounds for Tiger's buggy/incomplete PC/SC.
10
14
  Small bugfixes for PC/SC status constants.
11
15
 
12
- v0.2.0 Added automatic builds
16
+ v0.2.0. Added automatic builds
13
17
  Rakefile for auto builds using echoe
14
18
  extconf.rb: hack to fix Windows makefiles
15
19
 
16
- v0.1.2 Added Windows compatibility
20
+ v0.1.2. Added Windows compatibility
17
21
  *.c: restructured code so VC2005 likes it
18
22
  (variable declarations before function body)
19
23
  docs: license, readme, and what the gem is
20
24
 
21
- v0.1.1 Added support for Ubuntu 7.10
25
+ v0.1.1. Added support for Ubuntu 7.10
22
26
  ext/smartcard_pcsc/extconf.rb: better header
23
27
  detection
24
28
 
25
- v0.1.0 Initial release for OSX Leopard
29
+ v0.1.0. Initial release for OSX Leopard
data/Manifest CHANGED
@@ -1,20 +1,23 @@
1
- BUILD
2
- CHANGELOG
3
- ext/smartcard_pcsc/extconf.rb
4
- ext/smartcard_pcsc/pcsc.h
5
- ext/smartcard_pcsc/pcsc_card.c
6
- ext/smartcard_pcsc/pcsc_constants.c
7
- ext/smartcard_pcsc/pcsc_context.c
8
- ext/smartcard_pcsc/pcsc_io_request.c
9
- ext/smartcard_pcsc/pcsc_main.c
10
- ext/smartcard_pcsc/pcsc_multi_strings.c
11
- ext/smartcard_pcsc/pcsc_namespace.c
12
- ext/smartcard_pcsc/pcsc_reader_states.c
13
- ext/smartcard_pcsc/pcsc_surrogate_reader.h
14
- ext/smartcard_pcsc/pcsc_surrogate_wintypes.h
15
- lib/smartcard.rb
16
- LICENSE
17
- Manifest
18
- README
19
- test/test_all.rb
20
- tests/ts_pcsc_ext.rb
1
+ BUILD
2
+ CHANGELOG
3
+ ext/smartcard_pcsc/extconf.rb
4
+ ext/smartcard_pcsc/pcsc.h
5
+ ext/smartcard_pcsc/pcsc_card.c
6
+ ext/smartcard_pcsc/pcsc_constants.c
7
+ ext/smartcard_pcsc/pcsc_context.c
8
+ ext/smartcard_pcsc/pcsc_exception.c
9
+ ext/smartcard_pcsc/pcsc_io_request.c
10
+ ext/smartcard_pcsc/pcsc_main.c
11
+ ext/smartcard_pcsc/pcsc_multi_strings.c
12
+ ext/smartcard_pcsc/pcsc_namespace.c
13
+ ext/smartcard_pcsc/pcsc_reader_states.c
14
+ ext/smartcard_pcsc/pcsc_surrogate_reader.h
15
+ ext/smartcard_pcsc/pcsc_surrogate_wintypes.h
16
+ lib/smartcard/pcsc_exception.rb
17
+ lib/smartcard.rb
18
+ LICENSE
19
+ Manifest
20
+ README
21
+ test/test_containers.rb
22
+ test/test_smoke.rb
23
+ tests/ts_pcsc_ext.rb
@@ -12,9 +12,11 @@ if RUBY_PLATFORM =~ /darwin/
12
12
  pcsc_defines.push 'RB_SMARTCARD_OSX_TIGER_HACK'
13
13
  end
14
14
  elsif RUBY_PLATFORM =~ /win/
15
+
15
16
  have_library('winscard')
17
+ pcsc_defines << 'PCSC_SURROGATE_SCARD_IS_VALID_CONTEXT' unless have_library('winscard', 'SCardIsValidContext')
16
18
  else
17
- # pcsc is retarded and uses stuff like '#include <wintypes.h>'
19
+ # pcsclite is retarded and uses stuff like '#include <wintypes.h>'
18
20
  $CFLAGS += ' -I /usr/include/PCSC -I /usr/local/include/PCSC'
19
21
  have_library('pcsclite')
20
22
  end
@@ -37,6 +39,17 @@ end
37
39
  create_makefile('smartcard/pcsc')
38
40
 
39
41
  def win32_hack(mf_name)
42
+ # get the version of MSVC
43
+ Kernel.system `cl 2> msvc_version.txt`
44
+ msvc_logo = File.open('msvc_version.txt') { |f| f.read }
45
+ print msvc_logo
46
+ File.delete 'msvc_version.txt'
47
+ if msvc_logo =~ /Optimizing Compiler Version (\d+)/
48
+ msvc_ver = $1.to_i
49
+ # for MSVC 6.0, no manifest BS is needed -- straight-up compilation is good
50
+ return if msvc_ver == 12
51
+ end
52
+
40
53
  # evil, evil, evil -- hack the makefile to embed the manifest in the extension dll
41
54
  make_contents = File.open(mf_name, 'r') { |f| f.read }
42
55
  make_rules = make_contents.split(/(\n|\r)(\n|\r)+/)
@@ -19,7 +19,7 @@ int _PCSC_ReaderStates_lowlevel_get(VALUE rbReaderStates, SCARD_READERSTATE **re
19
19
  extern VALUE cPcscIoRequest;
20
20
  void Init_PCSC_IoRequest();
21
21
  int _PCSC_IoRequest_lowlevel_get(VALUE rbIoRequest, SCARD_IO_REQUEST **io_request);
22
- VALUE _PCSC_IoRequest_lowlevel_new(SCARD_IO_REQUEST *io_request);
22
+ VALUE _PCSC_IoRequest_lowlevel_new(const SCARD_IO_REQUEST *io_request);
23
23
 
24
24
  /* Class Smartcard::PCSC::Context */
25
25
  extern VALUE cPcscContext;
@@ -31,6 +31,11 @@ extern VALUE cPcscCard;
31
31
  void Init_PCSC_Card();
32
32
  int _PCSC_Card_lowlevel_get(VALUE rbCard, SCARDHANDLE *card_handle);
33
33
 
34
+ /* Class Smartcard::PCSC::Exception */
35
+ extern VALUE ePcscException;
36
+ void Init_PCSC_Exception();
37
+ void _PCSC_Exception_raise(DWORD pcsc_error, char *pcsc_function);
38
+
34
39
  /* Constants in Smartcard::PCSC */
35
40
  void Init_PCSC_Consts();
36
41
 
@@ -65,7 +65,7 @@ static VALUE PCSC_Card_initialize(VALUE self, VALUE rbContext, VALUE rbReaderNam
65
65
 
66
66
  card->pcsc_error = SCardConnect(context, RSTRING(rbFinalReaderName)->ptr, share_mode, preferred_protocols, &card->card_handle, &active_protocol);
67
67
  if(card->pcsc_error != SCARD_S_SUCCESS)
68
- rb_raise(rb_eRuntimeError, "SCardConnect: %s", pcsc_stringify_error(card->pcsc_error));
68
+ _PCSC_Exception_raise(card->pcsc_error, "SCardConnect");
69
69
  else
70
70
  card->released = 0;
71
71
  return self;
@@ -95,7 +95,7 @@ static VALUE PCSC_Card_reconnect(VALUE self, VALUE rbShareMode, VALUE rbPreferre
95
95
 
96
96
  card->pcsc_error = SCardReconnect(card->card_handle, share_mode, preferred_protocols, initialization, &active_protocol);
97
97
  if(card->pcsc_error != SCARD_S_SUCCESS)
98
- rb_raise(rb_eRuntimeError, "SCardReconnect: %s", pcsc_stringify_error(card->pcsc_error));
98
+ _PCSC_Exception_raise(card->pcsc_error, "SCardReconnect");
99
99
 
100
100
  return self;
101
101
  }
@@ -121,7 +121,7 @@ static VALUE PCSC_Card_disconnect(VALUE self, VALUE rbDisposition) {
121
121
  card->pcsc_error = SCardDisconnect(card->card_handle, disposition);
122
122
  card->released = 1;
123
123
  if(card->pcsc_error != SCARD_S_SUCCESS)
124
- rb_raise(rb_eRuntimeError, "SCardDisconnect: %s", pcsc_stringify_error(card->pcsc_error));
124
+ _PCSC_Exception_raise(card->pcsc_error, "SCardDisconnect");
125
125
  }
126
126
  return self;
127
127
  }
@@ -141,7 +141,7 @@ static VALUE PCSC_Card_begin_transaction(VALUE self) {
141
141
 
142
142
  card->pcsc_error = SCardBeginTransaction(card->card_handle);
143
143
  if(card->pcsc_error != SCARD_S_SUCCESS)
144
- rb_raise(rb_eRuntimeError, "SCardBeginTransaction: %s", pcsc_stringify_error(card->pcsc_error));
144
+ _PCSC_Exception_raise(card->pcsc_error, "SCardBeginTransaction");
145
145
  return self;
146
146
  }
147
147
 
@@ -164,7 +164,7 @@ static VALUE PCSC_Card_end_transaction(VALUE self, VALUE rbDisposition) {
164
164
  disposition = NUM2UINT(rbDisposition);
165
165
  card->pcsc_error = SCardEndTransaction(card->card_handle, disposition);
166
166
  if(card->pcsc_error != SCARD_S_SUCCESS)
167
- rb_raise(rb_eRuntimeError, "SCardEndTransaction: %s", pcsc_stringify_error(card->pcsc_error));
167
+ _PCSC_Exception_raise(card->pcsc_error, "SCardEndTransaction");
168
168
  return self;
169
169
  }
170
170
 
@@ -209,7 +209,7 @@ static VALUE PCSC_Card_get_attribute(VALUE self, VALUE rbAttributeId) {
209
209
  }
210
210
  }
211
211
  if(card->pcsc_error != SCARD_S_SUCCESS)
212
- rb_raise(rb_eRuntimeError, "SCardGetAttrib: %s", pcsc_stringify_error(card->pcsc_error));
212
+ _PCSC_Exception_raise(card->pcsc_error, "SCardGetAttrib");
213
213
  #endif
214
214
  return Qnil;
215
215
  }
@@ -248,7 +248,7 @@ static VALUE PCSC_Card_set_attribute(VALUE self, VALUE rbAttributeId, VALUE rbAt
248
248
  #else
249
249
  card->pcsc_error = SCardSetAttrib(card->card_handle, attribute_id, (LPSTR)RSTRING(rbFinalAttributeValue)->ptr, RSTRING(rbFinalAttributeValue)->len);
250
250
  if(card->pcsc_error != SCARD_S_SUCCESS)
251
- rb_raise(rb_eRuntimeError, "SCardSetAttrib: %s", pcsc_stringify_error(card->pcsc_error));
251
+ _PCSC_Exception_raise(card->pcsc_error, "SCardSetAttrib");
252
252
  #endif
253
253
  return self;
254
254
  }
@@ -306,7 +306,7 @@ static VALUE PCSC_Card_transmit(VALUE self, VALUE rbSendData, VALUE rbSendIoRequ
306
306
  recv_io_request, (LPSTR)recv_buffer, &recv_length);
307
307
  if(card->pcsc_error != SCARD_S_SUCCESS) {
308
308
  xfree(recv_buffer);
309
- rb_raise(rb_eRuntimeError, "SCardTransmit: %s", pcsc_stringify_error(card->pcsc_error));
309
+ _PCSC_Exception_raise(card->pcsc_error, "SCardTransmit");
310
310
  return Qnil;
311
311
  }
312
312
 
@@ -366,7 +366,7 @@ static VALUE PCSC_Card_control(VALUE self, VALUE rbControlCode, VALUE rbSendData
366
366
  #endif
367
367
  if(card->pcsc_error != SCARD_S_SUCCESS) {
368
368
  xfree(recv_buffer);
369
- rb_raise(rb_eRuntimeError, "SCardControl: %s", pcsc_stringify_error(card->pcsc_error));
369
+ _PCSC_Exception_raise(card->pcsc_error, "SCardControl");
370
370
  return Qnil;
371
371
  }
372
372
 
@@ -412,7 +412,7 @@ static VALUE PCSC_Card_status(VALUE self) {
412
412
  card->pcsc_error = SCardStatus(card->card_handle, reader_names_buffer, &reader_names_length, &state, &protocol, (LPSTR)atr_buffer, &atr_length);
413
413
  if(card->pcsc_error != SCARD_S_SUCCESS) {
414
414
  xfree(reader_names_buffer); xfree(atr_buffer);
415
- rb_raise(rb_eRuntimeError, "SCardStatus: %s", pcsc_stringify_error(card->pcsc_error));
415
+ _PCSC_Exception_raise(card->pcsc_error, "SCardStatus");
416
416
  return Qnil;
417
417
  }
418
418
 
@@ -45,7 +45,7 @@ static VALUE PCSC_Context_initialize(VALUE self, VALUE scope) {
45
45
 
46
46
  context->pcsc_error = SCardEstablishContext(NUM2INT(scope), NULL, NULL, &context->pcsc_context);
47
47
  if(context->pcsc_error != SCARD_S_SUCCESS)
48
- rb_raise(rb_eRuntimeError, "SCardEstablishContext: %s", pcsc_stringify_error(context->pcsc_error));
48
+ _PCSC_Exception_raise(context->pcsc_error, "SCardEstablishContext");
49
49
  else
50
50
  context->released = 0;
51
51
  return self;
@@ -69,7 +69,7 @@ static VALUE PCSC_Context_release(VALUE self) {
69
69
  context->pcsc_error = SCardReleaseContext(context->pcsc_context);
70
70
  context->released = 1;
71
71
  if(context->pcsc_error != SCARD_S_SUCCESS)
72
- rb_raise(rb_eRuntimeError, "SCardReleaseContext: %s", pcsc_stringify_error(context->pcsc_error));
72
+ _PCSC_Exception_raise(context->pcsc_error, "SCardReleaseContext");
73
73
  }
74
74
  return self;
75
75
  }
@@ -89,7 +89,7 @@ static VALUE PCSC_Context_is_valid(VALUE self) {
89
89
  Data_Get_Struct(self, struct SCardContextEx, context);
90
90
  if(context == NULL) return self;
91
91
 
92
- #if defined(RB_SMARTCARD_OSX_TIGER_HACK)
92
+ #if defined(RB_SMARTCARD_OSX_TIGER_HACK) || defined(PCSC_SURROGATE_SCARD_IS_VALID_CONTEXT)
93
93
  return Qtrue;
94
94
  #else
95
95
  context->pcsc_error = SCardIsValidContext(context->pcsc_context);
@@ -130,7 +130,7 @@ static VALUE PCSC_Context_list_reader_groups(VALUE self) {
130
130
  }
131
131
  }
132
132
  if(context->pcsc_error != SCARD_S_SUCCESS)
133
- rb_raise(rb_eRuntimeError, "SCardListReaderGroups: %s", pcsc_stringify_error(context->pcsc_error));
133
+ _PCSC_Exception_raise(context->pcsc_error, "SCardListReaderGroups");
134
134
  return Qnil;
135
135
  }
136
136
 
@@ -176,8 +176,8 @@ static VALUE PCSC_Context_list_readers(VALUE self, VALUE rbGroups) {
176
176
  }
177
177
  if(groups != NULL) xfree(groups);
178
178
  if(context->pcsc_error != SCARD_S_SUCCESS)
179
- rb_raise(rb_eRuntimeError, "SCardListReaders: %s", pcsc_stringify_error(context->pcsc_error));
180
- return Qnil;
179
+ _PCSC_Exception_raise(context->pcsc_error, "SCardListReaders");
180
+ return Qnil;
181
181
  }
182
182
 
183
183
  /* :Document-method: cancel
@@ -195,7 +195,7 @@ static VALUE PCSC_Context_cancel(VALUE self) {
195
195
 
196
196
  context->pcsc_error = SCardCancel(context->pcsc_context);
197
197
  if(context->pcsc_error != SCARD_S_SUCCESS)
198
- rb_raise(rb_eRuntimeError, "SCardCancel: %s", pcsc_stringify_error(context->pcsc_error));
198
+ _PCSC_Exception_raise(context->pcsc_error, "SCardCancel");
199
199
  return self;
200
200
  }
201
201
 
@@ -232,7 +232,7 @@ static VALUE PCSC_Context_get_status_change(VALUE self, VALUE rbReaderStates, VA
232
232
  else {
233
233
  context->pcsc_error = SCardGetStatusChange(context->pcsc_context, timeout, reader_states, reader_states_count);
234
234
  if(context->pcsc_error != SCARD_S_SUCCESS)
235
- rb_raise(rb_eRuntimeError, "SCardCancel: %s", pcsc_stringify_error(context->pcsc_error));
235
+ _PCSC_Exception_raise(context->pcsc_error, "SCardGetStatusChange");
236
236
  }
237
237
  return self;
238
238
  }
@@ -0,0 +1,39 @@
1
+ #include "pcsc.h"
2
+
3
+ VALUE ePcscException;
4
+
5
+ #if defined(WIN32)
6
+ static char scard_error_buffer[128];
7
+
8
+ /* Produces a string for an error code yielded by the SCard* PC/SC functions. Returns a static global buffer. */
9
+ static char *pcsc_stringify_error(DWORD scard_error) {
10
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
11
+ NULL, scard_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
12
+ scard_error_buffer, sizeof(scard_error_buffer), NULL );
13
+ return scard_error_buffer;
14
+ }
15
+ #endif
16
+
17
+
18
+ #ifdef MAKE_RDOC_HAPPY
19
+ mSmartcard = rb_define_module("Smartcard");
20
+ mPcsc = rb_define_module_under(mSmartcard, "PCSC");
21
+ #endif
22
+
23
+ /* :Document-class: Smartcard::PCSC::Exception
24
+ * Contains information about an exception at the PC/SC layer.
25
+ */
26
+ void Init_PCSC_Exception() {
27
+ ePcscException = rb_define_class_under(mPcsc, "PcscException", rb_eRuntimeError);
28
+ }
29
+
30
+ /* Raises a PC/SC error. */
31
+ void _PCSC_Exception_raise(DWORD pcsc_error, char *pcsc_function) {
32
+ char buf[BUFSIZ];
33
+ VALUE exception;
34
+
35
+ sprintf(buf, "%s: %s", pcsc_function, pcsc_stringify_error(pcsc_error));
36
+ exception = rb_exc_new2(ePcscException, buf);
37
+ rb_iv_set(exception, "@errno", INT2NUM(pcsc_error));
38
+ rb_exc_raise(exception);
39
+ }
@@ -119,7 +119,7 @@ int _PCSC_IoRequest_lowlevel_get(VALUE rbIoRequest, SCARD_IO_REQUEST **io_reques
119
119
  }
120
120
 
121
121
  /* Creates a Smartcard::PCSC::IoRequest instance wrapping a given SCARD_IO_REQUEST. */
122
- VALUE _PCSC_IoRequest_lowlevel_new(SCARD_IO_REQUEST *io_request) {
122
+ VALUE _PCSC_IoRequest_lowlevel_new(const SCARD_IO_REQUEST *io_request) {
123
123
  struct SCardIoRequestEx *request;
124
124
 
125
125
  VALUE rbIoRequest = Data_Make_Struct(cPcscIoRequest, struct SCardIoRequestEx, NULL, PCSC_IoRequest_free, request);
@@ -7,4 +7,5 @@ void Init_pcsc() {
7
7
  Init_PCSC_Context();
8
8
  Init_PCSC_Card();
9
9
  Init_PCSC_Consts();
10
+ Init_PCSC_Exception();
10
11
  }
@@ -68,15 +68,3 @@ int PCSC_Internal_ruby_strings_to_multistring(VALUE rbStrings, char **strings) {
68
68
 
69
69
  return 0;
70
70
  }
71
-
72
- #if defined(WIN32)
73
- char scard_error_buffer[128];
74
-
75
- /* Produces a string for an error code yielded by the SCard* PC/SC functions. Returns a static global buffer. */
76
- char *pcsc_stringify_error(DWORD scard_error) {
77
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
78
- NULL, scard_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
79
- scard_error_buffer, sizeof(scard_error_buffer), NULL );
80
- return scard_error_buffer;
81
- }
82
- #endif
@@ -0,0 +1,5 @@
1
+ # Contains information about an exception at the PC/SC layer.
2
+ class Smartcard::PCSC::Exception
3
+ # The error number returned by the failed PC/SC function call. Should be one of the Smartcard::PCSC::SCARD_E_ constants.
4
+ attr_reader :errno
5
+ end
@@ -1,27 +1,29 @@
1
1
 
2
- # Gem::Specification for Smartcard-0.2.3
2
+ # Gem::Specification for Smartcard-0.3.1
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{smartcard}
7
- s.version = "0.2.3"
7
+ s.version = "0.3.1"
8
8
 
9
9
  s.specification_version = 2 if s.respond_to? :specification_version=
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Victor Costan"]
13
- s.date = %q{2008-01-10}
13
+ s.date = %q{2008-05-01}
14
14
  s.description = %q{Interface with ISO 7816 smart cards.}
15
15
  s.email = %q{victor@costan.us}
16
16
  s.extensions = ["ext/smartcard_pcsc/extconf.rb"]
17
- s.files = ["BUILD", "CHANGELOG", "ext/smartcard_pcsc/extconf.rb", "ext/smartcard_pcsc/pcsc.h", "ext/smartcard_pcsc/pcsc_card.c", "ext/smartcard_pcsc/pcsc_constants.c", "ext/smartcard_pcsc/pcsc_context.c", "ext/smartcard_pcsc/pcsc_io_request.c", "ext/smartcard_pcsc/pcsc_main.c", "ext/smartcard_pcsc/pcsc_multi_strings.c", "ext/smartcard_pcsc/pcsc_namespace.c", "ext/smartcard_pcsc/pcsc_reader_states.c", "ext/smartcard_pcsc/pcsc_surrogate_reader.h", "ext/smartcard_pcsc/pcsc_surrogate_wintypes.h", "lib/smartcard.rb", "LICENSE", "Manifest", "README", "test/test_all.rb", "tests/ts_pcsc_ext.rb", "smartcard.gemspec"]
17
+ s.extra_rdoc_files = ["BUILD", "CHANGELOG", "ext/smartcard_pcsc/extconf.rb", "ext/smartcard_pcsc/pcsc.h", "ext/smartcard_pcsc/pcsc_card.c", "ext/smartcard_pcsc/pcsc_constants.c", "ext/smartcard_pcsc/pcsc_context.c", "ext/smartcard_pcsc/pcsc_exception.c", "ext/smartcard_pcsc/pcsc_io_request.c", "ext/smartcard_pcsc/pcsc_main.c", "ext/smartcard_pcsc/pcsc_multi_strings.c", "ext/smartcard_pcsc/pcsc_namespace.c", "ext/smartcard_pcsc/pcsc_reader_states.c", "ext/smartcard_pcsc/pcsc_surrogate_reader.h", "ext/smartcard_pcsc/pcsc_surrogate_wintypes.h", "lib/smartcard/pcsc_exception.rb", "lib/smartcard.rb", "LICENSE", "README"]
18
+ s.files = ["BUILD", "CHANGELOG", "ext/smartcard_pcsc/extconf.rb", "ext/smartcard_pcsc/pcsc.h", "ext/smartcard_pcsc/pcsc_card.c", "ext/smartcard_pcsc/pcsc_constants.c", "ext/smartcard_pcsc/pcsc_context.c", "ext/smartcard_pcsc/pcsc_exception.c", "ext/smartcard_pcsc/pcsc_io_request.c", "ext/smartcard_pcsc/pcsc_main.c", "ext/smartcard_pcsc/pcsc_multi_strings.c", "ext/smartcard_pcsc/pcsc_namespace.c", "ext/smartcard_pcsc/pcsc_reader_states.c", "ext/smartcard_pcsc/pcsc_surrogate_reader.h", "ext/smartcard_pcsc/pcsc_surrogate_wintypes.h", "lib/smartcard/pcsc_exception.rb", "lib/smartcard.rb", "LICENSE", "Manifest", "README", "test/test_containers.rb", "test/test_smoke.rb", "tests/ts_pcsc_ext.rb", "smartcard.gemspec"]
18
19
  s.has_rdoc = true
19
20
  s.homepage = %q{http://www.costan.us/smartcard}
21
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Smartcard", "--main", "README"]
20
22
  s.require_paths = ["lib", "ext"]
21
23
  s.rubyforge_project = %q{smartcard}
22
- s.rubygems_version = %q{1.0.1}
24
+ s.rubygems_version = %q{1.1.1}
23
25
  s.summary = %q{Interface with ISO 7816 smart cards.}
24
- s.test_files = ["test/test_all.rb"]
26
+ s.test_files = ["test/test_containers.rb", "test/test_smoke.rb"]
25
27
  end
26
28
 
27
29
 
@@ -44,10 +46,9 @@ end
44
46
  # p.rdoc_pattern = /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
45
47
  #
46
48
  # p.eval = proc do |p|
47
- # case RUBY_PLATFORM
48
- # when /mswin/
49
+ # if Platform.windows?
49
50
  # p.files += ['lib/smartcard/pcsc.so']
50
- # p.platform = Gem::Platform::WIN32
51
+ # p.platform = Gem::Platform::CURRENT
51
52
  #
52
53
  # # take out the extension info from the gemspec
53
54
  # task :postcompile_hacks => [:compile] do
@@ -0,0 +1,53 @@
1
+ require 'test/unit'
2
+ require 'smartcard'
3
+
4
+ class ContainersTest < Test::Unit::TestCase
5
+ def setup
6
+
7
+ end
8
+
9
+ def teardown
10
+
11
+ end
12
+
13
+ # tests the SmartCard::PCSC::ReaderStates container
14
+ def test_reader_states
15
+ reader_states = Smartcard::PCSC::ReaderStates.new(2)
16
+ reader_states.set_current_state_of!(1, Smartcard::PCSC::STATE_ATRMATCH)
17
+ reader_states.set_current_state_of!(0, Smartcard::PCSC::STATE_CHANGED)
18
+ reader_states.set_event_state_of!(0, Smartcard::PCSC::STATE_IGNORE)
19
+ reader_states.set_event_state_of!(1, Smartcard::PCSC::STATE_PRESENT)
20
+ reader_states.set_atr_of!(1, "Ruby\0rocks!")
21
+ reader_states.set_atr_of!(0, "grreat success")
22
+ reader_states.set_reader_name_of!(0, "PC/SC Reader 0")
23
+ reader_states.set_reader_name_of!(1, "CCID Reader 1")
24
+
25
+ assert_equal Smartcard::PCSC::STATE_ATRMATCH, reader_states.current_state_of(1), 'ReaderStates.set_current_state_of! / current_state_of mismatch'
26
+ assert_equal Smartcard::PCSC::STATE_CHANGED, reader_states.current_state_of(0), 'ReaderStates.set_current_state_of! / current_state_of mismatch'
27
+
28
+ assert_equal Smartcard::PCSC::STATE_IGNORE, reader_states.event_state_of(0), 'ReaderStates.set_event_state_of! / event_state_of mismatch'
29
+ assert_equal Smartcard::PCSC::STATE_PRESENT, reader_states.event_state_of(1), 'ReaderStates.set_event_state_of! / event_state_of mismatch'
30
+
31
+ assert_equal "Ruby\0rocks!", reader_states.atr_of(1), 'ReaderStates.set_atr_of! / atr_of mismatch'
32
+ assert_equal "grreat success", reader_states.atr_of(0), 'ReaderStates.set_atr_of! / atr_of mismatch'
33
+
34
+ assert_equal "PC/SC Reader 0", reader_states.reader_name_of(0)
35
+ assert_equal "CCID Reader 1", reader_states.reader_name_of(1)
36
+
37
+ [[5, IndexError], [2, IndexError], [nil, TypeError]].each do |bad_index_test|
38
+ assert_raise bad_index_test[1] do
39
+ reader_states.current_state_of(bad_index_test[0])
40
+ end
41
+ end
42
+ end
43
+
44
+ # tests the SmartCard::PCSC::IoRequest container
45
+ def test_io_request
46
+ io_request = Smartcard::PCSC::IoRequest.new
47
+ [Smartcard::PCSC::PROTOCOL_T0, Smartcard::PCSC::PROTOCOL_T1, Smartcard::PCSC::PROTOCOL_RAW].each do |t_protocol|
48
+ io_request.protocol = t_protocol
49
+ r_protocol = io_request.protocol
50
+ assert_equal r_protocol, t_protocol, 'IoRequest.protocol= / protocol mismatch'
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'smartcard'
3
+
4
+ class SmokeTest < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # smoke-test to ensure that the extension loads and can call into the PC/SC library
12
+ def test_smoke
13
+ context = Smartcard::PCSC::Context.new(Smartcard::PCSC::SCOPE_SYSTEM)
14
+
15
+ reader_groups = context.list_reader_groups
16
+ readers1 = context.list_readers reader_groups
17
+ readers2 = context.list_readers reader_groups.first
18
+ readers3 = context.list_readers nil
19
+
20
+ context.release
21
+ end
22
+ end
@@ -1,77 +1,7 @@
1
- require 'rubygems'
2
- gem 'smartcard', '>= 0.2.1'
3
1
  require 'smartcard'
4
2
  require 'pp'
5
3
 
6
- def test_reader_states
7
- reader_states = Smartcard::PCSC::ReaderStates.new(2)
8
- reader_states.set_current_state_of!(1, Smartcard::PCSC::STATE_ATRMATCH)
9
- reader_states.set_current_state_of!(0, Smartcard::PCSC::STATE_CHANGED)
10
- reader_states.set_event_state_of!(0, Smartcard::PCSC::STATE_IGNORE)
11
- reader_states.set_event_state_of!(1, Smartcard::PCSC::STATE_PRESENT)
12
- reader_states.set_atr_of!(1, "Ruby\0rocks!")
13
- reader_states.set_atr_of!(0, "grreat success")
14
- reader_states.set_reader_name_of!(0, "PC/SC Reader 0")
15
- reader_states.set_reader_name_of!(1, "CCID Reader 1")
16
-
17
- test_state1, test_state0 = reader_states.current_state_of(1), reader_states.current_state_of(0)
18
- if (test_state1 != Smartcard::PCSC::STATE_ATRMATCH) or (test_state0 != Smartcard::PCSC::STATE_CHANGED)
19
- puts "FAILED: ReaderStates.set_current_state_of! / current_state_of returned #{test_state1},#{test_state0} instead of #{Smartcard::PCSC::STATE_ATRMATCH},#{Smartcard::PCSC::STATE_CHANGED}\n"
20
- return false
21
- end
22
- test_state0, test_state1 = reader_states.event_state_of(0), reader_states.event_state_of(1)
23
- if (test_state0 != Smartcard::PCSC::STATE_IGNORE) or (test_state1 != Smartcard::PCSC::STATE_PRESENT)
24
- puts "FAILED: ReaderStates.set_event_state_of! / event_state_of returned #{test_state0},#{test_state1} instead of #{Smartcard::PCSC::STATE_IGNORE},#{Smartcard::PCSC::STATE_PRESENT}\n"
25
- return false
26
- end
27
- test_atr1, test_atr0 = reader_states.atr_of(1), reader_states.atr_of(0)
28
- if (test_atr1 != "Ruby\0rocks!") or (test_atr0 != "grreat success")
29
- puts "FAILED: ReaderStates.set_atr_of! / atr_of returned '#{test_atr1}','#{test_atr0}' instead of 'Ruby\\0rocks!','grreat success'\n"
30
- return false
31
- end
32
- test_reader0, test_reader1 = reader_states.reader_name_of(0), reader_states.reader_name_of(1)
33
- if (test_reader0 != "PC/SC Reader 0") or (test_reader1 != "CCID Reader 1")
34
- puts "FAILED: ReaderStates.set_reader_name_of! / reader_name_of returned '#{test_reader0}','#{test_reader1}' instead of 'PC/SC Reader 0','CCID Reader 1'\n"
35
- return false
36
- end
37
-
38
- [5, 2, nil].each do |bad_index|
39
- exception_thrown = false
40
- begin
41
- reader_states.current_state_of(bad_index)
42
- rescue IndexError => e
43
- puts "(expected) exception thrown: #{e}\n"
44
- exception_thrown = e
45
- rescue TypeError => e
46
- puts "(expected) exception thrown: #{e}\n"
47
- exception_thrown = e
48
- end
49
- unless exception_thrown
50
- puts "FAILED: ReaderStates.current_state_of responded for bad index #{bad_index}\n"
51
- return false
52
- end
53
- end
54
-
55
- return true
56
- end
57
-
58
- def test_io_request
59
- io_request = Smartcard::PCSC::IoRequest.new
60
- [Smartcard::PCSC::PROTOCOL_T0, Smartcard::PCSC::PROTOCOL_T1, Smartcard::PCSC::PROTOCOL_RAW].each do |t_protocol|
61
- io_request.protocol = t_protocol
62
- r_protocol = io_request.protocol
63
- if r_protocol != t_protocol
64
- puts "FAILED: IoRequest.protocol= / protocol failed for protocol #{t_protocol} (got #{r_protocol} instead)\n"
65
- return false
66
- end
67
- end
68
- end
69
-
70
- test_reader_states
71
- test_io_request
72
-
73
-
74
- context = Smartcard::PCSC::Context.new(Smartcard::PCSC::SCOPE_SYSTEM);
4
+ context = Smartcard::PCSC::Context.new(Smartcard::PCSC::SCOPE_SYSTEM)
75
5
 
76
6
  reader_groups = context.list_reader_groups
77
7
  pp reader_groups
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartcard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-10 00:00:00 -05:00
12
+ date: 2008-05-01 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,8 +19,26 @@ executables: []
19
19
 
20
20
  extensions:
21
21
  - ext/smartcard_pcsc/extconf.rb
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - BUILD
24
+ - CHANGELOG
25
+ - ext/smartcard_pcsc/extconf.rb
26
+ - ext/smartcard_pcsc/pcsc.h
27
+ - ext/smartcard_pcsc/pcsc_card.c
28
+ - ext/smartcard_pcsc/pcsc_constants.c
29
+ - ext/smartcard_pcsc/pcsc_context.c
30
+ - ext/smartcard_pcsc/pcsc_exception.c
31
+ - ext/smartcard_pcsc/pcsc_io_request.c
32
+ - ext/smartcard_pcsc/pcsc_main.c
33
+ - ext/smartcard_pcsc/pcsc_multi_strings.c
34
+ - ext/smartcard_pcsc/pcsc_namespace.c
35
+ - ext/smartcard_pcsc/pcsc_reader_states.c
36
+ - ext/smartcard_pcsc/pcsc_surrogate_reader.h
37
+ - ext/smartcard_pcsc/pcsc_surrogate_wintypes.h
38
+ - lib/smartcard/pcsc_exception.rb
39
+ - lib/smartcard.rb
40
+ - LICENSE
41
+ - README
24
42
  files:
25
43
  - BUILD
26
44
  - CHANGELOG
@@ -29,6 +47,7 @@ files:
29
47
  - ext/smartcard_pcsc/pcsc_card.c
30
48
  - ext/smartcard_pcsc/pcsc_constants.c
31
49
  - ext/smartcard_pcsc/pcsc_context.c
50
+ - ext/smartcard_pcsc/pcsc_exception.c
32
51
  - ext/smartcard_pcsc/pcsc_io_request.c
33
52
  - ext/smartcard_pcsc/pcsc_main.c
34
53
  - ext/smartcard_pcsc/pcsc_multi_strings.c
@@ -36,18 +55,25 @@ files:
36
55
  - ext/smartcard_pcsc/pcsc_reader_states.c
37
56
  - ext/smartcard_pcsc/pcsc_surrogate_reader.h
38
57
  - ext/smartcard_pcsc/pcsc_surrogate_wintypes.h
58
+ - lib/smartcard/pcsc_exception.rb
39
59
  - lib/smartcard.rb
40
60
  - LICENSE
41
61
  - Manifest
42
62
  - README
43
- - test/test_all.rb
63
+ - test/test_containers.rb
64
+ - test/test_smoke.rb
44
65
  - tests/ts_pcsc_ext.rb
45
66
  - smartcard.gemspec
46
67
  has_rdoc: true
47
68
  homepage: http://www.costan.us/smartcard
48
69
  post_install_message:
49
- rdoc_options: []
50
-
70
+ rdoc_options:
71
+ - --line-numbers
72
+ - --inline-source
73
+ - --title
74
+ - Smartcard
75
+ - --main
76
+ - README
51
77
  require_paths:
52
78
  - lib
53
79
  - ext
@@ -66,9 +92,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
92
  requirements: []
67
93
 
68
94
  rubyforge_project: smartcard
69
- rubygems_version: 1.0.1
95
+ rubygems_version: 1.1.1
70
96
  signing_key:
71
97
  specification_version: 2
72
98
  summary: Interface with ISO 7816 smart cards.
73
99
  test_files:
74
- - test/test_all.rb
100
+ - test/test_containers.rb
101
+ - test/test_smoke.rb
File without changes