lib/travis/client/repository.rb in travis-1.2.7 vs lib/travis/client/repository.rb in travis-1.2.8
- old
+ new
@@ -15,19 +15,35 @@
def encrypt(value)
encrypted = to_rsa.public_encrypt(value)
Base64.encode64(encrypted).gsub(/\s+/, "")
end
+ def to_ssh
+ ['ssh-rsa ', "\0\0\0\assh-rsa#{sized_bytes(to_rsa.e)}#{sized_bytes(to_rsa.n)}"].pack('a*m').gsub("\n", '')
+ end
+
def to_rsa
@to_rsa ||= OpenSSL::PKey::RSA.new(to_s)
rescue OpenSSL::PKey::RSAError
public_key = to_s.gsub('RSA PUBLIC KEY', 'PUBLIC KEY')
@to_rsa = OpenSSL::PKey::RSA.new(public_key)
end
def ==(other)
other.to_s == self
end
+
+ private
+
+ def sized_bytes(value)
+ bytes = to_byte_array(value.to_i)
+ [bytes.size, *bytes].pack('NC*')
+ end
+
+ def to_byte_array(num, *significant)
+ return significant if num.between?(-1, 0) and significant[0][7] == num[7]
+ to_byte_array(*num.divmod(256)) + significant
+ end
end
include States
# @!parse attr_reader :slug, :description