smartcard 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/smartcard_pcsc/extconf.rb +19 -7
- data/ext/smartcard_pcsc/pcsc.h +3 -0
- data/ext/smartcard_pcsc/pcsc_card.c +7 -1
- data/ext/smartcard_pcsc/pcsc_main.c +1 -1
- data/lib/smartcard.rb +1 -1
- data/tests/ts_pcsc_ext.rb +10 -5
- metadata +1 -1
@@ -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
|
-
|
10
|
+
# TODO: no clue what to do here
|
13
11
|
else
|
14
|
-
|
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('
|
34
|
+
create_makefile('smartcard/pcsc')
|
data/ext/smartcard_pcsc/pcsc.h
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/smartcard.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|