Class: Rage::Cookies::SignedJar

Inherits:
Object
  • Object
show all
Extended by:
RbNaClKeyBuilder
Defined in:
lib/rage/cookies.rb

Constant Summary collapse

PURPOSE =
"signed cookie"
SEPARATOR =
"."
VERSION =
"00"

Constants included from RbNaClKeyBuilder

RbNaClKeyBuilder::RBNACL_MAX_VERSION, RbNaClKeyBuilder::RBNACL_MIN_VERSION

Class Method Summary collapse

Class Method Details

.dump(value) ⇒ Object



392
393
394
395
396
# File 'lib/rage/cookies.rb', line 392

def dump(value)
  encoded_value = Base64.urlsafe_encode64(value.to_s)
  signed_payload = signed_payload_for(VERSION, encoded_value)
  "#{signed_payload}#{SEPARATOR}#{digest_for(signed_payload, primary_signer)}"
end

.load(value) ⇒ Object



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/rage/cookies.rb', line 376

def load(value)
  version, encoded_value, digest = parse_signed_cookie(value)
  return nil if digest.nil?

  return nil unless version == VERSION

  signed_payload = signed_payload_for(version, encoded_value)
  return Base64.urlsafe_decode64(encoded_value) if verify_digest?(signed_payload, digest)

  Rage.logger.debug("Failed to verify signed cookie")
  nil
rescue ArgumentError
  Rage.logger.debug("Failed to decode signed cookie")
  nil
end