verified 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8371a4df479325c78b7ccda1b0831166c768648
4
- data.tar.gz: c9283c35875c14cbbb2fbc73e3128e13016e248c
3
+ metadata.gz: 662f237da759389d4d0c5555e205f24f775f75f3
4
+ data.tar.gz: 724fb1cd3688075750946b4921d47d9dbdae1f5f
5
5
  SHA512:
6
- metadata.gz: b5a41333437f598396ef93988acb6a8d9aa47d0abb5395a7d152a62cea86788900b6e90b09102330bc9a3ca9bd443539e66c49a43d3e4af3f6cb993684e60455
7
- data.tar.gz: 3a76b4ac8e15741fb8cdfdc6e20d4ff28623f08ee4b67a9057c5759ffd628ee7c1c06f6baec74de633aa196844b441c732cd9fdfac89acd21244ec3686d4cf30
6
+ metadata.gz: 34711f2c9a721d9d84d9f936514b32279b5824efeaa6414075f607fd65fcf5344d10a23a8d5c3134671a42178c64328ece0a78b775b2b6bdb7a069102ac12ec7
7
+ data.tar.gz: d1632fce51c5d5d299490845acdd529bd4bd693fbdfcea9f02b088798ad94da884bd703a14bf57b11bcd5705967cf2da112bd2615a4691f8aab1dd8b6ba2be42
data/.gitattributes ADDED
@@ -0,0 +1,22 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+
4
+ # Custom for Visual Studio
5
+ *.cs diff=csharp
6
+ *.sln merge=union
7
+ *.csproj merge=union
8
+ *.vbproj merge=union
9
+ *.fsproj merge=union
10
+ *.dbproj merge=union
11
+
12
+ # Standard to msysgit
13
+ *.doc diff=astextplain
14
+ *.DOC diff=astextplain
15
+ *.docx diff=astextplain
16
+ *.DOCX diff=astextplain
17
+ *.dot diff=astextplain
18
+ *.DOT diff=astextplain
19
+ *.pdf diff=astextplain
20
+ *.PDF diff=astextplain
21
+ *.rtf diff=astextplain
22
+ *.RTF diff=astextplain
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in verified.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ruby N (rubymeow)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Verified
2
+
3
+ A simple Ruby Gem to verify and parse MRZ codes on passports. Useful if you need to meet KYC or Money Laundering requirements.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'verified'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install verified
21
+
22
+ ## Usage
23
+
24
+ ### Passport
25
+
26
+ Setup your passport instance like so:
27
+ ```ruby
28
+ passport = Verified::Passport.new("mrz_line_1", "mrz_line_2")
29
+ ```
30
+
31
+ ```
32
+ mrz_line_1: The first line of a Passport MRZ (the long strip of text on the bottom). (string, required)
33
+ mrz_line_2: The second line of a Passport MRZ (the long strip of text on the bottom). (string, required)
34
+ ```
35
+
36
+ It then can be called using any of the folllowing methods:
37
+
38
+ ```
39
+ verified? : Returns true if it's a valid passport MRZ, false if it's not.
40
+ issuing_state : Issuing country of the passport
41
+ last_name : Last name on the passport
42
+ first_names : Array of first names on the passport (First and any middle names)
43
+ passport_number : Passport Number
44
+ nationality : Nationality of the person on the passport. Different from the issuing state (eg. Swedish person who is also a citizen of UK.)
45
+ date_of_birth : Date of Birth, given as a Ruby Date object.
46
+ gender : Gender, given as M, F or nil if not specified.
47
+ expiry_date : Expiry date of the passport, given as a Ruby Date object.
48
+ personal_number : Personal number, if chosen to be given by issuer. Nil if not specified.
49
+ ```
50
+
51
+ ### UK Drivers License
52
+
53
+ This is coming soon, as I'm currently waiting for the DVLA to respond to a [freedom of information request]() that will allow me to understand how the check digits in UK driver numbers are calculated.
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install the gem onto your local machine, run `bundle exec rake install`.
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rubymeow/verified.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+
70
+ MRZ parsing based on Document 9303 (Machine Readable Travel Documents - Part 1 - Machine Readable Passports. Volume 1 - Passports with Machine Readable Data Stored in Optical Character Recognition format) by the ICAO which can be found here:
71
+ http://www.icao.int/publications/pages/publication.aspx?docnum=9303
72
+
73
+ Warning: This is by no means a KYC solution on it's own. This merely parses MRZ's and validates they are valid **mrz codes**. This does **not** confirm the document you are verifying is legitimate.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "verified"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/verified.rb CHANGED
@@ -1,22 +1,6 @@
1
- require 'verified/check'
1
+ require "verified/version"
2
+ require "verified/parser"
3
+ require "verified/passport"
2
4
 
3
- Verified = Class.new
4
- class Verified::Passport
5
- def initialize(mrz_line_1, mrz_line_2)
6
- checker = Check.new
7
- @data = checker.check(mrz_line_1, mrz_line_2)
8
- end
9
-
10
- def verified?
11
- return false if @data == false
12
- return true
13
- end
14
-
15
- def method_missing(name, *args, &blk)
16
- if args.empty? && blk.nil? && @data.has_key?(name.to_s)
17
- @data[name.to_s]
18
- else
19
- super
20
- end
21
- end
22
- end
5
+ module Verified
6
+ end
@@ -0,0 +1,4 @@
1
+ require "verified/parser/mrz"
2
+
3
+ module Parser
4
+ end
@@ -0,0 +1,6 @@
1
+ require "verified/parser/mrz/check.rb"
2
+ require "verified/parser/mrz/check_digit.rb"
3
+ require "verified/parser/mrz/yy_date.rb"
4
+
5
+ module MRZ
6
+ end
@@ -0,0 +1,48 @@
1
+ module MRZ
2
+ class Check
3
+ def initialize
4
+ @@digit_checker = CheckDigit.new
5
+ @@date_converter = YYDate.new
6
+ end
7
+
8
+ def check(mrz_line_1, mrz_line_2)
9
+ # Read the first line without chevrons
10
+ split = mrz_line_1.split(/<+/)
11
+
12
+ doc_data = Hash.new(9)
13
+ doc_data["issuing_state"] = mrz_line_1[2...5].sub(/<+/, '')
14
+ doc_data["last_name"] = split[1][3..-1]
15
+ doc_data["first_names"] = split[2..-1]
16
+ doc_data["passport_number"] = mrz_line_2[0...9]
17
+ doc_data["nationality"] = mrz_line_2[10...13].sub(/<+/, '')
18
+ doc_data["date_of_birth"] = @@date_converter.convert_to_date(mrz_line_2[13...19])
19
+ doc_data["gender"] = mrz_line_2[20].sub(/<+/, '')
20
+ doc_data["expiry_date"] = @@date_converter.convert_to_date(mrz_line_2[21...27])
21
+ doc_data["personal_number"] = mrz_line_2[28...42].sub(/<+/, '')
22
+
23
+ # Grabbing the MRZ's check digits
24
+ doc_check = Array.new
25
+ doc_check[0] = mrz_line_2[9].to_s
26
+ doc_check[1] = mrz_line_2[19].to_s
27
+ doc_check[2] = mrz_line_2[27].to_s
28
+ doc_check[3] = mrz_line_2[42].to_s
29
+ doc_check[4] = mrz_line_2[43].to_s
30
+
31
+ # Calculating our own check digits...
32
+ our_check = Array.new
33
+ our_check[0] = @@digit_checker.check_calc(mrz_line_2[0...9])
34
+ our_check[1] = @@digit_checker.check_calc(mrz_line_2[13...19])
35
+ our_check[2] = @@digit_checker.check_calc(mrz_line_2[21...27])
36
+ our_check[3] = @@digit_checker.check_calc(mrz_line_2[28...42])
37
+ our_check[4] = @@digit_checker.check_calc(mrz_line_2[0...10]+mrz_line_2[13...20]+mrz_line_2[21...43])
38
+
39
+ # The 4th check digit can be either > or 0, we always return 0 from our CheckDigit calc.
40
+ if our_check[3] == "0" && doc_check[3] == "<"
41
+ our_check[3] = "<"
42
+ end
43
+
44
+ return doc_data if doc_check.uniq.sort == our_check.uniq.sort
45
+ return false
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ module MRZ
2
+ class CheckDigit
3
+ def check_calc(str)
4
+ str = str.strip.upcase
5
+ values = str.chars.map do |char|
6
+ case char
7
+ when '<'
8
+ 0
9
+ when 'A'..'Z'
10
+ char.ord - 65 + 10
11
+ when '0'..'9'
12
+ char.ord - 48
13
+ else
14
+ raise "Unexpected character '#{char}'"
15
+ end
16
+ end
17
+ return (values.zip([7,3,1].cycle).map{|(v,w)| v * w}.reduce(:+) % 10).to_s
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require "date"
2
+
3
+ module MRZ
4
+ class YYDate
5
+ def convert_to_date(input_date)
6
+ #yymmdd has the flaw of not knowing which century
7
+ #uses current year as a cut off to make an accurate prediction
8
+ current_year_yy = (Date.today.strftime("%Y"))[2..4]
9
+ input_year_yy = input_date[0..1]
10
+ input_month = input_date[2..3]
11
+ input_day = input_date[4..5]
12
+ return Date.parse(input_day+"-"+input_month+"-"+"19"+input_year_yy) if input_year_yy >= current_year_yy
13
+ return Date.parse(input_day+"-"+input_month+"-"+"20"+input_year_yy)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ module Verified
2
+ class Passport
3
+ private
4
+ def initialize(mrz_line_1, mrz_line_2)
5
+ checker = MRZ::Check.new
6
+ @data = checker.check(mrz_line_1, mrz_line_2)
7
+ end
8
+
9
+ def method_missing(name, *args, &blk)
10
+ if args.empty? && blk.nil? && @data.has_key?(name.to_s)
11
+ @data[name.to_s]
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ public
18
+ def verified?
19
+ return true if @data != false
20
+ return false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Verified
2
+ VERSION = "1.3.0"
3
+ end
Binary file
data/verified.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'verified/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "verified"
8
+ spec.version = Verified::VERSION
9
+ spec.authors = ["Ruby"]
10
+ spec.email = ["hi@ruby.sh"]
11
+
12
+ spec.summary = "Really simple passport, drivers license and other identification parsing and verification."
13
+ spec.description = "A simple gem to verify and parse MRZ codes and numbers on passports and UK drivers licenses. Useful if you need to comply with KYC or Money Laundering ID checks."
14
+ spec.homepage = "http://github.com/rubymeow/verified"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ end
metadata CHANGED
@@ -1,24 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verified
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-23 00:00:00.000000000 Z
12
- dependencies: []
13
- description: A simple gem to verify and parse MRZ codes on passports. Useful if you
14
- need to comply with KYC or Money Laundering ID checks.
15
- email: hi@ruby.sh
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A simple gem to verify and parse MRZ codes and numbers on passports and
56
+ UK drivers licenses. Useful if you need to comply with KYC or Money Laundering ID
57
+ checks.
58
+ email:
59
+ - hi@ruby.sh
16
60
  executables: []
17
61
  extensions: []
18
62
  extra_rdoc_files: []
19
63
  files:
64
+ - .gitattributes
65
+ - .gitignore
66
+ - .travis.yml
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
20
73
  - lib/verified.rb
21
- - lib/verified/check.rb
74
+ - lib/verified/parser.rb
75
+ - lib/verified/parser/mrz.rb
76
+ - lib/verified/parser/mrz/check.rb
77
+ - lib/verified/parser/mrz/check_digit.rb
78
+ - lib/verified/parser/mrz/yy_date.rb
79
+ - lib/verified/passport.rb
80
+ - lib/verified/version.rb
81
+ - verified-1.3.0.gem
82
+ - verified.gemspec
22
83
  homepage: http://github.com/rubymeow/verified
23
84
  licenses:
24
85
  - MIT
@@ -29,18 +90,19 @@ require_paths:
29
90
  - lib
30
91
  required_ruby_version: !ruby/object:Gem::Requirement
31
92
  requirements:
32
- - - ">="
93
+ - - '>='
33
94
  - !ruby/object:Gem::Version
34
95
  version: '0'
35
96
  required_rubygems_version: !ruby/object:Gem::Requirement
36
97
  requirements:
37
- - - ">="
98
+ - - '>='
38
99
  - !ruby/object:Gem::Version
39
100
  version: '0'
40
101
  requirements: []
41
102
  rubyforge_project:
42
- rubygems_version: 2.4.5
103
+ rubygems_version: 2.0.14
43
104
  signing_key:
44
105
  specification_version: 4
45
- summary: Really simple passport parsing and verification.
106
+ summary: Really simple passport, drivers license and other identification parsing
107
+ and verification.
46
108
  test_files: []
@@ -1,82 +0,0 @@
1
- require 'date'
2
-
3
- class Check
4
- def check(mrz_line_1, mrz_line_2)
5
- #make a new digit checker
6
- @@digit_checker = CheckDigit.new
7
- @@date_converter = YYDate.new
8
- #string manipulation to simply reading the first line
9
- split = mrz_line_1.split(/<+/)
10
- #get data unformatted from passport
11
- doc_data = Hash.new(9)
12
- #first line of MRZ
13
- doc_data["IssuingState"] = mrz_line_1[2...5].sub(/<+/, '')
14
- doc_data["LastName"] = split[1][3..-1]
15
- doc_data["FirstNames"] = split[2..-1]
16
-
17
- #second line of MRZ
18
- doc_data["Number"] = mrz_line_2[0...9]
19
- doc_data["Nationality"] = mrz_line_2[10...13].sub(/<+/, '')
20
- doc_data["DateOfBirth"] = @@date_converter.convert_to_date(mrz_line_2[13...19])
21
- doc_data["Gender"] = mrz_line_2[20].sub(/<+/, '')
22
- doc_data["ExpiryDate"] = @@date_converter.convert_to_date(mrz_line_2[21...27])
23
- doc_data["PersonalNumber"] = mrz_line_2[28...42].sub(/<+/, '')
24
-
25
- #mrz given check digits
26
- doc_check = Array.new
27
- doc_check[0] = mrz_line_2[9].to_s
28
- doc_check[1] = mrz_line_2[19].to_s
29
- doc_check[2] = mrz_line_2[27].to_s
30
- doc_check[3] = mrz_line_2[42].to_s
31
- doc_check[4] = mrz_line_2[43].to_s
32
-
33
- #calculate our own check digits
34
- our_check = Array.new
35
- our_check[0] = @@digit_checker.check_calc(mrz_line_2[0...9])
36
- our_check[1] = @@digit_checker.check_calc(mrz_line_2[13...19])
37
- our_check[2] = @@digit_checker.check_calc(mrz_line_2[21...27])
38
- our_check[3] = @@digit_checker.check_calc(mrz_line_2[28...42])
39
- our_check[4] = @@digit_checker.check_calc(mrz_line_2[0...10]+mrz_line_2[13...20]+mrz_line_2[21...43])
40
-
41
- #the 4th check digit can be either > or 0, we always return 0 from our CheckDigit calc.
42
- #this basically changes our check to > so the true return can pass
43
- if our_check[3] == "0" && doc_check[3] == "<"
44
- our_check[3] = "<"
45
- end
46
-
47
- return doc_data if doc_check.uniq.sort == our_check.uniq.sort
48
- return false
49
- end
50
- end
51
-
52
- class Check::CheckDigit
53
- def check_calc(str)
54
- str = str.strip.upcase
55
- values = str.chars.map do |char|
56
- case char
57
- when '<'
58
- 0
59
- when 'A'..'Z'
60
- char.ord - 65 + 10
61
- when '0'..'9'
62
- char.ord - 48
63
- else
64
- raise "Unexpected character '#{char}'"
65
- end
66
- end
67
- return (values.zip([7,3,1].cycle).map{|(v,w)| v * w}.reduce(:+) % 10).to_s
68
- end
69
- end
70
-
71
- class Check::YYDate
72
- def convert_to_date(input_date)
73
- #yymmdd has the flaw of not knowing which century
74
- #uses current year as a cut off to make an accurate prediction
75
- current_year_yy = (Date.today.strftime("%Y"))[2..4]
76
- input_year_yy = input_date[0..1]
77
- input_month = input_date[2..3]
78
- input_day = input_date[4..5]
79
- return Date.parse(input_day+"-"+input_month+"-"+"19"+input_year_yy) if input_year_yy >= current_year_yy
80
- return Date.parse(input_day+"-"+input_month+"-"+"20"+input_year_yy)
81
- end
82
- end