lib/roda/plugins/sessions.rb in roda-3.72.0 vs lib/roda/plugins/sessions.rb in roda-3.73.0

- old
+ new

@@ -8,11 +8,10 @@ # :nocov: raise LoadError, "Roda sessions plugin requires the aes-256-ctr cipher" # :nocov: end -require 'base64' require 'json' require 'securerandom' require 'zlib' require 'rack/utils' @@ -169,10 +168,14 @@ hmac_secret = secret = secret.dup.force_encoding('BINARY') cipher_secret = secret.slice!(0, 32) [cipher_secret.freeze, hmac_secret.freeze] end + def self.load_dependencies(app, opts=OPTS) + app.plugin :_base64 + end + # Configure the plugin, see Sessions for details on options. def self.configure(app, opts=OPTS) opts = (app.opts[:sessions] || DEFAULT_OPTIONS).merge(opts) co = opts[:cookie_options] = DEFAULT_COOKIE_OPTIONS.merge(opts[:cookie_options] || OPTS).freeze opts[:remove_cookie_options] = co.merge(:max_age=>'0', :expires=>Time.at(0)) @@ -342,11 +345,11 @@ # Interpret given cookie data as a Rack::Session::Cookie def _deserialize_session(data) opts = roda_class.opts[:sessions] begin - data = Base64.urlsafe_decode64(data) + data = Base64_.urlsafe_decode64(data) rescue ArgumentError return _session_serialization_error("Unable to decode session: invalid base64") end case version = data.getbyte(0) @@ -491,10 +494,10 @@ data << per_cookie_secret_base if per_cookie_secret_base data << cipher_iv data << encrypted_data data << OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, opts[:hmac_secret], data+opts[:key]) - data = Base64.urlsafe_encode64(data) + data = Base64_.urlsafe_encode64(data) if data.bytesize >= 4096 raise CookieTooLarge, "attempted to create cookie larger than 4096 bytes" end