Class: OpenPGP::Packet::SymmetricSessionKey

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

Overview

OpenPGP Symmetric-Key Encrypted Session Key packet (tag 3).

Instance Attribute Summary collapse

Attributes inherited from OpenPGP::Packet

#data, #size, #tag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenPGP::Packet

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

Constructor Details

#initialize(options = {}, &block) ⇒ SymmetricSessionKey

Returns a new instance of SymmetricSessionKey.



192
193
194
195
196
197
198
199
# File 'lib/openpgp/packet.rb', line 192

def initialize(options = {}, &block)
  defaults = {
    :version   => 4,
    :algorithm => Cipher::DEFAULT.to_i,
    :s2k       => S2K::DEFAULT.new,
  }
  super(defaults.merge(options), &block)
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



181
182
183
# File 'lib/openpgp/packet.rb', line 181

def algorithm
  @algorithm
end

#s2kObject

Returns the value of attribute s2k.



181
182
183
# File 'lib/openpgp/packet.rb', line 181

def s2k
  @s2k
end

#versionObject

Returns the value of attribute version.



181
182
183
# File 'lib/openpgp/packet.rb', line 181

def version
  @version
end

Class Method Details

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



183
184
185
186
187
188
189
190
# File 'lib/openpgp/packet.rb', line 183

def self.parse_body(body, options = {})
  case version = body.read_byte
    when 4
      self.new({:version => version, :algorithm => body.read_byte, :s2k => body.read_s2k}.merge(options))
    else
      raise "Invalid OpenPGP symmetric-key ESK packet version: #{version}"
  end
end

Instance Method Details

#write_body(buffer) ⇒ Object



201
202
203
204
205
# File 'lib/openpgp/packet.rb', line 201

def write_body(buffer)
  buffer.write_byte(version)
  buffer.write_byte(algorithm.to_i)
  buffer.write_s2k(s2k)
end