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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 387297ecdd03a3f1a103a1c852be5a2ecd07abc3
4
- data.tar.gz: 83a0e1784b853a92de75aa9c75829b5999409cab
3
+ metadata.gz: fd51561f2a2662deee047aeec5ac9f7eaffdf0b5
4
+ data.tar.gz: c71044ae647c76af59cd9472431eb702ecb3f74d
5
5
  SHA512:
6
- metadata.gz: e2d21cde31f35746242a8eaf48bd996b01adc3aa24698133cbf82f1104dbbf6aa304d125d1e767662d7498c2ead5ea8a5e75ae704e93a489a91779fadf958189
7
- data.tar.gz: 46daddb661e5f9b879cdfd2e8487fbd570b20a3aa88165cabe4c205ea6557e6819db0bbc98d46a7dc9e3df0a6c41b08c13d7ba3efee4c369f43af837abd3d625
6
+ metadata.gz: 56778712f628f749027aa1143cc77e6e4d0c313335b628fa9ff0f0c0e27d696cb700ad5ae56c9ed2189580eac883ebd2737cde9dc4bcf985753637646f4c8284
7
+ data.tar.gz: 02f01c1c68610a692bc86c5ac1f0d645bb71cf27bd462285ce96b6915a9a23288ad097b297c9b7c829562352e81440a85ffb0e7d0380749608e1fb29d46c3c69
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phc_string_format (0.1.4)
4
+ phc_string_format (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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(/\$/, 5)
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)
@@ -1,3 +1,3 @@
1
1
  module PhcStringFormat
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  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.1.4
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-06-28 00:00:00.000000000 Z
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.6.11
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.