maskerade 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +11 -0
- data/.ruby-gemset +1 -0
- data/Gemfile +4 -0
- data/README.md +44 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/maskerade.rb +5 -0
- data/lib/maskerade/credit_card_masker.rb +62 -0
- data/lib/maskerade/version.rb +3 -0
- data/maskerade.gemspec +32 -0
- data/maskerade.png +0 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: acc7e01071137d4e8d0af63cb890f83782a56957f856151008510d01d68f47ba
|
4
|
+
data.tar.gz: 1826c49ba8c23deb12492c5b894a5ff62630039fa03f5331bdf609c43068f6d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4414accea7a7ffb9c166ed59aac8e96ee2812f5bc73ce0bae1897bead3f920f6f50779ce480d26e1e8577d20eb9db42ad6aafd970c261b7529cdffb09494a896
|
7
|
+
data.tar.gz: ee44f4271256f03cd880e4915e79db8a18b54d487600d72ed855f7a6324b0e0d8a6c2436c3e827e0253e5643011942c211e9eb18cd273ecc28a8e90829f581aa
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
maskerade
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
![maskerade.png](maskerade.png)
|
2
|
+
|
3
|
+
# Maskerade
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'maskerade'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install maskerade
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
masker = ::Maskerade::CreditCardMasker.new(:replacement_token => "X", :expose_last => 4)
|
25
|
+
masker.mask("4111-1111-1111-1111") # "XXXX-XXXX-XXXX-1111"
|
26
|
+
```
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
masker = ::Maskerade::CreditCardMasker.new(:replacement_text => "[MASKED]")
|
30
|
+
masker.mask("4111-1111-1111-1111") # "[MASKED]"
|
31
|
+
```
|
32
|
+
|
33
|
+
## Notes
|
34
|
+
|
35
|
+
This gem works similar to the zendesk credit_card_sanitizer gem, but has the advantage of being able to work
|
36
|
+
even when the card number is preceded or followed by extra numbers:
|
37
|
+
* E.g., it works on "Starbucks Store #555 6011 0726 6818 0642"
|
38
|
+
* See https://github.com/zendesk/credit_card_sanitizer/issues/47
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "maskerade"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/maskerade.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "luhn_checksum"
|
2
|
+
|
3
|
+
# Masks all possible credit card numbers, which may be seperated by dashes or spaces.
|
4
|
+
# Some options are available to control how the card gets masked.
|
5
|
+
module Maskerade
|
6
|
+
class CreditCardMasker
|
7
|
+
attr_reader :replacement_token, :expose_last
|
8
|
+
|
9
|
+
COMPANY_CARD_REGEX = {
|
10
|
+
:visa => /\b4\d{3}[ -]?\d{4}[ -]?\d{4}[ -]?(?:\d|\d{4}|\d{7})\b/,
|
11
|
+
:amex => /\b3[47]\d{2}[ -]?\d{6}[ -]?\d{5}\b/,
|
12
|
+
:diners_club => /\b3(?:0[0-5]|[68]\d)\d[ -]?\d{6}[ -]?(?:\d{4}|\d{9})\b/,
|
13
|
+
:mastercard => /\b(?:5[1-5]\d{2}[ -]?\d{2}|6771[ -]?89|222[1-9][ -]?\d{2}|22[3-9]\d[ -]?\d{2}|2[3-6]\d{2}[ -]?\d{2}|27[01]\d[ -]?\d{2}|2720[ -]?\d{2})\d{2}[ -]?\d{4}[ -]?\d{4}\b/,
|
14
|
+
:discover => /\b(?:6011|65\d{2}|64[4-9]\d)[ -]?\d{4}[ -]?\d{4}[ -]?(?:\d{4}|\d{7})\b/,
|
15
|
+
:union_pay => /\b62\d{2}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/,
|
16
|
+
:jcb => /\b(?:308[89]|309[0-4]|309[6-9]|310[0-2]|311[2-9]|3120|315[8-9]|333[7-9]|334[0-9]|352[89]|35[3-8]\d)[ -]?\d{4}[ -]?\d{4}[ -]?(?:\d{4}|\d{7})\b/,
|
17
|
+
:switch_short_iin => /\b(?:4903|4905|4911|4936|6333|6759)[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}(?:\d{2,3})?\b/,
|
18
|
+
:switch_long_iin => /\b(?:5641[ -]?82|6331[ -]?10)\d{2}[ -]?\d{4}[ -]?\d{4}(?:\d{2,3})?\b/,
|
19
|
+
:solo => /\b(?:6334|6767)[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}(?:\d{2,3})?\b/,
|
20
|
+
:dankort => /\b5019[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/,
|
21
|
+
:maestro => /\b(?:5[06-8]|6\d)\d{2}[ -]?\d{4}[ -]?\d{4}[ -]?\d{0,7}\b$/,
|
22
|
+
:forbrugsforeningen => /\b6007[ -]?22\d{2}[ -]?\d{4}[ -]?\d{4}\b/,
|
23
|
+
:laser => /\b(?:6304|6706|6709|6771(?!89))[ -]?\d{4}[ -]?\d{4}[ -]?(?:\d{4}|\d{6,7})?\b/
|
24
|
+
}
|
25
|
+
|
26
|
+
ALL_CARDS_REGEX = ::Regexp.union(COMPANY_CARD_REGEX.values)
|
27
|
+
DIGIT_REGEX = /[[:digit:]]/
|
28
|
+
|
29
|
+
# Options:
|
30
|
+
# replacement_text: The entire card number gets replaced with this text; if set, the other two options are ignored.
|
31
|
+
# replacement_token: The character used to replace digits of the credit number. Defaults to "X".
|
32
|
+
# expose_last: The number of trailing digits of the credit card number to leave intact. Defaults to 0.
|
33
|
+
def initialize(replacement_text: nil, replacement_token: "X", expose_last: 0)
|
34
|
+
@replacement_text = replacement_text
|
35
|
+
@replacement_token = replacement_token
|
36
|
+
@expose_last = expose_last
|
37
|
+
end
|
38
|
+
|
39
|
+
def mask(value)
|
40
|
+
value&.gsub(ALL_CARDS_REGEX) do |match|
|
41
|
+
mask_one(match)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def mask_one(value)
|
48
|
+
digits = value.tr("^0-9", "")
|
49
|
+
return value unless ::LuhnChecksum.valid?(digits)
|
50
|
+
|
51
|
+
return @replacement_text if @replacement_text
|
52
|
+
|
53
|
+
value.gsub(DIGIT_REGEX).with_index do |number, index|
|
54
|
+
if index < digits.size - expose_last
|
55
|
+
replacement_token
|
56
|
+
else
|
57
|
+
number
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/maskerade.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "maskerade/version"
|
5
|
+
|
6
|
+
::Gem::Specification.new do |spec|
|
7
|
+
spec.name = "maskerade"
|
8
|
+
spec.version = ::Maskerade::VERSION
|
9
|
+
spec.authors = ["Phillip Hellewell"]
|
10
|
+
spec.email = ["sshock@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Credit card masker"
|
13
|
+
spec.description = "Credit card masker with support for major credit cards and luhn check"
|
14
|
+
spec.homepage = "https://github.com/mxenabled/maskerade"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "luhn_checksum", "0.1.1"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "mad_rubocop"
|
32
|
+
end
|
data/maskerade.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maskerade
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phillip Hellewell
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: luhn_checksum
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mad_rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Credit card masker with support for major credit cards and luhn check
|
84
|
+
email:
|
85
|
+
- sshock@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".ruby-gemset"
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/maskerade.rb
|
100
|
+
- lib/maskerade/credit_card_masker.rb
|
101
|
+
- lib/maskerade/version.rb
|
102
|
+
- maskerade.gemspec
|
103
|
+
- maskerade.png
|
104
|
+
homepage: https://github.com/mxenabled/maskerade
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubygems_version: 3.0.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Credit card masker
|
127
|
+
test_files: []
|