Class: OpenPGP::S2K::Salted

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

Overview

See Also:

Direct Known Subclasses

Iterated

Constant Summary

IDENTIFIER =
0x01

Constants inherited from

DEFAULT

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from

#digest, #digest_input_with_preload, #identifier, identifier, #to_key, #to_s

Constructor Details

- (Salted) initialize(passphrase = nil, options = {}, &block)

A new instance of Salted

Parameters:

  • (String, #to_s) passphrase (defaults to: nil)
  • (Hash{Symbol => Object}) options (defaults to: {})


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

def initialize(passphrase = nil, options = {}, &block)
  super(passphrase, options, &block)
  @salt = Random.bytes(8) unless @salt
end

Instance Attribute Details

- (String) salt

Returns:

  • (String)


142
143
144
# File 'lib/openpgp/s2k.rb', line 142

def salt
  @salt
end

Class Method Details

+ (S2K) parse(input)

Parameters:

Returns:



137
138
139
# File 'lib/openpgp/s2k.rb', line 137

def self.parse(input)
  self.new(nil, :algorithm => input.read_byte, :salt => input.read_bytes(8))
end

Instance Method Details

- (String) digest_input

Returns:

  • (String)


168
169
170
# File 'lib/openpgp/s2k.rb', line 168

def digest_input
  salt.to_s[0, 8] << passphrase
end

- (Hash) to_hash

Returns:

  • (Hash)


162
163
164
# File 'lib/openpgp/s2k.rb', line 162

def to_hash
  super.merge({:salt => salt})
end

- write(buffer)

This method returns an undefined value.

Parameters:



155
156
157
158
# File 'lib/openpgp/s2k.rb', line 155

def write(buffer)
  super(buffer)
  buffer.write_bytes(salt)
end