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



381
382
383
384
385
# File 'lib/rage/cookies.rb', line 381

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



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/rage/cookies.rb', line 365

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