diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-04-15 16:53:47 -0700 |
---|---|---|
committer | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-04-16 09:11:47 -0700 |
commit | ac1490b7c900ee04238f89f0c085fd565e489c00 (patch) | |
tree | ded01936c1ca47cfdf19a478034779ee6b5c94f1 /lib/openssl | |
parent | d172036b4a3e137107a35f2f7818e01b9b4d630d (diff) | |
download | ruby-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.rb | 19 |
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. |