Class: OpenPGP::Packet::PublicKey

Inherits:
  • Object
show all
Defined in:
lib/openpgp/packet.rb

Overview

OpenPGP Public-Key packet (tag 6).

See Also:

Direct Known Subclasses

PublicSubkey, SecretKey

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from

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

Constructor Details

This class inherits a constructor from OpenPGP::Packet

Instance Attribute Details

- (Object) algorithm

Returns the value of attribute algorithm



245
246
247
# File 'lib/openpgp/packet.rb', line 245

def algorithm
  @algorithm
end

- (Object) fingerprint



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/openpgp/packet.rb', line 278

def fingerprint
  @fingerprint ||= case version
    when 2, 3
      Digest::MD5.hexdigest([key[:n], key[:e]].join).upcase
    when 4
      material = [0x99.chr, [size].pack('n'), version.chr, [timestamp].pack('N'), algorithm.chr]
      key_fields.each do |key_field|
        material << [OpenPGP.bitlength(key[key_field])].pack('n')
        material << key[key_field]
      end
      Digest::SHA1.hexdigest(material.join).upcase
  end
end

- (Object) key

Returns the value of attribute key



246
247
248
# File 'lib/openpgp/packet.rb', line 246

def key
  @key
end

- (Object) key_fields

Returns the value of attribute key_fields



246
247
248
# File 'lib/openpgp/packet.rb', line 246

def key_fields
  @key_fields
end

- (Object) key_id

Returns the value of attribute key_id



246
247
248
# File 'lib/openpgp/packet.rb', line 246

def key_id
  @key_id
end

- (Object) size

Returns the value of attribute size



244
245
246
# File 'lib/openpgp/packet.rb', line 244

def size
  @size
end

- (Object) timestamp

Returns the value of attribute timestamp



245
246
247
# File 'lib/openpgp/packet.rb', line 245

def timestamp
  @timestamp
end

- (Object) version

Returns the value of attribute version



245
246
247
# File 'lib/openpgp/packet.rb', line 245

def version
  @version
end

Class Method Details

+ (Object) parse_body(body, options = {})

def parse(data) # FIXME



249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/openpgp/packet.rb', line 249

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

- (Object) read_key_material(body)



264
265
266
267
268
269
270
271
272
273
# File 'lib/openpgp/packet.rb', line 264

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