phc_string_format 0.3.4 → 0.3.5
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 +5 -5
- data/.rubocop.yml +2 -10
- data/.simplecov +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +12 -1
- data/README.md +4 -3
- data/lib/phc_string_format.rb +3 -2
- data/lib/phc_string_format/phc_string.rb +2 -20
- data/lib/phc_string_format/validations.rb +34 -0
- data/lib/phc_string_format/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bb2f0d0c00976c78f68dfc2ebdaa2fa87bbe930aecd1a97a29d41352f6f03bb2
|
4
|
+
data.tar.gz: 98d1aa8ababe727401fe90b8235f645598037c864d23fc67b9992c6adc3aeeb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d237ce6fc74598654b30c18b16688e15407d89e3df3d051282a77d4a8ab9be1d6f06da53927083dbf89cbdb238896004f2cbc20e83bbbd1b4206713dcfafb80b
|
7
|
+
data.tar.gz: 3c81d00427397be5fe6357e9478eda86864bb35388430a97d86e83839d92409bc29b72c0f1a2bd3524249e2b7591a014f4cdd995abb4c0bba3162009da115f26
|
data/.rubocop.yml
CHANGED
@@ -9,26 +9,18 @@ AllCops:
|
|
9
9
|
- '*.gemspec'
|
10
10
|
- Rakefile
|
11
11
|
|
12
|
-
Metrics/AbcSize:
|
13
|
-
Max: 20
|
14
|
-
|
15
12
|
Metrics/BlockLength:
|
16
13
|
Exclude:
|
17
14
|
- 'spec/**/*'
|
18
|
-
Metrics/ClassLength:
|
19
|
-
Max: 120
|
20
15
|
|
21
16
|
Metrics/CyclomaticComplexity:
|
22
|
-
Max:
|
17
|
+
Max: 7
|
23
18
|
|
24
19
|
Metrics/LineLength:
|
25
|
-
|
20
|
+
Max: 110
|
26
21
|
|
27
22
|
Metrics/MethodLength:
|
28
23
|
Max: 15
|
29
24
|
|
30
25
|
Metrics/ParameterLists:
|
31
26
|
Max: 6
|
32
|
-
|
33
|
-
Metrics/PerceivedComplexity:
|
34
|
-
Max: 10
|
data/.simplecov
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
phc_string_format (0.3.
|
4
|
+
phc_string_format (0.3.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -12,6 +12,8 @@ GEM
|
|
12
12
|
ice_nine (~> 0.11.0)
|
13
13
|
thread_safe (~> 0.3, >= 0.3.1)
|
14
14
|
byebug (10.0.2)
|
15
|
+
codacy-coverage (1.1.8)
|
16
|
+
simplecov
|
15
17
|
codeclimate-engine-rb (0.4.1)
|
16
18
|
virtus (~> 1.0)
|
17
19
|
coderay (1.1.2)
|
@@ -20,9 +22,11 @@ GEM
|
|
20
22
|
descendants_tracker (0.0.4)
|
21
23
|
thread_safe (~> 0.3, >= 0.3.1)
|
22
24
|
diff-lcs (1.3)
|
25
|
+
docile (1.3.1)
|
23
26
|
equalizer (0.0.11)
|
24
27
|
ice_nine (0.11.2)
|
25
28
|
jaro_winkler (1.5.1)
|
29
|
+
json (2.1.0)
|
26
30
|
kwalify (0.7.2)
|
27
31
|
method_source (0.9.0)
|
28
32
|
parallel (1.12.1)
|
@@ -64,6 +68,11 @@ GEM
|
|
64
68
|
ruby-progressbar (~> 1.7)
|
65
69
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
66
70
|
ruby-progressbar (1.9.0)
|
71
|
+
simplecov (0.16.1)
|
72
|
+
docile (~> 1.1)
|
73
|
+
json (>= 1.8, < 3)
|
74
|
+
simplecov-html (~> 0.10.0)
|
75
|
+
simplecov-html (0.10.2)
|
67
76
|
thread_safe (0.3.6)
|
68
77
|
unicode-display_width (1.4.0)
|
69
78
|
virtus (1.0.5)
|
@@ -77,12 +86,14 @@ PLATFORMS
|
|
77
86
|
|
78
87
|
DEPENDENCIES
|
79
88
|
bundler (~> 1.16)
|
89
|
+
codacy-coverage
|
80
90
|
phc_string_format!
|
81
91
|
pry-byebug (~> 3.6)
|
82
92
|
rake (~> 10.0)
|
83
93
|
reek (~> 5.0)
|
84
94
|
rspec (~> 3.0)
|
85
95
|
rubocop (~> 0.58.2)
|
96
|
+
simplecov
|
86
97
|
|
87
98
|
BUNDLED WITH
|
88
99
|
1.16.2
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[](https://travis-ci.org/naokikimura/phc_string_format)
|
5
5
|
[](https://snyk.io/test/github/naokikimura/phc_string_format?targetFile=Gemfile.lock)
|
6
6
|
[](https://app.codacy.com/app/naokikimura/phc_string_format?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/phc_string_format&utm_campaign=badger)
|
7
|
+
[](https://www.codacy.com/app/naokikimura/phc_string_format?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/phc_string_format&utm_campaign=Badge_Coverage)
|
7
8
|
|
8
9
|
PHC string format implemented by Ruby
|
9
10
|
|
@@ -31,13 +32,13 @@ require 'phc_string_format'
|
|
31
32
|
encrypted_password = '$argon2i$v=19$m=4096,t=3,p=1$IfH5R3O3r3501DfGnGr2rw$DfQ8Hv9R2eF2uBs1dR99IGjVjDl/rpkJIkaNyZ1g3pk'
|
32
33
|
|
33
34
|
# parse
|
34
|
-
|
35
|
+
phc_string_args = PhcStringFormat::Formatter.parse(encrypted_password)
|
35
36
|
# => {:id=>"argon2i", :version=>19, :params=>{"m"=>4096, "t"=>3, "p"=>1}, :salt=>"!\xF1\xF9Gs\xB7\xAF~t\xD47\xC6\x9Cj\xF6\xAF", :hash=>"\r\xF4<\x1E\xFFQ\xD9\xE1v\xB8\e5u\x1F} h\xD5\x8C9\x7F\xAE\x99\t\"F\x8D\xC9\x9D`\xDE\x99"}
|
36
37
|
|
37
38
|
# format
|
38
|
-
password_hash = PhcStringFormat::Formatter.format(
|
39
|
+
password_hash = PhcStringFormat::Formatter.format(phc_string_args)
|
39
40
|
|
40
|
-
password_hash ==
|
41
|
+
password_hash == encrypted_password
|
41
42
|
```
|
42
43
|
|
43
44
|
## Development
|
data/lib/phc_string_format.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'phc_string_format/b64'
|
2
|
-
require 'phc_string_format/formatter'
|
3
|
-
require 'phc_string_format/phc_string'
|
4
2
|
require 'phc_string_format/version'
|
3
|
+
require 'phc_string_format/validations'
|
4
|
+
require 'phc_string_format/phc_string'
|
5
|
+
require 'phc_string_format/formatter'
|
5
6
|
|
6
7
|
#
|
7
8
|
# PHC string format implemented by Ruby
|
@@ -3,25 +3,7 @@ module PhcStringFormat
|
|
3
3
|
# Parser for parsing PHC-string-format.
|
4
4
|
#
|
5
5
|
class PhcString
|
6
|
-
|
7
|
-
@validators ||= []
|
8
|
-
@validators << lambda { |object|
|
9
|
-
value = object.instance_variable_get(name)
|
10
|
-
return if options[:allow_nil] && !value
|
11
|
-
regex = options.dig(:format, :with)
|
12
|
-
raise ArgumentError, options[:message] unless !regex || value =~ regex
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.validate(name, **options)
|
17
|
-
@validators ||= []
|
18
|
-
@validators << ->(object) { raise ArgumentError, options[:message] unless object.send(name) }
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.do_validate(that)
|
22
|
-
@validators.each { |validator| validator.call(that) }
|
23
|
-
that
|
24
|
-
end
|
6
|
+
include Validations
|
25
7
|
|
26
8
|
def self.parse(string)
|
27
9
|
string ||= ''
|
@@ -53,7 +35,7 @@ module PhcStringFormat
|
|
53
35
|
)
|
54
36
|
end
|
55
37
|
|
56
|
-
private_class_method :
|
38
|
+
private_class_method :split
|
57
39
|
|
58
40
|
validates :@id, message: 'id is non-compliant', format: { with: /\A[a-z0-9-]{1,32}\z/ }
|
59
41
|
validates \
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PhcStringFormat
|
2
|
+
#
|
3
|
+
# Provides a validation framework to your objects.
|
4
|
+
#
|
5
|
+
module Validations
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend ClassMethods
|
8
|
+
end
|
9
|
+
#
|
10
|
+
# class methods
|
11
|
+
#
|
12
|
+
module ClassMethods
|
13
|
+
def validates(name, **options)
|
14
|
+
@validators ||= []
|
15
|
+
@validators << lambda { |object|
|
16
|
+
value = object.instance_variable_get(name)
|
17
|
+
return if options[:allow_nil] && !value
|
18
|
+
regex = options.dig(:format, :with)
|
19
|
+
raise ArgumentError, options[:message] unless !regex || value =~ regex
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate(name, **options)
|
24
|
+
@validators ||= []
|
25
|
+
@validators << ->(object) { raise ArgumentError, options[:message] unless object.send(name) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def do_validate(that)
|
29
|
+
@validators.each { |validator| validator.call(that) }
|
30
|
+
that
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phc_string_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- naokikimura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".reek.yml"
|
78
78
|
- ".rspec"
|
79
79
|
- ".rubocop.yml"
|
80
|
+
- ".simplecov"
|
80
81
|
- ".travis.yml"
|
81
82
|
- CODE_OF_CONDUCT.md
|
82
83
|
- Gemfile
|
@@ -90,6 +91,7 @@ files:
|
|
90
91
|
- lib/phc_string_format/b64.rb
|
91
92
|
- lib/phc_string_format/formatter.rb
|
92
93
|
- lib/phc_string_format/phc_string.rb
|
94
|
+
- lib/phc_string_format/validations.rb
|
93
95
|
- lib/phc_string_format/version.rb
|
94
96
|
- phc_string_format.gemspec
|
95
97
|
homepage: https://github.com/naokikimura/phc_string_format
|
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
116
|
version: '0'
|
115
117
|
requirements: []
|
116
118
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.7.6
|
118
120
|
signing_key:
|
119
121
|
specification_version: 4
|
120
122
|
summary: PHC string format implemented by Ruby.
|