aboutsummaryrefslogtreecommitdiffstats
path: root/lib/openssl
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-04-15 16:53:47 -0700
committerAaron Patterson <tenderlove@ruby-lang.org>2021-04-16 09:11:47 -0700
commitac1490b7c900ee04238f89f0c085fd565e489c00 (patch)
treeded01936c1ca47cfdf19a478034779ee6b5c94f1 /lib/openssl
parentd172036b4a3e137107a35f2f7818e01b9b4d630d (diff)
downloadruby-openssl-ac1490b7c900ee04238f89f0c085fd565e489c00.tar.gz
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.
Diffstat (limited to 'lib/openssl')
-rw-r--r--lib/openssl/buffering.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/openssl/buffering.rb b/lib/openssl/buffering.rb
index 32e04b48..116179d2 100644
--- a/lib/openssl/buffering.rb
+++ b/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.