Class: OpenPGP::Packet::Signature

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

Overview

OpenPGP Signature packet (tag 2).

See Also:

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) fields

Returns the value of attribute fields



147
148
149
# File 'lib/openpgp/packet.rb', line 147

def fields
  @fields
end

- (Object) hash_algorithm

Returns the value of attribute hash_algorithm



145
146
147
# File 'lib/openpgp/packet.rb', line 145

def hash_algorithm
  @hash_algorithm
end

- (Object) key_algorithm

Returns the value of attribute key_algorithm



145
146
147
# File 'lib/openpgp/packet.rb', line 145

def key_algorithm
  @key_algorithm
end

- (Object) key_id

Returns the value of attribute key_id



146
147
148
# File 'lib/openpgp/packet.rb', line 146

def key_id
  @key_id
end

- (Object) type

Returns the value of attribute type



144
145
146
# File 'lib/openpgp/packet.rb', line 144

def type
  @type
end

- (Object) version

Returns the value of attribute version



144
145
146
# File 'lib/openpgp/packet.rb', line 144

def version
  @version
end

Class Method Details

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



149
150
151
152
153
154
155
# 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

Instance Method Details

- (Object) read_signature(body) (protected)



184
185
186
187
188
189
190
191
192
193
# 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

- (Object) read_v3_signature(body) (protected)



161
162
163
164
165
166
167
168
# 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

- (Object) read_v4_signature(body) (protected)



172
173
174
175
176
177
178
179
180
# 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