Class: Arrow::Session::SHA1Id

Inherits:
Id
  • Object
show all
Defined in:
lib/arrow/session/sha1id.rb

Overview

The Arrow::Session::SHA1Id class, a derivative of Arrow::Session::Id. Instances of this class are session IDs created by SHA1-hashing some semi-random data.

Synopsis

# In arrow.conf:

session:

idType: sha1:.

Authors

Please see the file LICENSE in the top-level directory for licensing details.

Constant Summary collapse

DEFAULT_SALT =

Default salt characters

'sadblkw456jbhgsdfi7283hnehonaseegop26m'

Class Method Summary collapse

Methods inherited from Id

create, derivativeDirs, #initialize, #new?, #to_s

Methods inherited from Object

deprecate_class_method, deprecate_method, inherited

Constructor Details

This class inherits a constructor from Arrow::Session::Id

Class Method Details

.generate(uri, request) ⇒ Object

Generate a new id



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/arrow/session/sha1id.rb', line 34

def self::generate( uri, request )
	salt = uri.opaque || DEFAULT_SALT
	seed = [
		salt,
		Time.new.to_s,
		Object.new.inspect,
		rand(),
		Process.pid,
	].join
	return Digest::SHA1.hexdigest( Digest::SHA1.hexdigest(seed) )
end

.validate(uri, idstr) ⇒ Object

Returns the validated id if the given id is in the expected form for this type, or nil if it is not.



48
49
50
51
52
# File 'lib/arrow/session/sha1id.rb', line 48

def self::validate( uri, idstr )
	rval = idstr[/^([a-f0-9]{40})$/]
	rval.untaint
	return rval
end