class Travis::Client::Repository::Key
def ==(other)
def ==(other) other.to_s == self end
def encrypt(value)
def encrypt(value) encrypted = to_rsa.public_encrypt(value) Base64.encode64(encrypted).gsub(/\s+/, "") end
def initialize(data)
def initialize(data) @to_s = data end
def sized_bytes(value)
def sized_bytes(value) bytes = to_byte_array(value.to_i) [bytes.size, *bytes].pack('NC*') end
def to_byte_array(num, *significant)
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
def to_rsa
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 to_ssh
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