iso7813 0.0.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/.gitignore +18 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/iso7813.gemspec +23 -0
- data/lib/iso7813/track1.rb +78 -0
- data/lib/iso7813/track2.rb +59 -0
- data/lib/iso7813/version.rb +3 -0
- data/lib/iso7813.rb +6 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/track1_spec.rb +22 -0
- data/spec/track2_spec.rb +20 -0
- metadata +99 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Eduardo Mourao
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Iso7813
|
2
|
+
|
3
|
+
This is the full ISO-7813 implementation, in ruby! This is battle tested, production ready. Use at will.
|
4
|
+
|
5
|
+
I recommend that you copy those files into your own project and not use this as a gem.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'iso7813'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install iso7813
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Just include the modules into your classes.
|
24
|
+
|
25
|
+
## Help
|
26
|
+
|
27
|
+
Pretty please: don't ask me anything before reading the standard and the code. I'm either busy or drinking beer.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/iso7813.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iso7813/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
|
8
|
+
gem.add_development_dependency "rspec"
|
9
|
+
gem.add_dependency 'iso7812'
|
10
|
+
|
11
|
+
gem.name = "iso7813"
|
12
|
+
gem.version = Iso7813::VERSION
|
13
|
+
gem.authors = ["Eduardo Mourao"]
|
14
|
+
gem.email = ["eduardo.a20@gmail.com"]
|
15
|
+
gem.description = %q{Implementation of the ISO/IEC 7813 standard}
|
16
|
+
gem.summary = %q{Implementation of the ISO/IEC 7813 standard}
|
17
|
+
gem.homepage = ""
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'iso7812'
|
2
|
+
|
3
|
+
module Iso7813
|
4
|
+
|
5
|
+
class Track1
|
6
|
+
|
7
|
+
include Iso7812::CardNumber
|
8
|
+
|
9
|
+
def stx
|
10
|
+
'%'
|
11
|
+
end
|
12
|
+
|
13
|
+
def fc
|
14
|
+
'B'
|
15
|
+
end
|
16
|
+
|
17
|
+
def fs
|
18
|
+
'^'
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :last_name
|
22
|
+
attr_accessor :first_name
|
23
|
+
attr_accessor :middle_name
|
24
|
+
attr_accessor :title
|
25
|
+
attr_accessor :pan
|
26
|
+
attr_accessor :expiration_date
|
27
|
+
attr_accessor :service_code
|
28
|
+
|
29
|
+
def nm
|
30
|
+
_nm = "#{last_name}/#{first_name}"
|
31
|
+
_nm << " #{middle_name}" unless middle_name.nil?
|
32
|
+
_nm << ".#{title}" unless title.nil?
|
33
|
+
_nm
|
34
|
+
end
|
35
|
+
|
36
|
+
def ed
|
37
|
+
expiration_date || "^"
|
38
|
+
end
|
39
|
+
|
40
|
+
def sc
|
41
|
+
service_code || "^"
|
42
|
+
end
|
43
|
+
|
44
|
+
def dd
|
45
|
+
"#{stx}#{fc}#{pan}#{fs}#{nm}#{fs}#{ed}#{sc}".length.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def etx
|
49
|
+
"?"
|
50
|
+
end
|
51
|
+
|
52
|
+
def lrc(_track)
|
53
|
+
raise 'The track printer should do that, not the track generation software (parity)'
|
54
|
+
end
|
55
|
+
|
56
|
+
def track(include_lrc_and_sentinel = false)
|
57
|
+
_track = "#{stx}#{fc}#{pan}#{fs}#{nm}#{fs}#{ed}#{sc}#{dd}"
|
58
|
+
_track << "#{etx}#{lrc(_track)}" if include_lrc_and_sentinel
|
59
|
+
_track
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.generate(fields = {}, include_lrc_and_sentinel = false)
|
63
|
+
|
64
|
+
track1 = Track1.new
|
65
|
+
track1.last_name = fields[:last_name]
|
66
|
+
track1.first_name = fields[:first_name]
|
67
|
+
track1.middle_name = fields[:middle_name]
|
68
|
+
track1.title = fields[:title]
|
69
|
+
track1.pan = fields[:pan]
|
70
|
+
track1.expiration_date = fields[:expiration_date]
|
71
|
+
track1.service_code = fields[:service_code]
|
72
|
+
|
73
|
+
track1.track(include_lrc_and_sentinel)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'iso7812'
|
2
|
+
|
3
|
+
module Iso7813
|
4
|
+
|
5
|
+
class Track2
|
6
|
+
|
7
|
+
include Iso7812::CardNumber
|
8
|
+
|
9
|
+
attr_accessor :pan
|
10
|
+
attr_accessor :expiration_date
|
11
|
+
attr_accessor :service_code
|
12
|
+
|
13
|
+
def stx
|
14
|
+
';'
|
15
|
+
end
|
16
|
+
|
17
|
+
def ed
|
18
|
+
expiration_date || "="
|
19
|
+
end
|
20
|
+
|
21
|
+
def sc
|
22
|
+
service_code || "="
|
23
|
+
end
|
24
|
+
|
25
|
+
def dd
|
26
|
+
"#{stx}#{pan}#{fs}#{ed}#{sc}".length.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def etx
|
30
|
+
"?"
|
31
|
+
end
|
32
|
+
|
33
|
+
def fs
|
34
|
+
'='
|
35
|
+
end
|
36
|
+
|
37
|
+
def lrc(_track)
|
38
|
+
raise 'The track printer should do that, not the track generation software (parity)'
|
39
|
+
end
|
40
|
+
|
41
|
+
def track(include_lrc_and_sentinel = false)
|
42
|
+
_track = "#{stx}#{pan}#{fs}#{ed}#{sc}#{dd}"
|
43
|
+
_track << "#{etx}#{lrc(_track)}" if include_lrc_and_sentinel
|
44
|
+
_track
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.generate(fields = {}, include_lrc_and_sentinel = false)
|
48
|
+
|
49
|
+
track2 = Track2.new
|
50
|
+
track2.pan = fields[:pan]
|
51
|
+
track2.expiration_date = fields[:expiration_date]
|
52
|
+
track2.service_code = fields[:service_code]
|
53
|
+
|
54
|
+
track2.track(include_lrc_and_sentinel)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/lib/iso7813.rb
ADDED
data/spec/spec_helper.rb
ADDED
data/spec/track1_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Iso7813
|
4
|
+
|
5
|
+
describe Track1 do
|
6
|
+
|
7
|
+
it "should correctly create a track1" do
|
8
|
+
|
9
|
+
track = Track1.generate( {last_name: 'DOE',
|
10
|
+
first_name: 'JOHN',
|
11
|
+
pan: '1234567890123445',
|
12
|
+
expiration_date: '9901',
|
13
|
+
service_code: '101'}, false)
|
14
|
+
|
15
|
+
track.should eq "%B1234567890123445^DOE/JOHN^990110135"
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
end
|
data/spec/track2_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Iso7813
|
4
|
+
|
5
|
+
describe Track2 do
|
6
|
+
|
7
|
+
it "should correctly create a track2" do
|
8
|
+
|
9
|
+
track = Track2.generate( { pan: '1234567890123445',
|
10
|
+
expiration_date: '9901',
|
11
|
+
service_code: '101'}, false)
|
12
|
+
|
13
|
+
track.should eq ";1234567890123445=990110125"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iso7813
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eduardo Mourao
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: iso7812
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Implementation of the ISO/IEC 7813 standard
|
47
|
+
email:
|
48
|
+
- eduardo.a20@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- iso7813.gemspec
|
59
|
+
- lib/iso7813.rb
|
60
|
+
- lib/iso7813/track1.rb
|
61
|
+
- lib/iso7813/track2.rb
|
62
|
+
- lib/iso7813/version.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/track1_spec.rb
|
65
|
+
- spec/track2_spec.rb
|
66
|
+
homepage: ''
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
hash: -1157021876782384626
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
hash: -1157021876782384626
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.8.24
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Implementation of the ISO/IEC 7813 standard
|
96
|
+
test_files:
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/track1_spec.rb
|
99
|
+
- spec/track2_spec.rb
|