Class: Rage::Cookies::EncryptedJar
- Inherits:
-
Object
- Object
- Rage::Cookies::EncryptedJar
- Defined in:
- lib/rage/cookies.rb
Constant Summary collapse
- SALT =
"encrypted cookie"- PADDING =
"00"
Class Method Summary collapse
Class Method Details
.dump(value) ⇒ Object
276 277 278 279 280 |
# File 'lib/rage/cookies.rb', line 276 def dump(value) # add two bytes to hold meta information, e.g. in case we # need to change the encryption algorithm in the future Base64.urlsafe_encode64(PADDING + primary_box.encrypt(value.to_s)) end |
.load(value) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/rage/cookies.rb', line 257 def load(value) box = primary_box begin box.decrypt(Base64.urlsafe_decode64(value).byteslice(2..)) rescue ArgumentError Rage.logger.debug("Failed to decode encrypted cookie") nil rescue RbNaCl::CryptoError Rage.logger.debug("Failed to decrypt encrypted cookie") i ||= 0 if (box = fallback_boxes[i]) Rage.logger.debug("Trying to decrypt with fallback key ##{i + 1}") i += 1 retry end end end |