aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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.