Skip to content

Commit

Permalink
Drop base64 dependency (#1071)
Browse files Browse the repository at this point in the history
See #1066

Co-authored-by: Koichi Sasada <ko1@atdot.net>
  • Loading branch information
Earlopain and ko1 authored Feb 20, 2024
1 parent b0b9534 commit 47bb58b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
1 change: 0 additions & 1 deletion debug.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ Gem::Specification.new do |spec|

spec.add_dependency "irb", "~> 1.10" # for irb:debug integration
spec.add_dependency "reline", ">= 0.3.8"
spec.add_dependency "base64"
end
5 changes: 2 additions & 3 deletions lib/debug/server_cdp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'json'
require 'digest/sha1'
require 'base64'
require 'securerandom'
require 'stringio'
require 'open3'
Expand Down Expand Up @@ -298,7 +297,7 @@ def handshake port, path
show_protocol :<, res

if res.match(/^Sec-WebSocket-Accept: (.*)\r\n/)
correct_key = Base64.strict_encode64 Digest::SHA1.digest "#{key}==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
correct_key = Digest::SHA1.base64digest "#{key}==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
raise "The Sec-WebSocket-Accept value: #{$1} is not valid" unless $1 == correct_key
else
raise "Unknown response: #{res}"
Expand Down Expand Up @@ -379,7 +378,7 @@ def handshake
show_protocol '>', req

if req.match(/^Sec-WebSocket-Key: (.*)\r\n/)
accept = Base64.strict_encode64 Digest::SHA1.digest "#{$1}258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
accept = Digest::SHA1.base64digest "#{$1}258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: #{accept}\r\n\r\n"
@sock.print res
show_protocol :<, res
Expand Down
3 changes: 1 addition & 2 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'net/http'
require 'uri'
require 'digest/sha1'
require 'base64'

require_relative 'test_case'
require_relative 'dap_utils'
Expand Down Expand Up @@ -924,7 +923,7 @@ def handshake port, uuid
@sock.print "GET /#{uuid} HTTP/1.1\r\nHost: 127.0.0.1:#{port}\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: #{key}==\r\n\r\n"
server_key = get_server_key

correct_key = Base64.strict_encode64 Digest::SHA1.digest "#{key}==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
correct_key = Digest::SHA1.base64digest "#{key}==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
raise "The Sec-WebSocket-Accept value: #{$1} is not valid" unless server_key == correct_key
end

Expand Down

0 comments on commit 47bb58b

Please sign in to comment.