From c409a07dc960b11595b329b6245b12b7be6d2dd7 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:14:29 +0100 Subject: [PATCH] Drop dependency on base64 (#986) --- dalli.gemspec | 2 -- lib/dalli/protocol/meta/key_regularizer.rb | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dalli.gemspec b/dalli.gemspec index 723eab97..99ea6611 100644 --- a/dalli.gemspec +++ b/dalli.gemspec @@ -22,6 +22,4 @@ Gem::Specification.new do |s| s.metadata = { 'rubygems_mfa_required' => 'true' } - - s.add_dependency 'base64' end diff --git a/lib/dalli/protocol/meta/key_regularizer.rb b/lib/dalli/protocol/meta/key_regularizer.rb index eeb2b6a2..56b18605 100644 --- a/lib/dalli/protocol/meta/key_regularizer.rb +++ b/lib/dalli/protocol/meta/key_regularizer.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'base64' - module Dalli module Protocol class Meta @@ -17,13 +15,15 @@ class KeyRegularizer def self.encode(key) return [key, false] if key.ascii_only? && !WHITESPACE.match(key) - [Base64.strict_encode64(key), true] + strict_base64_encoded = [key].pack('m0') + [strict_base64_encoded, true] end def self.decode(encoded_key, base64_encoded) return encoded_key unless base64_encoded - Base64.strict_decode64(encoded_key).force_encoding(Encoding::UTF_8) + strict_base64_decoded = encoded_key.unpack1('m0') + strict_base64_decoded.force_encoding(Encoding::UTF_8) end end end