Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated base64 in favour of pack/unpack (2-2-stable) #2174

Open
wants to merge 2 commits into
base: 2-2-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. For info on

## Unreleased

- Remove `Base64` use in favour of `pack`/`unpack` ([#2174](https://github.com/rack/rack/pull/2174), [@adam12](https://github.com/adam12))

## [2.2.9] - 2023-03-21

- Return empty when parsing a multi-part POST with only one end delimiter. ([#2104](https://github.com/rack/rack/pull/2104), [@alpaca-tc])
Expand Down
3 changes: 1 addition & 2 deletions lib/rack/auth/basic.rb
Expand Up @@ -2,7 +2,6 @@

require_relative 'abstract/handler'
require_relative 'abstract/request'
require 'base64'

module Rack
module Auth
Expand Down Expand Up @@ -48,7 +47,7 @@ def basic?
end

def credentials
@credentials ||= Base64.decode64(params).split(':', 2)
@credentials ||= params.unpack("m").first.split(':', 2)
end

def username
Expand Down
5 changes: 2 additions & 3 deletions lib/rack/auth/digest/nonce.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'digest/md5'
require 'base64'

module Rack
module Auth
Expand All @@ -21,15 +20,15 @@ class << self
end

def self.parse(string)
new(*Base64.decode64(string).split(' ', 2))
new(*string.unpack("m").first.split(' ', 2))
end

def initialize(timestamp = Time.now, given_digest = nil)
@timestamp, @given_digest = timestamp.to_i, given_digest
end

def to_s
Base64.encode64("#{@timestamp} #{digest}").strip
["#{@timestamp} #{digest}"].pack("m0")
end

def digest
Expand Down
5 changes: 2 additions & 3 deletions lib/rack/session/cookie.rb
Expand Up @@ -4,7 +4,6 @@
require 'zlib'
require_relative 'abstract/id'
require 'json'
require 'base64'
require 'delegate'

module Rack
Expand Down Expand Up @@ -51,11 +50,11 @@ class Cookie < Abstract::PersistedSecure
# Encode session cookies as Base64
class Base64
def encode(str)
::Base64.strict_encode64(str)
[str].pack("m0")
end

def decode(str)
::Base64.decode64(str)
str.unpack("m").first
end

# Encode session cookies as Marshaled Base64 data
Expand Down