summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-04-15 16:53:47 -0700
committerKazuki Yamaguchi <k@rhe.jp>2021-07-18 17:44:53 +0900
commit593164c2bea634e33682a0095825ef17021a7433 (patch)
treefdbbcb26daac29fc24eb16708dfbecd8faf73f69 /ext/openssl
parent6d71918d94a6b34249015499e5e822d3b20fd10f (diff)
[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
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/lib/openssl/buffering.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/openssl/lib/openssl/buffering.rb b/ext/openssl/lib/openssl/buffering.rb
index 32e04b4896b..116179d21ff 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.