diff options
author | Miklos Fazekas <mfazekas@szemafor.com> | 2018-03-21 13:04:31 +0100 |
---|---|---|
committer | Miklos Fazekas <mfazekas@szemafor.com> | 2018-03-21 13:04:31 +0100 |
commit | 1a63204dc8fa800ce9a7b1e60e138276e3c4bb21 (patch) | |
tree | 78766271ab552b814c4a7e021df8918c34820d83 | |
parent | 8a7f06de8e7be8d59e5da1e8e6b7ae3147f2c798 (diff) | |
download | net-ssh-1a63204dc8fa800ce9a7b1e60e138276e3c4bb21.tar.gz |
Fix test test issue
-rw-r--r-- | lib/net/ssh/buffer.rb | 82 | ||||
-rw-r--r-- | lib/net/ssh/test/packet.rb | 26 |
2 files changed, 54 insertions, 54 deletions
diff --git a/lib/net/ssh/buffer.rb b/lib/net/ssh/buffer.rb index 6d96066..df91591 100644 --- a/lib/net/ssh/buffer.rb +++ b/lib/net/ssh/buffer.rb @@ -4,7 +4,7 @@ require 'net/ssh/transport/openssl' require 'net/ssh/authentication/certificate' require 'net/ssh/authentication/ed25519_loader' -module Net +module Net module SSH # Net::SSH::Buffer is a flexible class for building and parsing binary @@ -47,7 +47,7 @@ module Net # easier to write multiple values of the same type in a briefer manner. def self.from(*args) raise ArgumentError, "odd number of arguments given" unless args.length % 2 == 0 - + buffer = new 0.step(args.length - 1, 2) do |index| type = args[index] @@ -60,69 +60,69 @@ module Net buffer.send("write_#{type}", value) end end - + buffer end - + # exposes the raw content of the buffer attr_reader :content - + # the current position of the pointer in the buffer attr_accessor :position - + # Creates a new buffer, initialized to the given content. The position # is initialized to the beginning of the buffer. def initialize(content="") @content = content.to_s @position = 0 end - + # Returns the length of the buffer's content. def length @content.length end - + # Returns the number of bytes available to be read (e.g., how many bytes # remain between the current position and the end of the buffer). def available length - position end - + # Returns a copy of the buffer's content. def to_s (@content || "").dup end - + # Compares the contents of the two buffers, returning +true+ only if they # are identical in size and content. def ==(buffer) to_s == buffer.to_s end - + # Returns +true+ if the buffer contains no data (e.g., it is of zero length). def empty? @content.empty? end - + # Resets the pointer to the start of the buffer. Subsequent reads will # begin at position 0. def reset! @position = 0 end - + # Returns true if the pointer is at the end of the buffer. Subsequent # reads will return nil, in this case. def eof? @position >= length end - + # Resets the buffer, making it empty. Also, resets the read position to # 0. def clear! @content = "" @position = 0 end - + # Consumes n bytes from the buffer, where n is the current position # unless otherwise specified. This is useful for removing data from the # buffer that has previously been read, when you are expecting more data @@ -141,20 +141,20 @@ module Net end self end - + # Appends the given text to the end of the buffer. Does not alter the # read position. Returns the buffer object itself. def append(text) @content << text self end - + # Returns all text from the current pointer to the end of the buffer as # a new Net::SSH::Buffer object. def remainder_as_buffer Buffer.new(@content[@position..-1]) end - + # Reads all data up to and including the given pattern, which may be a # String, Fixnum, or Regexp and is interpreted exactly as String#index # does. Returns nil if nothing matches. Increments the position to point @@ -169,7 +169,7 @@ module Net end index && read(index + length) end - + # Reads and returns the next +count+ bytes from the buffer, starting from # the read position. If +count+ is +nil+, this will return all remaining # text in the buffer. This method will increment the pointer. @@ -179,7 +179,7 @@ module Net @position += count @content[@position - count, count] end - + # Reads (as #read) and returns the given number of bytes from the buffer, # and then consumes (as #consume!) all data up to the new read position. def read!(count=nil) @@ -187,12 +187,12 @@ module Net consume! data end - + # Calls block(self) until the buffer is empty, and returns all results. def read_all(&block) Enumerator.new { |e| e << yield(self) until eof? }.to_a end - + # Return the next 8 bytes as a 64-bit integer (in network byte order). # Returns nil if there are less than 8 bytes remaining to be read in the # buffer. @@ -201,7 +201,7 @@ module Net lo = read_long or return nil return (hi << 32) + lo end - + # Return the next four bytes as a long integer (in network byte order). # Returns nil if there are less than 4 bytes remaining to be read in the # buffer. @@ -209,14 +209,14 @@ module Net b = read(4) or return nil b.unpack("N").first end - + # Read and return the next byte in the buffer. Returns nil if called at # the end of the buffer. def read_byte b = read(1) or return nil b.getbyte(0) end - + # Read and return an SSH2-encoded string. The string starts with a long # integer that describes the number of bytes remaining in the string. # Returns nil if there are not enough bytes to satisfy the request. @@ -224,14 +224,14 @@ module Net length = read_long or return nil read(length) end - + # Read a single byte and convert it into a boolean, using 'C' rules # (i.e., zero is false, non-zero is true). def read_bool b = read_byte or return nil b != 0 end - + # Read a bignum (OpenSSL::BN) from the buffer, in SSH2 format. It is # essentially just a string, which is reinterpreted to be a bignum in # binary format. @@ -240,7 +240,7 @@ module Net return unless data OpenSSL::BN.new(data, 2) end - + # Read a key from the buffer. The key will start with a string # describing its type. The remainder of the key is defined by the # type that was read. @@ -248,7 +248,7 @@ module Net type = read_string return (type ? read_keyblob(type) : nil) end - + # Read a keyblob of the given type from the buffer, and return it as # a key. Only RSA, DSA, and ECDSA keys are supported. def read_keyblob(type) @@ -295,30 +295,30 @@ module Net else raise NotImplementedError, "unsupported key type `#{type}'" end - + return key end - + # Reads the next string from the buffer, and returns a new Buffer # object that wraps it. def read_buffer Buffer.new(read_string) end - + # Writes the given data literally into the string. Does not alter the # read position. Returns the buffer object. def write(*data) data.each { |datum| @content << datum.dup.force_encoding('BINARY') } self end - + # Optimized version of write where the caller gives up ownership of string # to the method. This way we can mutate the string. def write_moved(string) @content << string.force_encoding('BINARY') self end - + # Writes each argument to the buffer as a network-byte-order-encoded # 64-bit integer (8 bytes). Does not alter the read position. Returns the # buffer object. @@ -330,7 +330,7 @@ module Net end self end - + # Writes each argument to the buffer as a network-byte-order-encoded # long (4-byte) integer. Does not alter the read position. Returns the # buffer object. @@ -338,14 +338,14 @@ module Net @content << n.pack("N*") self end - + # Writes each argument to the buffer as a byte. Does not alter the read # position. Returns the buffer object. def write_byte(*n) n.each { |b| @content << b.chr } self end - + # Writes each argument to the buffer as an SSH2-encoded string. Each # string is prefixed by its length, encoded as a 4-byte long integer. # Does not alter the read position. Returns the buffer object. @@ -357,7 +357,7 @@ module Net end self end - + # Writes each argument to the buffer as an SSH2-encoded string. Each # string is prefixed by its length, encoded as a 4-byte long integer. # Does not alter the read position. Returns the buffer object. @@ -370,7 +370,7 @@ module Net end self end - + # Writes each argument to the buffer as a (C-style) boolean, with 1 # meaning true, and 0 meaning false. Does not alter the read position. # Returns the buffer object. @@ -378,7 +378,7 @@ module Net b.each { |v| @content << (v ? "\1" : "\0") } self end - + # Writes each argument to the buffer as a bignum (SSH2-style). No # checking is done to ensure that the arguments are, in fact, bignums. # Does not alter the read position. Returns the buffer object. @@ -386,7 +386,7 @@ module Net @content << n.map { |b| b.to_ssh }.join self end - + # Writes the given arguments to the buffer as SSH2-encoded keys. Does not # alter the read position. Returns the buffer object. def write_key(*key) diff --git a/lib/net/ssh/test/packet.rb b/lib/net/ssh/test/packet.rb index b6bc9c3..ad4a334 100644 --- a/lib/net/ssh/test/packet.rb +++ b/lib/net/ssh/test/packet.rb @@ -1,8 +1,8 @@ require 'net/ssh/connection/constants' require 'net/ssh/transport/constants' -module Net - module SSH +module Net + module SSH module Test # This is an abstract class, not to be instantiated directly, subclassed by @@ -18,18 +18,18 @@ module Net class Packet include Net::SSH::Transport::Constants include Net::SSH::Connection::Constants - + # Register a custom channel request. extra_parts is an array of types # of extra parameters def self.register_channel_request(request, extra_parts) @registered_requests ||= {} @registered_requests[request] = { extra_parts: extra_parts } end - + def self.registered_channel_requests(request) @registered_requests && @registered_requests[request] end - + # Ceate a new packet of the given +type+, and with +args+ being a list of # data elements in the order expected for packets of the given +type+ # (see #types). @@ -37,28 +37,28 @@ module Net @type = self.class.const_get(type.to_s.upcase) @data = args end - + # The default for +remote?+ is false. Subclasses should override as necessary. def remote? false end - + # The default for +local?+ is false. Subclasses should override as necessary. def local? false end - + # Instantiates the packets data elements. When the packet was first defined, # some elements may not have been fully realized, and were described as # Proc objects rather than atomic types. This invokes those Proc objects - # and replaces them with their returned values. This allows for values + # and replaces them with their returned values. This allows for values # like Net::SSH::Test::Channel#remote_id to be used in scripts before # the remote_id is known (since it is only known after a channel has been # confirmed open). def instantiate! @data.map! { |i| i.respond_to?(:call) ? i.call : i } end - + # Returns an array of symbols describing the data elements for packets of # the same type as this packet. These types are used to either validate # sent packets (Net::SSH::Test::LocalPacket) or build received packets @@ -70,8 +70,8 @@ module Net # added. Unsupported packet types will otherwise raise an exception. def types @types ||= case @type - when KEXINIT then - %i[longlonglonglong + when KEXINIT then + %i[long long long long string string string string string string string string string string bool] when NEWKEYS then [] @@ -97,4 +97,4 @@ module Net end end -end; end; end
\ No newline at end of file +end; end; end |