rotp 3.0.1 → 3.1.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: 8a81c9c19f20358ab16d62429767d58a02713f0a
4
- data.tar.gz: 33806577d34a4da96b99424a5feb9a16f229657f
3
+ metadata.gz: c450bbb03ba621504bffd4d10d86beb9aa0df214
4
+ data.tar.gz: 13a046cf63204bea4517283ae0a2473becc67ceb
5
5
  SHA512:
6
- metadata.gz: 61867eea08079d4478b0394209a6a076c1a1c518ac0365735ec71bacc3aa8b716f88bb591af19f8c5566122764ca581f3ce7dd041b53299a170edb7275621caf
7
- data.tar.gz: c980bbb7d215597f050cf7318493fdf43dba6027771f9c233330b08b4e1909352d10456078c4738f8a321245e6e7a02d63cf38cd0b3a95c409a19cde7a96569c
6
+ metadata.gz: d76a02cc91e2de40619a99a925c3452546c31914fc0172918c40a68f405975b6ee293f437d91d49004b1e4074607f9f7abf8b266345ced389e9e313d6f0ab030
7
+ data.tar.gz: 08e82ddf0a585ee225a9d98b04cf0a22c7a386504f8f3db3936c07dc6231ecafa3f8f920fd9048b4606cb14080a194f7a4c333311735696d9016a88975d0c5b1
@@ -1,5 +1,9 @@
1
1
  ### Changelog
2
2
 
3
+ #### 3.1.0
4
+
5
+ - Add Add digits paramater to provisioning URI. #54 from @sbc100
6
+
3
7
  #### 3.0.1
4
8
 
5
9
  - Use SecureRandom. See mdp/rotp/pull/52
@@ -38,7 +38,12 @@ module ROTP
38
38
  # @param [Integer] initial_count starting counter value, defaults to 0
39
39
  # @return [String] provisioning uri
40
40
  def provisioning_uri(name, initial_count=0)
41
- encode_params("otpauth://hotp/#{URI.encode(name)}", :secret=>secret, :counter=>initial_count)
41
+ params = {
42
+ secret: secret,
43
+ counter: initial_count,
44
+ digits: digits == DEFAULT_DIGITS ? nil : digits
45
+ }
46
+ encode_params("otpauth://hotp/#{URI.encode(name)}", params)
42
47
  end
43
48
 
44
49
  end
@@ -1,6 +1,7 @@
1
1
  module ROTP
2
2
  class OTP
3
3
  attr_reader :secret, :digits, :digest
4
+ DEFAULT_DIGITS = 6
4
5
 
5
6
  # @param [String] secret in the form of base32
6
7
  # @option options digits [Integer] (6)
@@ -11,7 +12,7 @@ module ROTP
11
12
  # Google Authenticate only supports 'sha1' currently
12
13
  # @returns [OTP] OTP instantiation
13
14
  def initialize(s, options = {})
14
- @digits = options[:digits] || 6
15
+ @digits = options[:digits] || DEFAULT_DIGITS
15
16
  @digest = options[:digest] || "sha1"
16
17
  @secret = s
17
18
  end
@@ -58,8 +58,13 @@ module ROTP
58
58
  # For compatibility the issuer appears both before that account name and also in the
59
59
  # query string.
60
60
  issuer_string = issuer.nil? ? "" : "#{URI.encode(issuer)}:"
61
- encode_params("otpauth://totp/#{issuer_string}#{URI.encode(name)}",
62
- :secret => secret, :period => (interval==30 ? nil : interval), :issuer => issuer)
61
+ params = {
62
+ secret: secret,
63
+ period: interval == 30 ? nil : interval,
64
+ issuer: issuer,
65
+ digits: digits == DEFAULT_DIGITS ? nil : digits,
66
+ }
67
+ encode_params("otpauth://totp/#{issuer_string}#{URI.encode(name)}", params)
63
68
  end
64
69
 
65
70
  private
@@ -1,3 +1,3 @@
1
1
  module ROTP
2
- VERSION = "3.0.1"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -82,6 +82,20 @@ RSpec.describe ROTP::HOTP do
82
82
  it 'includes the secret as parameter' do
83
83
  expect(params['secret'].first).to eq 'a' * 32
84
84
  end
85
+
86
+ context 'with default digits' do
87
+ it 'does not include digits parameter with default digits' do
88
+ expect(params['digits'].first).to be_nil
89
+ end
90
+ end
91
+
92
+ context 'with non-default digits' do
93
+ let(:hotp) { ROTP::HOTP.new('a' * 32, digits: 8) }
94
+
95
+ it 'includes digits parameter' do
96
+ expect(params['digits'].first).to eq '8'
97
+ end
98
+ end
85
99
  end
86
100
 
87
101
  describe '#verify_with_retries' do
@@ -97,6 +97,20 @@ RSpec.describe ROTP::TOTP do
97
97
  end
98
98
  end
99
99
 
100
+ context 'with default digits' do
101
+ it 'does does not include digits parameter' do
102
+ expect(params['digits'].first).to be_nil
103
+ end
104
+ end
105
+
106
+ context 'with non-default digits' do
107
+ let(:totp) { ROTP::TOTP.new 'JBSWY3DPEHPK3PXP', digits: 8 }
108
+
109
+ it 'does does not include digits parameter' do
110
+ expect(params['digits'].first).to eq '8'
111
+ end
112
+ end
113
+
100
114
  context 'with issuer' do
101
115
  let(:totp) { ROTP::TOTP.new 'JBSWY3DPEHPK3PXP', issuer: 'FooCo' }
102
116
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotp
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Percival
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-21 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard-rspec