phc_string_format 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/phc_string_format.rb +5 -3
- data/lib/phc_string_format/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd51561f2a2662deee047aeec5ac9f7eaffdf0b5
|
4
|
+
data.tar.gz: c71044ae647c76af59cd9472431eb702ecb3f74d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56778712f628f749027aa1143cc77e6e4d0c313335b628fa9ff0f0c0e27d696cb700ad5ae56c9ed2189580eac883ebd2737cde9dc4bcf985753637646f4c8284
|
7
|
+
data.tar.gz: 02f01c1c68610a692bc86c5ac1f0d645bb71cf27bd462285ce96b6915a9a23288ad097b297c9b7c829562352e81440a85ffb0e7d0380749608e1fb29d46c3c69
|
data/Gemfile.lock
CHANGED
data/lib/phc_string_format.rb
CHANGED
@@ -10,12 +10,13 @@ require "base64"
|
|
10
10
|
#
|
11
11
|
module PhcStringFormat
|
12
12
|
module Formatter
|
13
|
-
def self.format(id:, params: {}, salt: '', hash: '', hint: {salt: {encoding: 'base64'}})
|
13
|
+
def self.format(id:, version: nil, params: {}, salt: '', hash: '', hint: {salt: {encoding: 'base64'}})
|
14
14
|
raise ArgumentError.new, 'id is required' if id.nil?
|
15
15
|
raise ArgumentError.new, 'hash needs salt' if (salt.nil? || salt.empty?) && !(hash.nil? || hash.empty?)
|
16
16
|
|
17
17
|
elements = [
|
18
18
|
id,
|
19
|
+
("v=#{version}" if version),
|
19
20
|
(params.map{|e| e.join '='}.join(',') if params),
|
20
21
|
hint.dig(:salt, :encoding) == '7bit' ? salt : short_strict_encode64(salt),
|
21
22
|
short_strict_encode64(hash)
|
@@ -24,13 +25,14 @@ module PhcStringFormat
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.parse(string, hint: {salt: {encoding: 'base64'}})
|
27
|
-
elements = string.split(/\$/,
|
28
|
+
elements = string.split(/\$/, 6)
|
28
29
|
elements.shift
|
29
30
|
id = elements.shift
|
31
|
+
version = parse_parameter_string(elements.shift)['v'] if (elements.first || '').start_with?('v=')
|
30
32
|
params = parse_parameter_string(elements.shift) if (elements.first || '').include?('=')
|
31
33
|
salt = hint.dig(:salt, :encoding) == '7bit' ? elements.shift : short_strict_decode64(elements.shift)
|
32
34
|
hash = short_strict_decode64(elements.shift)
|
33
|
-
{id: id, params: params, salt: salt, hash: hash}.select {|_,v| v}
|
35
|
+
{id: id, version: version, params: params, salt: salt, hash: hash}.select {|_,v| v}
|
34
36
|
end
|
35
37
|
|
36
38
|
def self.parse_parameter_string(string)
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- naokikimura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.5.2.3
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: PHC string format implemented by Ruby.
|