# 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

private_key[RW]
time_limit[RW]

### Public Class Methods

new(timestamp = Time.now, given_digest = nil) click to toggle source

    # File lib/rack/auth/digest/nonce.rb, line 26
    def initialize(timestamp = Time.now, given_digest = nil)
      @timestamp, @given_digest = timestamp.to_i, given_digest
    end

parse(string) click to toggle source

    # File lib/rack/auth/digest/nonce.rb, line 22
    def self.parse(string)
      new(*string.unpack("m").first.split(' ', 2))
    end

### Public Instance Methods

digest() click to toggle source

    # File lib/rack/auth/digest/nonce.rb, line 34
    def digest
      ::Digest::MD5.hexdigest("#{@timestamp}:#{self.class.private_key}")
    end

fresh?() click to toggle source

    # File lib/rack/auth/digest/nonce.rb, line 46
    def fresh?
      !stale?
    end

stale?() click to toggle source

    # File lib/rack/auth/digest/nonce.rb, line 42
    def stale?
      !self.class.time_limit.nil? && (Time.now.to_i - @timestamp) > self.class.time_limit
    end

to_s() click to toggle source

    # File lib/rack/auth/digest/nonce.rb, line 30
    def to_s
      ["#{@timestamp} #{digest}"].pack("m").strip
    end

valid?() click to toggle source

    # File lib/rack/auth/digest/nonce.rb, line 38
    def valid?
      digest == @given_digest
    end