1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add a #dbman attr_reader for CGI::Session and make CGI::Session::CookieStore#generate_digest public so it's easy to generate digests

using the cookie store's secret. [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6342 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Rick Olson 2007-03-06 04:09:14 +00:00
parent d1b08f4a75
commit 2b7dbad8e0
3 changed files with 10 additions and 6 deletions

View file

@ -1,5 +1,8 @@
*SVN*
# Add a #dbman attr_reader for CGI::Session and make CGI::Session::CookieStore#generate_digest public so it's easy to generate digests
using the cookie store's secret. [Rick]
* Added Request#url that returns the complete URL used for the request [DHH]
* Extract dynamic scaffolding into a plugin. #7700 [Josh Peek]

View file

@ -26,6 +26,7 @@ class CGI
# Make the CGI instance available to session stores.
attr_reader :cgi
attr_reader :dbman
alias_method :initialize_without_cgi_reader, :initialize
def initialize(cgi, options = {})
@cgi = cgi

View file

@ -94,6 +94,12 @@ class CGI::Session::CookieStore
write_cookie('value' => '', 'expires' => 1.year.ago)
end
# Generate the HMAC keyed message digest. Uses SHA1 by default.
def generate_digest(data)
key = @secret.respond_to?(:call) ? @secret.call(@session) : @secret
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new(@digest), key, data)
end
private
# Marshal a session hash into safe cookie data. Include an integrity hash.
def marshal(session)
@ -113,12 +119,6 @@ class CGI::Session::CookieStore
end
end
# Generate the HMAC keyed message digest. Uses SHA1 by default.
def generate_digest(data)
key = @secret.respond_to?(:call) ? @secret.call(@session) : @secret
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new(@digest), key, data)
end
# Read the session data cookie.
def read_cookie
@session.cgi.cookies[@cookie_options['name']].first