Skip to content
Browse files

Refactor Rack::Session::Cookie#unpacked_cookie_data

  • Loading branch information...
1 parent 2301a16 commit 0f6ee067c7414e86fa3c6702b6135de42c29c6c2 @brainopia brainopia committed
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/rack/session/cookie.rb
View
16 lib/rack/session/cookie.rb
@@ -105,14 +105,7 @@ def unpacked_cookie_data(env)
if @secrets.size > 0 && session_data
session_data, digest = session_data.split("--")
-
- if session_data && digest
- ok = @secrets.any? do |secret|
- digest == generate_hmac(session_data, secret)
- end
- end
-
- session_data = nil unless ok
+ session_data = nil unless digest_match?(session_data, digest)
end
coder.decode(session_data) || {}
@@ -152,6 +145,13 @@ def destroy_session(env, session_id, options)
generate_sid unless options[:drop]
end
+ def digest_match?(data, digest)
+ return unless data && digest
+ @secrets.any? do |secret|
+ digest == generate_hmac(data, secret)
+ end
+ end
+
def generate_hmac(data, secret)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, data)
end

0 comments on commit 0f6ee06

Please sign in to comment.
Something went wrong with that request. Please try again.