iso8583 0.1.1 → 0.1.3
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/AUTHORS +1 -0
- data/CHANGELOG +10 -0
- data/README +5 -27
- data/Rakefile +56 -60
- data/lib/8583.rb +12 -0
- data/lib/8583/berlin.rb +82 -0
- data/lib/8583/bitmap.rb +117 -0
- data/lib/8583/codec.rb +189 -0
- data/lib/8583/exception.rb +4 -0
- data/lib/8583/field.rb +90 -0
- data/lib/8583/fields.rb +148 -0
- data/lib/8583/message.rb +419 -0
- data/lib/8583/util.rb +94 -0
- data/lib/iso8583.rb +2 -6
- data/test/BitmapTests.rb +64 -52
- data/test/message_test.rb +50 -11
- data/test/test_codec.rb +16 -9
- data/test/test_fields.rb +37 -13
- data/test/test_seperate_msg.rb +22 -0
- data/test/test_util.rb +32 -0
- metadata +25 -14
- data/lib/berlin.rb +0 -79
- data/lib/bitmap.rb +0 -117
- data/lib/codec.rb +0 -173
- data/lib/exception.rb +0 -5
- data/lib/field.rb +0 -178
- data/lib/fields.rb +0 -130
- data/lib/message.rb +0 -416
data/lib/8583/util.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Copyright 2009 by Tim Becker (tim.becker@kuriostaet.de)
|
2
|
+
# MIT License, for details, see the LICENSE file accompaning
|
3
|
+
# this distribution
|
4
|
+
|
5
|
+
module ISO8583
|
6
|
+
|
7
|
+
# general utilities
|
8
|
+
#
|
9
|
+
# Convert a String of bytes to their hex representation
|
10
|
+
# E.g.:
|
11
|
+
#
|
12
|
+
# b2hex "\x12\x34\xab" => "1234AB"
|
13
|
+
#
|
14
|
+
def b2hex(byte_string)
|
15
|
+
r = byte_string.unpack("H*")[0]
|
16
|
+
r.length > 1 ? r : " "
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Convert a String containing hex data to
|
21
|
+
# a String containing the corresponding bytes:
|
22
|
+
#
|
23
|
+
# hex2b "abcd12" => "\xa\cd\12"
|
24
|
+
#
|
25
|
+
def hex2b(hex_string)
|
26
|
+
string = hex_string.gsub(/\s+/, "")
|
27
|
+
raise ISO8583Exception.new("Invalid Hex chars: #{hex_string}") unless string =~ /^[A-Fa-f0-9]*$/
|
28
|
+
raise ISO8583Exception.new("Uneven number of Hex chars #{hex_string}") unless ( (string.length % 2) == 0)
|
29
|
+
[string].pack("H*")
|
30
|
+
end
|
31
|
+
|
32
|
+
def _conv(str, mapping)
|
33
|
+
_str = ""
|
34
|
+
str.each_byte{|byte|
|
35
|
+
_str << mapping[byte]
|
36
|
+
}
|
37
|
+
_str
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Convert a String of ASCII chars to EBCDIC
|
42
|
+
#
|
43
|
+
def ascii2ebcdic(ascii)
|
44
|
+
_conv(ascii, US_ASCII2IBM037)
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Convert an EBCDIC String to ASCII
|
49
|
+
#
|
50
|
+
def ebcdic2ascii(ebcdic)
|
51
|
+
_conv(ebcdic, IBM0372US_ASCII)
|
52
|
+
end
|
53
|
+
|
54
|
+
# The charsets supported by iconv aren't guranteed. At the very least MACs don't support ebcdic,
|
55
|
+
# so providing rudimentary mappings here.
|
56
|
+
US_ASCII2IBM037 = [
|
57
|
+
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
58
|
+
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
|
59
|
+
0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61,
|
60
|
+
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x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3f, 0x3f, 0x3f, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22,
|
84
|
+
0x3f, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
|
85
|
+
0x3f, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
|
86
|
+
0x3f, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
|
87
|
+
0x5e, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x5b, 0x5d, 0x3f, 0x3f, 0x3f, 0x3f,
|
88
|
+
0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
|
89
|
+
0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
|
90
|
+
0x5c, 0x3f, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
|
91
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
|
92
|
+
]
|
93
|
+
|
94
|
+
end
|
data/lib/iso8583.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
|
5
|
-
require
|
6
|
-
require "fields"
|
7
|
-
require "exception"
|
8
|
-
require "bitmap"
|
9
|
-
require "message"
|
4
|
+
|
5
|
+
require '8583'
|
data/test/BitmapTests.rb
CHANGED
@@ -1,68 +1,80 @@
|
|
1
1
|
require 'lib/iso8583'
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
|
+
include ISO8583
|
5
|
+
|
4
6
|
class BitmapTests < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
def test_create_empty
|
8
|
+
b = Bitmap.new
|
9
|
+
assert_equal(b.to_s.size, 64, "proper length: 64")
|
10
|
+
b.set(112)
|
11
|
+
assert_equal(b.to_s.size, 128, "proper length: 128")
|
12
|
+
assert_equal(b.to_s, "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000")
|
13
|
+
b.unset(112)
|
14
|
+
5.step(20,2){|i| b.set(i)}
|
15
|
+
assert(b.to_s.size==64, "proper length: 64")
|
16
|
+
assert_equal(b.to_s, "0000101010101010101000000000000000000000000000000000000000000000")
|
17
|
+
assert b[5]
|
18
|
+
assert b[7]
|
19
|
+
assert b[11]
|
20
|
+
assert !b[12]
|
21
|
+
assert !b[199]
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
23
|
+
assert_raises(ISO8583Exception) {b.set 1000 }
|
24
|
+
assert_raises(ISO8583Exception) { b.set 1 }
|
25
|
+
assert_raises(ISO8583Exception) { b.set -1 }
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def test_out_of_bounds_errors
|
29
|
+
b = Bitmap.new
|
30
|
+
assert_raises(ISO8583Exception) {b.set 1000 }
|
31
|
+
assert_raises(ISO8583Exception) { b.set 1 }
|
32
|
+
assert_raises(ISO8583Exception) { b.set -1 }
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def test_parse_bmp
|
36
|
+
# 0000000001001001001001001001001001001001001001001001001001000000
|
37
|
+
# generated by: 10.step(60,3) {|i| mp.set(i)}
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
tst = "\x00\x49\x24\x92\x49\x24\x92\x40"
|
40
|
+
b = Bitmap.new tst
|
41
|
+
10.step(60,3) {|i|
|
42
|
+
assert(b[i], "bit #{i} is not set.")
|
43
|
+
assert(!b[i+i], "bit #{i+i} is set.")
|
44
|
+
}
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
#10000000000000000001000000100000010000001000000100000010000001000000100000010000001000000100000010000001000000100000010000001000
|
47
|
+
# generated by: 20.step(128,7) {|i| mp.set(i)}
|
48
|
+
tst = "\x80\x00\x10\x20\x40\x81\x02\x04\x08\x10\x20\x40\x81\x02\x04\x08"
|
49
|
+
b = Bitmap.new tst
|
50
|
+
20.step(128,7) {|i|
|
51
|
+
assert(b[i], "bit #{i} is not set. (128 bit map)")
|
52
|
+
assert(!b[i+i], "bit #{i+i} is set. (128 bit map)")
|
53
|
+
}
|
54
|
+
end
|
56
55
|
|
57
56
|
def test_parse_rest
|
58
57
|
tst = "\x00\x49\x24\x92\x49\x24\x92\x40\x31\x32\x33\x34"
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
b, rest = Bitmap.parse tst
|
59
|
+
10.step(60,3) {|i|
|
60
|
+
assert(b[i], "bit #{i} is not set.")
|
61
|
+
assert(!b[i+i], "bit #{i+i} is set.")
|
62
|
+
}
|
64
63
|
assert_equal("1234", rest)
|
65
64
|
end
|
66
65
|
|
66
|
+
def test_each
|
67
|
+
bmp = Bitmap.new
|
68
|
+
bmp.set(2)
|
69
|
+
bmp.set(3)
|
70
|
+
bmp.set(5)
|
71
|
+
bmp.set(6)
|
72
|
+
arr = []
|
73
|
+
bmp.each{|bit|
|
74
|
+
arr.push bit
|
75
|
+
}
|
76
|
+
assert_equal [2,3,5,6], arr
|
77
|
+
end
|
78
|
+
|
67
79
|
end
|
68
|
-
|
80
|
+
|
data/test/message_test.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
require 'lib/
|
2
|
-
require 'lib/berlin'
|
1
|
+
require 'lib/8583'
|
2
|
+
require 'lib/8583/berlin'
|
3
3
|
require 'test/unit'
|
4
4
|
|
5
|
+
include ISO8583
|
6
|
+
|
5
7
|
class MessageTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
+
def test_create_empty
|
9
|
+
mes = BerlinMessage.new
|
8
10
|
mes.mti = 1100
|
9
11
|
pan = 474747474747
|
10
12
|
mes.pan = pan
|
@@ -30,15 +32,15 @@ class MessageTest < Test::Unit::TestCase
|
|
30
32
|
assert_equal pan, mes[2]
|
31
33
|
assert_equal pan, mes["Primary Account Number (PAN)"]
|
32
34
|
assert_equal "1420@\000\000\000\000\000\000\00012474747474747", mes.to_b
|
33
|
-
|
35
|
+
end
|
34
36
|
|
35
|
-
|
37
|
+
def test_parse
|
36
38
|
pan = 474747474747
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
assert_raises(ISO8583Exception) {
|
41
|
+
mes = BerlinMessage.parse "@\000\000\000\000\000\000\00012474747474747"
|
40
42
|
}
|
41
|
-
|
43
|
+
mes = BerlinMessage.parse "1430@\000\000\000\000\000\000\00012474747474747"
|
42
44
|
assert_equal pan, mes.pan
|
43
45
|
assert_equal 1430, mes.mti
|
44
46
|
end
|
@@ -118,7 +120,44 @@ END
|
|
118
120
|
assert_equal expected, mes.to_s
|
119
121
|
end
|
120
122
|
|
123
|
+
def test_round_trip
|
124
|
+
mes = BerlinMessage.new
|
125
|
+
mes.mti = "Network Management Request Response Issuer Gateway or Acquirer Gateway"
|
126
|
+
mes[2] = 12341234
|
127
|
+
mes[3] = 1111
|
128
|
+
mes[4] = 100
|
129
|
+
mes[6] = 101
|
130
|
+
mes[7] = "0808120000"
|
131
|
+
mes[10] = 100
|
132
|
+
mes[11] = 0
|
133
|
+
mes[12] = "740808120000"
|
134
|
+
mes[14] = "1010"
|
135
|
+
mes[22] = "POSDATACODE"
|
136
|
+
mes[23] = 0
|
137
|
+
mes[24] = 1
|
138
|
+
mes[25] = 90
|
139
|
+
mes[26] = 4444
|
140
|
+
mes[30] = 150
|
141
|
+
mes[32] = 321321
|
142
|
+
mes[35] = ";123123123=123?5"
|
143
|
+
mes[37] = "123 123"
|
144
|
+
mes[38] = "90"
|
145
|
+
mes[39] = 90
|
146
|
+
mes[41] = "TermLoc!"
|
147
|
+
mes[42] = "ID Code!"
|
148
|
+
mes[43] = "Card Acceptor Name Location"
|
149
|
+
mes[49] = "840"
|
150
|
+
mes[51] = 978
|
151
|
+
mes[52] = "\x00\x01\x02\x03"
|
152
|
+
mes[53] = "\x07\x06\x05\x04"
|
153
|
+
mes[54] = "No additional amount"
|
154
|
+
mes[55] = '\x07\x06\x05\x04'
|
155
|
+
mes[56] = 88888888888
|
156
|
+
mes[59] = "I'm you're private data, data for money..."
|
157
|
+
mes[64] = "\xF0\xF0\xF0\xF0"
|
121
158
|
|
122
|
-
|
159
|
+
bytes = mes.to_b
|
160
|
+
mes2 = BerlinMessage.parse(mes.to_b)
|
161
|
+
assert_equal(mes.to_b, mes2.to_b)
|
162
|
+
end
|
123
163
|
end
|
124
|
-
|
data/test/test_codec.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'lib/iso8583'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
include ISO8583
|
7
5
|
|
6
|
+
class FieldTest < Test::Unit::TestCase
|
8
7
|
def test_MMDDhhmmssCodec
|
9
8
|
dt = MMDDhhmmssCodec.decode "1212121212"
|
10
9
|
assert_equal DateTime, dt.class
|
@@ -14,7 +13,6 @@ class FieldTest < Test::Unit::TestCase
|
|
14
13
|
assert_equal 12, dt.min
|
15
14
|
assert_equal 12, dt.sec
|
16
15
|
|
17
|
-
|
18
16
|
assert_raise(ISO8583Exception) {
|
19
17
|
dt = MMDDhhmmssCodec.decode "1312121212"
|
20
18
|
}
|
@@ -36,7 +34,6 @@ class FieldTest < Test::Unit::TestCase
|
|
36
34
|
assert_equal 12, dt.min
|
37
35
|
assert_equal 12, dt.sec
|
38
36
|
|
39
|
-
|
40
37
|
assert_raise(ISO8583Exception) {
|
41
38
|
dt = YYMMDDhhmmssCodec.decode "091312121212"
|
42
39
|
}
|
@@ -46,15 +43,14 @@ class FieldTest < Test::Unit::TestCase
|
|
46
43
|
}
|
47
44
|
|
48
45
|
assert_equal "091212121212", YYMMDDhhmmssCodec.encode("091212121212")
|
49
|
-
|
50
46
|
end
|
47
|
+
|
51
48
|
def test_YYMMCodec
|
52
49
|
dt = YYMMCodec.decode "0812"
|
53
50
|
assert_equal DateTime, dt.class
|
54
51
|
assert_equal 2008, dt.year
|
55
52
|
assert_equal 12, dt.month
|
56
53
|
|
57
|
-
|
58
54
|
assert_raise(ISO8583Exception) {
|
59
55
|
dt = YYMMCodec.decode "0913"
|
60
56
|
}
|
@@ -64,7 +60,6 @@ class FieldTest < Test::Unit::TestCase
|
|
64
60
|
}
|
65
61
|
|
66
62
|
assert_equal "0912", YYMMCodec.encode("0912")
|
67
|
-
|
68
63
|
end
|
69
64
|
|
70
65
|
def test_AN_Codec
|
@@ -86,5 +81,17 @@ class FieldTest < Test::Unit::TestCase
|
|
86
81
|
assert_equal ";123123123=123?5", Track2.decode(";123123123=123?5")
|
87
82
|
end
|
88
83
|
|
89
|
-
|
84
|
+
def test_packed_codec
|
85
|
+
assert_equal "\x12", Packed_Number.encode(12)
|
86
|
+
assert_equal "\x12", Packed_Number.encode("12")
|
87
|
+
assert_equal "\x02", Packed_Number.encode("2")
|
88
|
+
assert_equal "\x02", Packed_Number.encode(2)
|
89
|
+
assert_equal "\x02\x55", Packed_Number.encode(0xff)
|
90
|
+
assert_raise(ISO8583Exception) {
|
91
|
+
dt = Packed_Number.encode ";12312312=123?5"
|
92
|
+
}
|
93
|
+
assert_raise(ISO8583Exception) {
|
94
|
+
dt = Packed_Number.encode "F"
|
95
|
+
}
|
96
|
+
end
|
90
97
|
end
|
data/test/test_fields.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'lib/iso8583'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
include ISO8583
|
7
5
|
|
6
|
+
class FieldTest < Test::Unit::TestCase
|
8
7
|
def test_LLL
|
9
8
|
value, rest = LLL.parse "123456"
|
10
9
|
assert_equal 123, value
|
@@ -34,9 +33,12 @@ class FieldTest < Test::Unit::TestCase
|
|
34
33
|
assert_raise(ISO8583Exception) {
|
35
34
|
enc = LLL.encode "1234"
|
36
35
|
}
|
37
|
-
|
38
|
-
|
36
|
+
end
|
39
37
|
|
38
|
+
def test_LL_BCD
|
39
|
+
value, rest = LL_BCD.parse "\x123456"
|
40
|
+
assert_equal 12, value
|
41
|
+
assert_equal "3456", rest
|
40
42
|
end
|
41
43
|
|
42
44
|
def test_LLVAR_N
|
@@ -70,9 +72,9 @@ class FieldTest < Test::Unit::TestCase
|
|
70
72
|
assert_raise(ISO8583Exception) {
|
71
73
|
enc = LLLVAR_N.encode "1234ABCD"
|
72
74
|
}
|
73
|
-
|
74
75
|
end
|
75
|
-
|
76
|
+
|
77
|
+
def test_LLVAR_Z
|
76
78
|
value, rest = LLVAR_Z.parse "16;123123123=123?5"+"021234"
|
77
79
|
assert_equal ";123123123=123?5", value
|
78
80
|
assert_equal "021234", rest
|
@@ -94,10 +96,6 @@ class FieldTest < Test::Unit::TestCase
|
|
94
96
|
assert_raise(ISO8583Exception) {
|
95
97
|
enc = LLVAR_Z.encode "1234ABCD"
|
96
98
|
}
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
99
|
end
|
102
100
|
|
103
101
|
def test_AN
|
@@ -144,6 +142,7 @@ class FieldTest < Test::Unit::TestCase
|
|
144
142
|
assert_equal "10 ", fld.encode("10")
|
145
143
|
assert_equal ["1!", "a"], fld.parse("1! a")
|
146
144
|
end
|
145
|
+
|
147
146
|
def test_B
|
148
147
|
fld = B.dup
|
149
148
|
fld.length = 3
|
@@ -159,6 +158,31 @@ class FieldTest < Test::Unit::TestCase
|
|
159
158
|
assert_equal ["1! ", "a"], fld.parse("1! a")
|
160
159
|
assert_equal ["1!", ""], fld.parse("1!\000")
|
161
160
|
end
|
162
|
-
|
163
|
-
|
161
|
+
|
162
|
+
def test_N_BCD
|
163
|
+
fld = N_BCD.dup
|
164
|
+
fld.length=3
|
165
|
+
value, rest = fld.parse "\x01\x23\x45"
|
166
|
+
assert_equal 123, value
|
167
|
+
|
168
|
+
assert_equal "\x01\x23", fld.encode(123)
|
169
|
+
assert_equal "\x01\x23", fld.encode("123")
|
170
|
+
assert_equal "\x01\x23", fld.encode("0123")
|
171
|
+
|
172
|
+
assert_raise(ISO8583Exception) {
|
173
|
+
fld.encode 12345
|
174
|
+
}
|
175
|
+
|
176
|
+
# There's a bug here. A 4 digit value encodes to 2 digits encoded,
|
177
|
+
# which passes the test for length ... This test doesn't pass:
|
178
|
+
|
179
|
+
#asssert_raise (ISO8583Exception) {
|
180
|
+
# fld.encode 1234
|
181
|
+
#}
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_YYMMDDhhmmss
|
185
|
+
fld = YYMMDDhhmmss
|
186
|
+
assert_equal "740808120000", fld.encode("740808120000")
|
187
|
+
end
|
164
188
|
end
|