rotp 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,8 +38,10 @@ module ROTP
38
38
  # @param [Integer] drift the number of seconds that the client
39
39
  # and server are allowed to drift apart
40
40
  def verify_with_drift(otp, drift, time = Time.now)
41
- drift_intervals = drift / interval
42
- (-drift_intervals..drift_intervals).any? { |n| verify(otp, time + n * interval) }
41
+ time = time.to_i
42
+ times = (time-drift..time+drift).step(interval).to_a
43
+ times << time + drift if times.last < time + drift
44
+ times.any? { |ti| verify(otp, ti) }
43
45
  end
44
46
 
45
47
  # Returns the provisioning URI for the OTP
@@ -1,3 +1,3 @@
1
1
  module ROTP
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -26,10 +26,18 @@ describe ROTP::TOTP do
26
26
  subject.verify_with_drift(subject.at(@now - 30), 60, @now).should be_true
27
27
  end
28
28
  it "should verify a slightly new number" do
29
- subject.verify_with_drift(subject.at(@now - 60), 60, @now).should be_true
29
+ subject.verify_with_drift(subject.at(@now + 60), 60, @now).should be_true
30
30
  end
31
31
  it "should reject a number that is outside the allowed drift" do
32
32
  subject.verify_with_drift(subject.at(@now - 60), 30, @now).should be_false
33
33
  end
34
+ context "with drift that is not a multiple of the TOTP interval" do
35
+ it "should verify a slightly old number" do
36
+ subject.verify_with_drift(subject.at(@now - 45), 45, @now).should be_true
37
+ end
38
+ it "should verify a slightly new number" do
39
+ subject.verify_with_drift(subject.at(@now + 40), 40, @now).should be_true
40
+ end
41
+ end
34
42
  end
35
43
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 0
10
- version: 1.4.0
9
+ - 1
10
+ version: 1.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mark Percival
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-20 00:00:00 Z
18
+ date: 2012-05-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec