6 # Rack::Auth::Digest::Nonce is the default nonce generator for the
7 # Rack::Auth::Digest::MD5 authentication handler.
9 # +private_key+ needs to set to a constant string.
11 # +time_limit+ can be optionally set to an integer (number of seconds),
12 # to limit the validity of the generated nonces.
17 attr_accessor
:private_key, :time_limit
20 def self.parse(string
)
21 new(*string
.unpack("m*").first
.split(' ', 2))
24 def initialize(timestamp
= Time
.now
, given_digest
= nil)
25 @timestamp, @given_digest = timestamp
.to_i
, given_digest
29 [([ @timestamp, digest
] * ' ')].pack("m*").strip
33 ::Digest::MD5.hexdigest([ @timestamp, self.class.private_key
] * ':')
37 digest
== @given_digest
41 !self.class.time_limit
.nil? && (@timestamp - Time
.now
.to_i
) < self.class.time_limit