Skip to content

Commit

Permalink
Do not use base64 (#51)
Browse files Browse the repository at this point in the history
... because it will require an explicit dependency since Ruby 3.4.0.
  • Loading branch information
mame committed Sep 19, 2023
1 parent 85220ab commit 7402538
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/websocket/handshake/handler/client04.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def handshake_keys
# Sec-WebSocket-Key value
# @return [String] key
def key
@key ||= Base64.encode64((1..16).map { rand(255).chr } * '').strip
@key ||= [(1..16).map { rand(255).chr } * ''].pack('m').strip
end

# Value of Sec-WebSocket-Accept that should be delivered back by server
# @return [Sering] accept
def accept
@accept ||= Base64.encode64(Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')).strip
@accept ||= [Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')].pack('m').strip
end

# Verify if received header Sec-WebSocket-Accept matches generated one.
Expand Down
2 changes: 1 addition & 1 deletion lib/websocket/handshake/handler/server04.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def handshake_keys
def signature
return unless key
string_to_sign = "#{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
Base64.encode64(Digest::SHA1.digest(string_to_sign)).chomp
[Digest::SHA1.digest(string_to_sign)].pack('m').chomp
end

def verify_key
Expand Down

0 comments on commit 7402538

Please sign in to comment.