rotp 3.0.1 → 3.1.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/rotp/hotp.rb +6 -1
- data/lib/rotp/otp.rb +2 -1
- data/lib/rotp/totp.rb +7 -2
- data/lib/rotp/version.rb +1 -1
- data/spec/lib/rotp/hotp_spec.rb +14 -0
- data/spec/lib/rotp/totp_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c450bbb03ba621504bffd4d10d86beb9aa0df214
|
4
|
+
data.tar.gz: 13a046cf63204bea4517283ae0a2473becc67ceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d76a02cc91e2de40619a99a925c3452546c31914fc0172918c40a68f405975b6ee293f437d91d49004b1e4074607f9f7abf8b266345ced389e9e313d6f0ab030
|
7
|
+
data.tar.gz: 08e82ddf0a585ee225a9d98b04cf0a22c7a386504f8f3db3936c07dc6231ecafa3f8f920fd9048b4606cb14080a194f7a4c333311735696d9016a88975d0c5b1
|
data/CHANGELOG.md
CHANGED
data/lib/rotp/hotp.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/rotp/otp.rb
CHANGED
@@ -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] ||
|
15
|
+
@digits = options[:digits] || DEFAULT_DIGITS
|
15
16
|
@digest = options[:digest] || "sha1"
|
16
17
|
@secret = s
|
17
18
|
end
|
data/lib/rotp/totp.rb
CHANGED
@@ -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
|
-
|
62
|
-
|
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
|
data/lib/rotp/version.rb
CHANGED
data/spec/lib/rotp/hotp_spec.rb
CHANGED
@@ -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
|
data/spec/lib/rotp/totp_spec.rb
CHANGED
@@ -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
|
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-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard-rspec
|