diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2021-04-17 12:42:58 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-17 12:42:58 +0900 |
commit | 03cb3d5429ecd17736e2a063d4cbd7963799de28 (patch) | |
tree | ded01936c1ca47cfdf19a478034779ee6b5c94f1 /lib | |
parent | d172036b4a3e137107a35f2f7818e01b9b4d630d (diff) | |
parent | ac1490b7c900ee04238f89f0c085fd565e489c00 (diff) | |
download | ruby-openssl-03cb3d5429ecd17736e2a063d4cbd7963799de28.tar.gz |
Merge pull request #438 from ruby/getbyte
Add SSLSocket#getbyte
Diffstat (limited to 'lib')
-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. |