Class: OpenPGP::Packet::PublicKey

Inherits:
OpenPGP::Packet show all
Defined in:
lib/openpgp/packet.rb

Overview

OpenPGP Public-Key packet (tag 6).

Direct Known Subclasses

PublicSubkey, SecretKey

Instance Attribute Summary collapse

Attributes inherited from OpenPGP::Packet

#data, #tag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenPGP::Packet

#body, for, #initialize, parse, parse_new_format, parse_old_format, tag

Constructor Details

This class inherits a constructor from OpenPGP::Packet

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



225
226
227
# File 'lib/openpgp/packet.rb', line 225

def algorithm
  @algorithm
end

#fingerprintObject



258
259
260
# File 'lib/openpgp/packet.rb', line 258

def fingerprint
  @fingerprint
end

#keyObject

Returns the value of attribute key.



226
227
228
# File 'lib/openpgp/packet.rb', line 226

def key
  @key
end

#key_fieldsObject

Returns the value of attribute key_fields.



226
227
228
# File 'lib/openpgp/packet.rb', line 226

def key_fields
  @key_fields
end

#key_idObject

Returns the value of attribute key_id.



226
227
228
# File 'lib/openpgp/packet.rb', line 226

def key_id
  @key_id
end

#sizeObject

Returns the value of attribute size.



224
225
226
# File 'lib/openpgp/packet.rb', line 224

def size
  @size
end

#timestampObject

Returns the value of attribute timestamp.



225
226
227
# File 'lib/openpgp/packet.rb', line 225

def timestamp
  @timestamp
end

#versionObject

Returns the value of attribute version.



225
226
227
# File 'lib/openpgp/packet.rb', line 225

def version
  @version
end

Class Method Details

.parse_body(body, options = {}) ⇒ Object

def parse(data) # FIXME



229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/openpgp/packet.rb', line 229

def self.parse_body(body, options = {})
  case version = body.read_byte
    when 2, 3
      # TODO
    when 4
      packet = self.new(:version => version, :timestamp => body.read_timestamp, :algorithm => body.read_byte, :key => {}, :size => body.size)
      packet.read_key_material(body)
      packet
    else
      raise "Invalid OpenPGP public-key packet version: #{version}"
  end
end

Instance Method Details

#read_key_material(body) ⇒ Object



244
245
246
247
248
249
250
251
252
253
# File 'lib/openpgp/packet.rb', line 244

def read_key_material(body)
  @key_fields = case algorithm
    when Algorithm::Asymmetric::RSA   then [:n, :e]
    when Algorithm::Asymmetric::ELG_E then [:p, :g, :y]
    when Algorithm::Asymmetric::DSA   then [:p, :q, :g, :y]
    else raise "Unknown OpenPGP key algorithm: #{algorithm}"
  end
  @key_fields.each { |field| key[field] = body.read_mpi }
  @key_id = fingerprint[-8..-1]
end