Permalink
Browse files

Add a #dbman attr_reader for CGI::Session and make CGI::Session::Cook…

…ieStore#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
  • Loading branch information...
1 parent d1b08f4 commit 2b7dbad8e081b1ce84a7262b1b0953254bf8f651 @technoweenie technoweenie committed Mar 6, 2007
View
3 actionpack/CHANGELOG
@@ -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
1 actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb
@@ -26,6 +26,7 @@ def self.generate_unique_id(constant = 'foobar')
# 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
12 actionpack/lib/action_controller/session/cookie_store.rb
@@ -94,6 +94,12 @@ def delete
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 @@ def unmarshal(cookie)
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

0 comments on commit 2b7dbad

Please sign in to comment.