Class: Rack::Auth::Digest::Nonce
- Inherits:
 - 
      Object
      
        
- Object
 - Rack::Auth::Digest::Nonce
 
 
- Defined in:
 - lib/rack/auth/digest/nonce.rb
 
Overview
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.
Class Attribute Summary collapse
- 
  
    
      .private_key  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute private_key.
 - 
  
    
      .time_limit  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute time_limit.
 
Class Method Summary collapse
Instance Method Summary collapse
- #digest ⇒ Object
 - #fresh? ⇒ Boolean
 - 
  
    
      #initialize(timestamp = Time.now, given_digest = nil)  ⇒ Nonce 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Nonce.
 - #stale? ⇒ Boolean
 - #to_s ⇒ Object
 - #valid? ⇒ Boolean
 
Constructor Details
#initialize(timestamp = Time.now, given_digest = nil) ⇒ Nonce
Returns a new instance of Nonce.
      27 28 29  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 27 def initialize( = Time.now, given_digest = nil) @timestamp, @given_digest = .to_i, given_digest end  | 
  
Class Attribute Details
.private_key ⇒ Object
Returns the value of attribute private_key.
      20 21 22  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 20 def private_key @private_key end  | 
  
.time_limit ⇒ Object
Returns the value of attribute time_limit.
      20 21 22  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 20 def time_limit @time_limit end  | 
  
Class Method Details
.parse(string) ⇒ Object
      23 24 25  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 23 def self.parse(string) new(*Base64.decode64(string).split(' ', 2)) end  | 
  
Instance Method Details
#digest ⇒ Object
      35 36 37  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 35 def digest ::Digest::MD5.hexdigest("#{@timestamp}:#{self.class.private_key}") end  | 
  
#fresh? ⇒ Boolean
      47 48 49  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 47 def fresh? !stale? end  | 
  
#stale? ⇒ Boolean
      43 44 45  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 43 def stale? !self.class.time_limit.nil? && (Time.now.to_i - @timestamp) > self.class.time_limit end  | 
  
#to_s ⇒ Object
      31 32 33  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 31 def to_s Base64.encode64("#{@timestamp} #{digest}").strip end  | 
  
#valid? ⇒ Boolean
      39 40 41  | 
    
      # File 'lib/rack/auth/digest/nonce.rb', line 39 def valid? digest == @given_digest end  |