Class: RStyx::Keyring::InfPublicKey

Inherits:
Object
  • Object
show all
Defined in:
lib/rstyx/keyring.rb

Overview

An Inferno public key.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pk, owner) ⇒ InfPublicKey

Create a new Inferno public key, given the OpenSSL public key and the owner



201
202
203
204
# File 'lib/rstyx/keyring.rb', line 201

def initialize(pk, owner)
  @pk = pk
  @owner = owner
end

Instance Attribute Details

#ownerObject

The owner of the public key



195
196
197
# File 'lib/rstyx/keyring.rb', line 195

def owner
  @owner
end

#pkObject

The actual public key, as an OpenSSL::PKey::RSA object



191
192
193
# File 'lib/rstyx/keyring.rb', line 191

def pk
  @pk
end

Class Method Details

.from_s(s) ⇒ Object

Create a new public key, given a public key record string such as might be read from an Inferno keyring file.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/rstyx/keyring.rb', line 210

def self.from_s(s)
  a = s.split("\n")
  if a.length < 4
    raise InvalidKeyException.new("bad public key syntax")
  end

  if a[0] != "rsa"
    raise InvalidKeyException.new("unknown key algorithm #{a[0]}")
  end

  n = Keyring.s2big(a[2])
  e = Keyring.s2big(a[3])
  pk = OpenSSL::PKey::RSA.new
  pk.n = n
  pk.e = e
  return(InfPublicKey.new(pk, a[1]))
end

Instance Method Details

#to_sObject

Return the public key information as a string suitable for writing as a protocol message or in the Inferno keyfile format.



231
232
233
234
235
236
237
238
239
# File 'lib/rstyx/keyring.rb', line 231

def to_s
  str = <<EOS
rsa
#{@owner}
#{Keyring.big2s(@pk.n.to_i)}
#{Keyring.big2s(@pk.e.to_i)}
EOS
  return(str)
end