lib/net/ssh/buffer.rb in net-ssh-6.3.0.beta1 vs lib/net/ssh/buffer.rb in net-ssh-7.0.0.beta1
- old
+ new
@@ -68,11 +68,11 @@
# 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=String.new)
+ def initialize(content = String.new)
@content = content.to_s
@position = 0
end
# Returns the length of the buffer's content.
@@ -126,11 +126,11 @@
# buffer that has previously been read, when you are expecting more data
# to be appended. It helps to keep the size of buffers down when they
# would otherwise tend to grow without bound.
#
# Returns the buffer object itself.
- def consume!(n=position)
+ def consume!(n = position)
if n >= length
# optimize for a fairly common case
clear!
elsif n > 0
@content = @content[n..-1] || String.new
@@ -169,20 +169,20 @@
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.
- def read(count=nil)
+ def read(count = nil)
count ||= length
count = length - @position if @position + count > length
@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)
+ def read!(count = nil)
data = read(count)
consume!
data
end
@@ -281,10 +281,12 @@
key.dmp1 = dmp1
key.dmq1 = dmq1
key.iqmp = iqmp
end
key
+ when /^ecdsa\-sha2\-(\w*)$/
+ OpenSSL::PKey::EC.read_keyblob($1, self)
else
raise Exception, "Cannot decode private key of type #{type}"
end
end
@@ -293,32 +295,45 @@
def read_keyblob(type)
case type
when /^(.*)-cert-v01@openssh\.com$/
key = Net::SSH::Authentication::Certificate.read_certblob(self, $1)
when /^ssh-dss$/
- key = OpenSSL::PKey::DSA.new
- if key.respond_to?(:set_pqg)
- key.set_pqg(read_bignum, read_bignum, read_bignum)
- else
- key.p = read_bignum
- key.q = read_bignum
- key.g = read_bignum
- end
- if key.respond_to?(:set_key)
- key.set_key(read_bignum, nil)
- else
- key.pub_key = read_bignum
- end
+ p = read_bignum
+ q = read_bignum
+ g = read_bignum
+ pub_key = read_bignum
+
+ asn1 = OpenSSL::ASN1::Sequence.new(
+ [
+ OpenSSL::ASN1::Sequence.new(
+ [
+ OpenSSL::ASN1::ObjectId.new('DSA'),
+ OpenSSL::ASN1::Sequence.new(
+ [
+ OpenSSL::ASN1::Integer.new(p),
+ OpenSSL::ASN1::Integer.new(q),
+ OpenSSL::ASN1::Integer.new(g)
+ ]
+ )
+ ]
+ ),
+ OpenSSL::ASN1::BitString.new(OpenSSL::ASN1::Integer.new(pub_key).to_der)
+ ]
+ )
+
+ key = OpenSSL::PKey::DSA.new(asn1.to_der)
when /^ssh-rsa$/
- key = OpenSSL::PKey::RSA.new
- if key.respond_to?(:set_key)
- e = read_bignum
- n = read_bignum
- key.set_key(n, e, nil)
- else
- key.e = read_bignum
- key.n = read_bignum
- end
+ e = read_bignum
+ n = read_bignum
+
+ asn1 = OpenSSL::ASN1::Sequence(
+ [
+ OpenSSL::ASN1::Integer(n),
+ OpenSSL::ASN1::Integer(e)
+ ]
+ )
+
+ key = OpenSSL::PKey::RSA.new(asn1.to_der)
when /^ssh-ed25519$/
Net::SSH::Authentication::ED25519Loader.raiseUnlessLoaded("unsupported key type `#{type}'")
key = Net::SSH::Authentication::ED25519::PubKey.read_keyblob(self)
when /^ecdsa\-sha2\-(\w*)$/
key = OpenSSL::PKey::EC.read_keyblob($1, self)