Class: Travis::Client::Repository::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/travis/client/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Key

Returns a new instance of Key.



11
12
13
# File 'lib/travis/client/repository.rb', line 11

def initialize(data)
  @to_s = data
end

Instance Attribute Details

#to_sObject (readonly)

Returns the value of attribute to_s.



9
10
11
# File 'lib/travis/client/repository.rb', line 9

def to_s
  @to_s
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'lib/travis/client/repository.rb', line 31

def ==(other)
  other.to_s == self
end

#encrypt(value) ⇒ Object



15
16
17
18
# File 'lib/travis/client/repository.rb', line 15

def encrypt(value)
  encrypted = to_rsa.public_encrypt(value)
  Base64.encode64(encrypted).gsub(/\s+/, "")
end

#to_rsaObject



24
25
26
27
28
29
# File 'lib/travis/client/repository.rb', line 24

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

#to_sshObject



20
21
22
# File 'lib/travis/client/repository.rb', line 20

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