Class: OpenPGP::S2K::Iterated

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

Overview

See Also:

Constant Summary

IDENTIFIER =
0x03
EXPBIAS =
6

Constants inherited from Salted

IDENTIFIER

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

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

A new instance of Iterated

Parameters:

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


193
194
195
196
# File 'lib/openpgp/s2k.rb', line 193

def initialize(passphrase = nil, options = {}, &block)
  super(passphrase, options, &block)
  @count = 65536 unless @count
end

Instance Attribute Details

- (Integer) count (readonly)

Returns:

  • (Integer)


188
189
190
# File 'lib/openpgp/s2k.rb', line 188

def count
  @count
end

Class Method Details

+ (S2K) parse(input)

Parameters:

Returns:



181
182
183
184
185
# File 'lib/openpgp/s2k.rb', line 181

def self.parse(input)
  self.new(nil, :algorithm => input.read_byte, :salt => input.read_bytes(8)) do |s2k|
    s2k.count = s2k.decode_count(input.read_byte)
  end
end

Instance Method Details

- (Integer) decode_count(count) (protected)

Parameters:

  • (Integer) count

Returns:

  • (Integer)


231
232
233
# File 'lib/openpgp/s2k.rb', line 231

def decode_count(count)
  (16 + (count & 15)) << ((count >> 4) + EXPBIAS)
end

- (String) digest_input

Returns:

  • (String)


214
215
216
217
218
219
220
221
222
# File 'lib/openpgp/s2k.rb', line 214

def digest_input
  buffer = Buffer.write do |buffer|
    iterations = count
    while iterations > 0
      buffer << (digest_input = super())
      iterations -= digest_input.size
    end
  end
end

- (Integer) encode_count(iterations) (protected)

Parameters:

  • (Integer) iterations

Returns:

  • (Integer)


238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/openpgp/s2k.rb', line 238

def encode_count(iterations)
  case iterations
    when 0..1024           then 0
    when 65011712..(1.0/0) then 255
    else
      count1 = iterations >> 6
      count2 = (count2 || 0) + 1 while count1 >= 32 && count1 >>= 1
      result = (count2 << 4) | (count1 - 16)
      result += 1 if decode_count(result) < iterations
      result
  end
end

- (Hash) to_hash

Returns:

  • (Hash)


208
209
210
# File 'lib/openpgp/s2k.rb', line 208

def to_hash
  super.merge(:count => count)
end

- write(buffer)

This method returns an undefined value.

Parameters:



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

def write(buffer)
  super(buffer)
  buffer.write_byte(encode_count(count))
end