smartcard 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,34 @@
1
1
  require 'mkmf'
2
+ require 'pp'
2
3
 
4
+ $CFLAGS ||= ''
3
5
  $LDFLAGS ||= ''
4
6
 
5
- pcsc_headers = []
6
- pcsc_defines = []
7
7
  if RUBY_PLATFORM =~ /darwin/
8
- pcsc_headers += ['<PCSC/winscard.h>']
9
- pcsc_headers += ['"pcsc_surrogate_wintypes.h"', '"pcsc_surrogate_reader.h"']
10
8
  $LDFLAGS += ' -framework PCSC'
11
9
  elsif RUBY_PLATFORM =~ /win/
12
- pcsc_headers += ['<winscard.h>']
10
+ # TODO: no clue what to do here
13
11
  else
14
- pcsc_headers += ['<winscard.h>']
12
+ # pcsc is retarded and uses stuff like '#include <wintypes.h>'
13
+ $CFLAGS += ' -I /usr/include/PCSC -I /usr/local/include/pcsc'
14
+ have_library('pcsclite')
15
15
  end
16
16
 
17
+ pcsc_headers = []
18
+ ['wintypes.h', 'reader.h', 'winscard.h', 'pcsclite.h'].each do |header|
19
+ ['', 'PCSC/', './pcsc_surrogate_'].each do |path_prefix|
20
+ if have_header(path_prefix + header)
21
+ pcsc_headers.push((path_prefix[0,1] == '.') ? "\"#{path_prefix + header}\"" : "<#{path_prefix + header}>")
22
+ break
23
+ end
24
+ end
25
+ end
26
+
27
+ pcsc_defines = []
28
+
17
29
  File.open('pcsc_include.h', 'w') do |f|
18
30
  pcsc_defines.each { |d| f.write "\#define #{d}\n" }
19
31
  pcsc_headers.each { |h| f.write "\#include #{h}\n" }
20
32
  end
21
33
 
22
- create_makefile('smartcard_pcsc')
34
+ create_makefile('smartcard/pcsc')
@@ -3,6 +3,9 @@
3
3
  /* Generated by 'extconf.rb' to point to the PC/SC header. */
4
4
  #include "pcsc_include.h"
5
5
 
6
+ /* Entrypoint into the Ruby extension. */
7
+ void Init_pcsc();
8
+
6
9
  /* Namespace structure. */
7
10
  extern VALUE mSmartcard; /* Smartcard module / namespace */
8
11
  extern VALUE mPcsc; /* Smartcard::PCSC module / namespace */
@@ -263,7 +263,13 @@ static VALUE PCSC_Card_transmit(VALUE self, VALUE rbSendData, VALUE rbSendIoRequ
263
263
  return Qnil;
264
264
  }
265
265
 
266
- DWORD recv_length = PCSCLITE_MAX_MESSAGE_SIZE;
266
+ #if defined(PCSCLITE_MAX_MESSAGE_SIZE)
267
+ DWORD recv_length = PCSCLITE_MAX_MESSAGE_SIZE;
268
+ #elif defined(MAX_BUFFER_SIZE_EXTENDED)
269
+ DWORD recv_length = MAX_BUFFER_SIZE_EXTENDED;
270
+ #else
271
+ DWORD recv_length = 65536;
272
+ #endif
267
273
  char *recv_buffer = ALLOC_N(char, recv_length);
268
274
  if(recv_buffer == NULL) return Qnil;
269
275
 
@@ -1,6 +1,6 @@
1
1
  #include "pcsc.h"
2
2
 
3
- void Init_smartcard_pcsc() {
3
+ void Init_pcsc() {
4
4
  Init_PCSC_Namespace();
5
5
  Init_PCSC_ReaderStates();
6
6
  Init_PCSC_IoRequest();
data/lib/smartcard.rb CHANGED
@@ -1 +1 @@
1
- require 'smartcard_pcsc'
1
+ require 'smartcard/pcsc'
data/tests/ts_pcsc_ext.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'smartcard'
2
+ require 'pp'
2
3
 
3
4
  def test_reader_states
4
5
  reader_states = Smartcard::PCSC::ReaderStates.new(2)
@@ -119,11 +120,15 @@ select_response = card0.transmit(select_apdu.map {|byte| byte.chr}.join(''), sen
119
120
  select_response_str = (0...select_response.length).map { |i| ' %02x' % select_response[i].to_i }.join('')
120
121
  puts "Response:#{select_response_str}\n"
121
122
 
122
- # This only works with GemPlus readers... any other suggestions?
123
- puts "Testing low-level control\n"
124
- ctl_string = [0x82, 0x01, 0x07, 0x00].map {|byte| byte.chr}.join('')
125
- ctl_response = card0.control 2049, ctl_string, 4
126
- pp ctl_response
123
+ begin
124
+ # This only works with GemPlus readers... any other suggestions?
125
+ puts "Testing low-level control\n"
126
+ ctl_string = [0x82, 0x01, 0x07, 0x00].map {|byte| byte.chr}.join('')
127
+ ctl_response = card0.control 2049, ctl_string, 4
128
+ pp ctl_response
129
+ rescue RuntimeError => e
130
+ puts "Card.control threw exception #{e}\n"
131
+ end
127
132
 
128
133
  puts "Disconnecting and cleaning up\n"
129
134
  card0.disconnect Smartcard::PCSC::DISPOSITION_LEAVE
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: smartcard
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
6
+ version: 0.1.1
7
7
  date: 2007-11-16 00:00:00 -05:00
8
8
  summary: Interface with ISO 7816 smart cards.
9
9
  require_paths: