class OpenPGP::Packet::Signature

OpenPGP Signature packet (tag 2).

@see tools.ietf.org/html/rfc4880#section-5.2

Attributes

fields[RW]
hash_algorithm[RW]
key_algorithm[RW]
key_id[RW]
type[RW]
version[RW]

Public Class Methods

parse_body(body, options = {}) click to toggle source
# File lib/openpgp/packet.rb, line 149
def self.parse_body(body, options = {})
  case version = body.read_byte
    when 3 then self.new(:version => 3).send(:read_v3_signature, body)
    when 4 then self.new(:version => 4).send(:read_v4_signature, body)
    else raise "Invalid OpenPGP signature packet version: #{version}"
  end
end

Protected Instance Methods

read_signature(body) click to toggle source

@see tools.ietf.org/html/rfc4880#section-5.2.2

# File lib/openpgp/packet.rb, line 184
def read_signature(body)
  case key_algorithm
    when Algorithm::Asymmetric::RSA
      @fields = [body.read_mpi]
    when Algorithm::Asymmetric::DSA
      @fields = [body.read_mpi, body.read_mpi]
    else
      raise "Unknown OpenPGP signature packet public-key algorithm: #{key_algorithm}"
  end
end
read_v3_signature(body) click to toggle source

@see tools.ietf.org/html/rfc4880#section-5.2.2

# File lib/openpgp/packet.rb, line 161
def read_v3_signature(body)
  raise "Invalid OpenPGP signature packet V3 header" if body.read_byte != 5
  @type, @timestamp, @key_id = body.read_byte, body.read_number(4), body.read_number(8, 16)
  @key_algorithm, @hash_algorithm = body.read_byte, body.read_byte
  body.read_bytes(2)
  read_signature(body)
  self
end
read_v4_signature(body) click to toggle source

@see tools.ietf.org/html/rfc4880#section-5.2.3

# File lib/openpgp/packet.rb, line 172
def read_v4_signature(body)
  @type = body.read_byte
  @key_algorithm, @hash_algorithm = body.read_byte, body.read_byte
  body.read_bytes(hashed_count = body.read_number(2))
  body.read_bytes(unhashed_count = body.read_number(2))
  body.read_bytes(2)
  read_signature(body)
  self
end