Skip to content

Commit

Permalink
Refactor Rack::Session::Cookie#unpacked_cookie_data
Browse files Browse the repository at this point in the history
  • Loading branch information
brainopia committed Jan 27, 2012
1 parent 2301a16 commit 0f6ee06
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/rack/session/cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) || {}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0f6ee06

Please sign in to comment.