From 593164c2bea634e33682a0095825ef17021a7433 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 15 Apr 2021 16:53:47 -0700 Subject: [ruby/openssl] Add SSLSocket#getbyte Normal sockets respond to `getbyte`, so we should make SSLSocket respond to `getbyte` as well. This way we can substitute SSLSockets for regular sockets. https://github.com/ruby/openssl/commit/ac1490b7c9 --- ext/openssl/lib/openssl/buffering.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ext') diff --git a/ext/openssl/lib/openssl/buffering.rb b/ext/openssl/lib/openssl/buffering.rb index 32e04b4896..116179d21f 100644 --- a/ext/openssl/lib/openssl/buffering.rb +++ b/ext/openssl/lib/openssl/buffering.rb @@ -99,8 +99,27 @@ module OpenSSL::Buffering end end + if "".respond_to?(:unpack1) + def unpack_byte(str) + str.unpack1("C") + end + else + def unpack_byte(str) + str.unpack("C").first + end + end + public + # call-seq: + # ssl.getbyte => 81 + # + # Get the next 8bit byte from `ssl`. Returns `nil` on EOF + def getbyte + byte = read(1) + byte && unpack_byte(byte) + end + ## # Reads _size_ bytes from the stream. If _buf_ is provided it must # reference a string which will receive the data. -- cgit v1.2.3