Skip to content

Commit

Permalink
Drop dependency on base64 (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Feb 1, 2024
1 parent 4c4a5a2 commit c409a07
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions dalli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ Gem::Specification.new do |s|
s.metadata = {
'rubygems_mfa_required' => 'true'
}

s.add_dependency 'base64'
end
8 changes: 4 additions & 4 deletions lib/dalli/protocol/meta/key_regularizer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'base64'

module Dalli
module Protocol
class Meta
Expand All @@ -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
Expand Down

0 comments on commit c409a07

Please sign in to comment.