A convenience module for writing a string of encoded data. It provides an interface for easily writing and encoding data.
Writes the given data literally into the string.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 159
159: def write( *data )
160: @content << data.join
161: 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.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 207
207: def write_bignum( *n )
208: @content << n.map { |b| b.to_ssh }.join
209: end
Writes each argument to the buffer as a (C-style) boolean, with 1 meaning true, and 0 meaning false.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 201
201: def write_bool( *b )
202: @content << b.map { |v| ( v ? 1 : 0 ).chr }.join
203: end
Writes each argument to the buffer as a byte.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 186
186: def write_byte( *n )
187: @content << n.map { |c| c.chr }.join
188: end
Writes each argument to the buffer as a network-byte-order-encoded 64-bit integer (8 bytes).
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 165
165: def write_int64( *n )
166: n.each do |i|
167: hi = ( i >> 32 ) & 0xFFFFFFFF
168: lo = i & 0xFFFFFFFF
169: @content << [ hi, lo ].pack( "N2" )
170: end
171: end
Writes the given arguments to the buffer as SSH2-encoded keys.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 212
212: def write_key( *key )
213: key.each do |k|
214: write_string( k.ssh_type )
215:
216: case k.ssh_type
217: when "ssh-dss"
218: write_bignum( k.p )
219: write_bignum( k.q )
220: write_bignum( k.g )
221: write_bignum( k.pub_key )
222:
223: when "ssh-rsa"
224: write_bignum( k.e )
225: write_bignum( k.n )
226:
227: else
228: raise NotImplementedError,
229: "unsupported key type '#{k.ssh_type}'"
230: end
231: end
232: end
Writes each argument to the buffer as a network-byte-order-encoded long (4-byte) integer.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 175
175: def write_long( *n )
176: @content << n.pack( "N*" )
177: end
Writes each argument to the buffer as a network-byte-order-encoded short (2-byte) integer.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 181
181: def write_short( *n )
182: @content << n.pack( "n*" )
183: 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.
[ show source ]
# File lib/net/ssh/util/buffer.rb, line 192
192: def write_string( *text )
193: text.each do |string|
194: write_long( string.length )
195: write( string )
196: end
197: end