otp 0.0.8 → 0.0.9
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/.rubocop.yml +49 -0
- data/Gemfile +3 -0
- data/lib/otp/base.rb +2 -2
- data/lib/otp/base32.rb +6 -7
- data/lib/otp/uri.rb +3 -4
- data/lib/otp/version.rb +1 -2
- data/test/helper.rb +8 -0
- data/test/test_base.rb +25 -0
- data/test/test_base32.rb +1 -2
- data/test/test_hotp.rb +1 -2
- data/test/test_totp.rb +8 -2
- data/test/test_uri.rb +23 -2
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032b0bd99d66d97d8281cd5006409b1f482c2314
|
4
|
+
data.tar.gz: ca0320a12fe5d73c907e8cd445dac6fd0219112f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f60da46723a92855571fcabbf0b8e0ad264093822516ebdd9d152181cb102280c92a3ce97a499b9bf661aac9adf6ff2694e2ae02294eb39d2e6d1be70d3eb8ed
|
7
|
+
data.tar.gz: 8d90aba69fd87db84b94a3b0a374f817a8566d970be4820e868f16a1098b81e8de188247bc9b29c4f811a0e4779bb1c8cc43907aef5fc1b4fd974a7fd68e28bb
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude: []
|
3
|
+
RunRailsCops: false
|
4
|
+
DisplayCopNames: true
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/GuardClause:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/TrailingComma:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/SpaceAroundOperators:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/SpaceBeforeBlockBraces:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/SpaceInsideHashLiteralBraces:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/SpaceInsideBlockBraces:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/RedundantReturn:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/SignalException:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/FormatString:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Style/EachWithObject:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Metrics/AbcSize:
|
43
|
+
Max: 20
|
44
|
+
|
45
|
+
Metrics/MethodLength:
|
46
|
+
Max: 30
|
47
|
+
|
48
|
+
Style/IfUnlessModifier:
|
49
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/lib/otp/base.rb
CHANGED
@@ -42,8 +42,8 @@ module OTP
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def verify(given_pw, last:0, post:0)
|
45
|
-
raise "last must be greater than or equal to 0" if last < 0
|
46
|
-
raise "post must be greater than or equal to 0" if post < 0
|
45
|
+
raise ArgumentError, "last must be greater than or equal to 0" if last < 0
|
46
|
+
raise ArgumentError, "post must be greater than or equal to 0" if post < 0
|
47
47
|
return false if given_pw.nil? || given_pw.empty?
|
48
48
|
return (-last..post).any?{|i| compare(password(i), given_pw) }
|
49
49
|
end
|
data/lib/otp/base32.rb
CHANGED
@@ -6,11 +6,11 @@ module OTP
|
|
6
6
|
)
|
7
7
|
|
8
8
|
DECODE_MAP = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
"A"=>0, "B"=>1, "C"=>2, "D"=>3, "E"=>4, "F"=>5, "G"=>6, "H"=>7,
|
10
|
+
"I"=>8, "J"=>9, "K"=>10, "L"=>11, "M"=>12, "N"=>13, "O"=>14, "P"=>15,
|
11
|
+
"Q"=>16, "R"=>17, "S"=>18, "T"=>19, "U"=>20, "V"=>21, "W"=>22, "X"=>23,
|
12
|
+
"Y"=>24, "Z"=>25, "2"=>26, "3"=>27, "4"=>28, "5"=>29, "6"=>30, "7"=>31,
|
13
|
+
"="=>-1,
|
14
14
|
}
|
15
15
|
|
16
16
|
DECODE_LENGTH = {
|
@@ -28,7 +28,7 @@ module OTP
|
|
28
28
|
|
29
29
|
def encode(bytes, padding: true)
|
30
30
|
return nil unless bytes
|
31
|
-
pad = padding ?
|
31
|
+
pad = padding ? "=" : ""
|
32
32
|
ret = ""
|
33
33
|
bytes = bytes.dup.force_encoding("binary")
|
34
34
|
off = 0
|
@@ -68,7 +68,6 @@ module OTP
|
|
68
68
|
else
|
69
69
|
n <<= 5
|
70
70
|
n |= d
|
71
|
-
l = ((i+1) * 5.0 / 8.0).floor
|
72
71
|
l = DECODE_LENGTH[i+1]
|
73
72
|
end
|
74
73
|
end
|
data/lib/otp/uri.rb
CHANGED
@@ -10,10 +10,9 @@ module OTP
|
|
10
10
|
uri = ::URI.parse(uri_string)
|
11
11
|
raise "URI scheme not match: #{uri.scheme}" unless uri.scheme != SCHEME
|
12
12
|
otp = otp_class(uri).new
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
m = %r{/(?:([^:]*): *)?(.+)}.match(::URI.decode(uri.path))
|
14
|
+
otp.issuer = m[1] if m[1]
|
15
|
+
otp.accountname = m[2]
|
17
16
|
query = Hash[::URI.decode_www_form(uri.query)]
|
18
17
|
otp.secret = query["secret"]
|
19
18
|
if value = query["algorithm"]
|
data/lib/otp/version.rb
CHANGED
data/test/helper.rb
ADDED
data/test/test_base.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class TestBase < Test::Unit::TestCase
|
4
|
+
def test_base
|
5
|
+
otp = OTP::Base.new
|
6
|
+
otp.new_secret(20)
|
7
|
+
assert_equal(32, otp.secret.length)
|
8
|
+
otp.new_secret(40)
|
9
|
+
assert_equal(64, otp.secret.length)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_methods_expected_to_be_override
|
13
|
+
base = OTP::Base.new
|
14
|
+
totp = OTP::TOTP.new
|
15
|
+
|
16
|
+
[
|
17
|
+
[:moving_factor, ],
|
18
|
+
[:type_specific_uri_params, ],
|
19
|
+
[:extract_type_specific_uri_params, {}],
|
20
|
+
].each do |m, *args|
|
21
|
+
assert_raise(NotImplementedError){ base.send(m, *args) }
|
22
|
+
assert_nothing_raised{ totp.send(m, *args) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/test_base32.rb
CHANGED
data/test/test_hotp.rb
CHANGED
data/test/test_totp.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require "otp"
|
1
|
+
require_relative "helper"
|
3
2
|
|
4
3
|
class TestTOTP < Test::Unit::TestCase
|
5
4
|
def assert_totp(totp, time, pass)
|
@@ -71,4 +70,11 @@ class TestTOTP < Test::Unit::TestCase
|
|
71
70
|
assert(totp.verify("78660635", last:2, post:2))
|
72
71
|
assert(!totp.verify("97845627", last:2, post:2))
|
73
72
|
end
|
73
|
+
|
74
|
+
def test_error
|
75
|
+
seed = "12345678901234567890"
|
76
|
+
totp = OTP::TOTP.new(OTP::Base32.encode(seed), "SHA1", 8)
|
77
|
+
assert_raise(ArgumentError){ assert(totp.verify("50451956", last:-2)) }
|
78
|
+
assert_raise(ArgumentError){ assert(totp.verify("50451956", post:-2)) }
|
79
|
+
end
|
74
80
|
end
|
data/test/test_uri.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
|
-
|
2
|
-
require "otp"
|
1
|
+
require_relative "helper"
|
3
2
|
|
4
3
|
class TestURI < Test::Unit::TestCase
|
4
|
+
def test_parse
|
5
|
+
uri = "otpauth://totp/account@example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
|
6
|
+
otp = OTP::URI.parse(uri)
|
7
|
+
assert_equal("account@example.com", otp.accountname)
|
8
|
+
assert_equal(nil, otp.issuer)
|
9
|
+
|
10
|
+
uri = "otpauth://totp/My%20Company:%20%20account@example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
|
11
|
+
otp = OTP::URI.parse(uri)
|
12
|
+
assert_equal("account@example.com", otp.accountname)
|
13
|
+
assert_equal("My Company", otp.issuer)
|
14
|
+
|
15
|
+
uri = "otpauth://totp/My%20Company:%20%20account@example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
|
16
|
+
otp = OTP::URI.parse(uri)
|
17
|
+
assert_equal("account@example.com", otp.accountname)
|
18
|
+
assert_equal("My Company", otp.issuer)
|
19
|
+
end
|
20
|
+
|
5
21
|
def test_totp
|
6
22
|
secret = OTP::Base32.encode("12345678901234567890")
|
7
23
|
totp = OTP::TOTP.new
|
@@ -46,4 +62,9 @@ class TestURI < Test::Unit::TestCase
|
|
46
62
|
assert_equal("My Company", otp.issuer)
|
47
63
|
assert_equal(otp.password, hotp.password)
|
48
64
|
end
|
65
|
+
|
66
|
+
def test_parse_invalid
|
67
|
+
assert_raise(RuntimeError){ OTP::URI.parse("http://www.netlab.jp") }
|
68
|
+
assert_raise(RuntimeError){ OTP::URI.parse("otpauth://foo") }
|
69
|
+
end
|
49
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: otp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuuzou Gotou
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
+
- ".rubocop.yml"
|
49
50
|
- ".travis.yml"
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
@@ -60,6 +61,8 @@ files:
|
|
60
61
|
- lib/otp/utils.rb
|
61
62
|
- lib/otp/version.rb
|
62
63
|
- otp.gemspec
|
64
|
+
- test/helper.rb
|
65
|
+
- test/test_base.rb
|
63
66
|
- test/test_base32.rb
|
64
67
|
- test/test_hotp.rb
|
65
68
|
- test/test_totp.rb
|
@@ -89,6 +92,8 @@ signing_key:
|
|
89
92
|
specification_version: 4
|
90
93
|
summary: One-Time Password Library
|
91
94
|
test_files:
|
95
|
+
- test/helper.rb
|
96
|
+
- test/test_base.rb
|
92
97
|
- test/test_base32.rb
|
93
98
|
- test/test_hotp.rb
|
94
99
|
- test/test_totp.rb
|