rotp 1.0.0 → 1.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.
@@ -3,28 +3,43 @@ module ROTP
3
3
 
4
4
  attr_reader :interval
5
5
 
6
+ # @option options [Integer] interval (30) the time interval in seconds for OTP
7
+ # This defaults to 30 which is standard.
6
8
  def initialize(s, options = {})
7
9
  @interval = options[:interval] || 30
8
10
  super
9
11
  end
10
12
 
13
+ # Accepts either a Unix timestamp integer or a Time object.
14
+ # Time objects will be adjusted to UTC automatically
15
+ # @param [Time/Integer] time the time to generate an OTP for
11
16
  def at(time)
12
17
  unless time.class == Time
13
18
  time = Time.at(time.to_i)
14
19
  end
15
- generate_otp(timehash(time))
20
+ generate_otp(timecode(time))
16
21
  end
17
22
 
23
+ # Generate the current time OTP
24
+ # @return [Integer] the OTP as an integer
18
25
  def now
19
- generate_otp(timehash(Time.now))
26
+ generate_otp(timecode(Time.now))
27
+ end
28
+
29
+ # Returns the provisioning URI for the OTP
30
+ # This can then be encoded in a QR Code and used
31
+ # to provision the Google Authenticator app
32
+ # @param [String] name of the account
33
+ # @return [String] provisioning uri
34
+ def provisioning_uri(name)
35
+ "otpauth://totp/#{URI.encode(name)}?secret=#{secret}"
20
36
  end
21
37
 
22
38
  private
23
39
 
24
- def timehash(time)
40
+ def timecode(time)
25
41
  i = time.utc.to_i * 1000
26
- i = i / (interval * 1000)
27
- i
42
+ i / (interval * 1000)
28
43
  end
29
44
 
30
45
  end
@@ -1,3 +1,3 @@
1
- module Rotp
2
- VERSION = "1.0.0"
1
+ module ROTP
2
+ VERSION = "1.1.0"
3
3
  end
@@ -4,11 +4,11 @@ require "rotp/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "rotp"
7
- s.version = Rotp::VERSION
7
+ s.version = ROTP::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Mark Percival"]
10
10
  s.email = ["mark@markpercival.us"]
11
- s.homepage = ""
11
+ s.homepage = "http://github.com/mdp/rotp"
12
12
  s.summary = %q{A Ruby library for generating and verifying one time passwords}
13
13
  s.description = %q{Works for both HOTP and TOTP, and include QR Code provisioning}
14
14
 
@@ -1,5 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe "generating a random base32 secret" do
4
+ it "should be 16 characters by default" do
5
+ ROTP.random_base32.length.should == 16
6
+ ROTP.random_base32.should match /[a-z2-7].+/
7
+ end
8
+ it "should be allow a specific length" do
9
+ ROTP.random_base32(32).length.should == 32
10
+ end
11
+ end
12
+
3
13
  describe "HOTP example values from the rfc" do
4
14
  it "should match the RFC" do
5
15
  # 12345678901234567890 in Bas32
@@ -16,6 +26,10 @@ describe "HOTP example values from the rfc" do
16
26
  hotp.at(8).should ==(399871)
17
27
  hotp.at(9).should ==(520489)
18
28
  end
29
+ it "should output its provisioning URI" do
30
+ hotp = ROTP::HOTP.new("wrn3pqx5uqxqvnqr")
31
+ hotp.provisioning_uri('mark@percival').should == "otpauth://hotp/mark@percival?secret=wrn3pqx5uqxqvnqr&counter=0"
32
+ end
19
33
  end
20
34
 
21
35
  describe "TOTP example values from the rfc" do
@@ -32,4 +46,9 @@ describe "TOTP example values from the rfc" do
32
46
  totp.now.should ==(102705)
33
47
  end
34
48
  end
49
+
50
+ it "should output its provisioning URI" do
51
+ totp = ROTP::TOTP.new("wrn3pqx5uqxqvnqr")
52
+ totp.provisioning_uri('mark@percival').should == "otpauth://totp/mark@percival?secret=wrn3pqx5uqxqvnqr"
53
+ end
35
54
  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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
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: 2011-02-12 00:00:00 -08:00
18
+ date: 2011-02-13 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,8 +45,28 @@ extra_rdoc_files: []
45
45
 
46
46
  files:
47
47
  - .gitignore
48
+ - .rspec
48
49
  - Gemfile
50
+ - README.markdown
49
51
  - Rakefile
52
+ - doc/ROTP/HOTP.html
53
+ - doc/ROTP/OTP.html
54
+ - doc/ROTP/TOTP.html
55
+ - doc/Rotp.html
56
+ - doc/_index.html
57
+ - doc/class_list.html
58
+ - doc/css/common.css
59
+ - doc/css/full_list.css
60
+ - doc/css/style.css
61
+ - doc/file.README.html
62
+ - doc/file_list.html
63
+ - doc/frames.html
64
+ - doc/index.html
65
+ - doc/js/app.js
66
+ - doc/js/full_list.js
67
+ - doc/js/jquery.js
68
+ - doc/method_list.html
69
+ - doc/top-level-namespace.html
50
70
  - lib/rotp.rb
51
71
  - lib/rotp/hotp.rb
52
72
  - lib/rotp/otp.rb
@@ -56,7 +76,7 @@ files:
56
76
  - spec/base_spec.rb
57
77
  - spec/spec_helper.rb
58
78
  has_rdoc: true
59
- homepage: ""
79
+ homepage: http://github.com/mdp/rotp
60
80
  licenses: []
61
81
 
62
82
  post_install_message: