class Rack::Auth::Digest::Nonce

Rack::Auth::Digest::Nonce is the default nonce generator for the Rack::Auth::Digest::MD5 authentication handler.

private_key needs to set to a constant string.

time_limit can be optionally set to an integer (number of seconds), to limit the validity of the generated nonces.

Attributes

Public Class Methods

# File lib/rack/auth/digest.rb, line 31
def initialize(timestamp = Time.now, given_digest = nil)
  @timestamp, @given_digest = timestamp.to_i, given_digest
end
# File lib/rack/auth/digest.rb, line 27
def self.parse(string)
  new(*Base64.decode64(string).split(' ', 2))
end

Public Instance Methods

# File lib/rack/auth/digest.rb, line 39
def digest
  ::Digest::MD5.hexdigest("#{@timestamp}:#{self.class.private_key}")
end
# File lib/rack/auth/digest.rb, line 51
def fresh?
  !stale?
end
# File lib/rack/auth/digest.rb, line 47
def stale?
  !self.class.time_limit.nil? && (Time.now.to_i - @timestamp) > self.class.time_limit
end
# File lib/rack/auth/digest.rb, line 35
def to_s
  Base64.encode64("#{@timestamp} #{digest}").strip
end
# File lib/rack/auth/digest.rb, line 43
def valid?
  digest == @given_digest
end