Skip to content

Commit

Permalink
Add SSLSocket#getbyte
Browse files Browse the repository at this point in the history
Normal sockets respond to `getbyte`, so we should make SSLSocket respond
to `getbyte` as well.  This way we can substitute SSLSockets for regular
sockets.
  • Loading branch information
tenderlove committed Apr 15, 2021
1 parent d172036 commit 011a889
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/openssl/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ def session
nil
end

# call-seq:
# ssl.getbyte => 81
#
# Get the next 8bit byte from `ssl`
def getbyte
read(1).unpack1("C")
end

private

def using_anon_cipher?
Expand Down
18 changes: 18 additions & 0 deletions test/openssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,24 @@ def test_sysread_and_syswrite
}
end

def test_getbyte
start_server { |port|
server_connect(port) { |ssl|
str = +("x" * 100 + "\n")
ssl.syswrite(str)
newstr = str.bytesize.times.map { |i|
ssl.getbyte
}.pack("C*")
assert_equal(str, newstr)

buf = String.new
ssl.syswrite(str)
assert_same buf, ssl.sysread(str.size, buf)
assert_equal(str, buf)
}
}
end

def test_sync_close
start_server do |port|
begin
Expand Down

0 comments on commit 011a889

Please sign in to comment.