Class: OpenPGP::Buffer

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Buffer) initialize(*args) {|buffer| ... }

A new instance of Buffer

Yields:

  • (buffer)

Yield Parameters:



16
17
18
19
# File 'lib/openpgp/buffer.rb', line 16

def initialize(*args, &block)
  super
  block.call(self) if block_given?
end

Class Method Details

+ (String) write(*args, &block)

Returns:

  • (String)


8
9
10
11
# File 'lib/openpgp/buffer.rb', line 8

def self.write(*args, &block)
  buffer = self.new(*args, &block)
  buffer.string
end

Instance Method Details

- (String) read_byte

Returns:

  • (String)


130
131
132
# File 'lib/openpgp/buffer.rb', line 130

def read_byte
  getbyte
end

- (String) read_bytes(count)

Parameters:

  • (Integer) count

Returns:

  • (String)


117
118
119
# File 'lib/openpgp/buffer.rb', line 117

def read_bytes(count)
  read(count)
end

- (String) read_mpi



75
76
77
78
79
# File 'lib/openpgp/buffer.rb', line 75

def read_mpi
  length = read_unpacked(2, 'n')      # length in bits
  length = ((length + 7) / 8.0).floor # length in bytes
  read_bytes(length)
end

- (Integer) read_number(count, base = nil)

Parameters:

  • (Integer) count
  • (Integer) base (defaults to: nil)

Returns:

  • (Integer)

See Also:



56
57
58
59
60
61
62
# File 'lib/openpgp/buffer.rb', line 56

def read_number(count, base = nil)
  number, shift = 0, count * 8
  read_bytes(count).each_byte do |octet|
    number += octet << (shift -= 8)
  end
  !base ? number : number.to_s(base).upcase
end

- (S2K) read_s2k



92
# File 'lib/openpgp/buffer.rb', line 92

def read_s2k()     S2K.parse(self) end

- (String) read_string

Returns:

  • (String)


23
24
25
# File 'lib/openpgp/buffer.rb', line 23

def read_string
  read_bytes(length = read_byte)
end

- (Integer) read_timestamp

Returns:

  • (Integer)

See Also:



39
40
41
# File 'lib/openpgp/buffer.rb', line 39

def read_timestamp
  read_unpacked(4, 'N')
end

- (Integer) read_unpacked(count, format)

Parameters:

  • (Integer) count
  • (String) format

Returns:

  • (Integer)


103
104
105
# File 'lib/openpgp/buffer.rb', line 103

def read_unpacked(count, format)
  read_bytes(count).unpack(format).first
end

- (String) string

Returns:

  • (String)


143
144
145
146
147
# File 'lib/openpgp/buffer.rb', line 143

def string
  string = super
  string.force_encoding(Encoding::ASCII_8BIT) if string.respond_to?(:force_encoding)
  string
end

- (Buffer) write_byte(value)

Parameters:

  • (#chr, #to_s) value

Returns:



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

def write_byte(value)
  self << (value.respond_to?(:chr) ? value : value.to_s[0]).chr
end

- (Buffer) write_bytes(value)

Parameters:

  • (String) value

Returns:



124
125
126
# File 'lib/openpgp/buffer.rb', line 124

def write_bytes(value)
  self << value
end

- (Buffer) write_mpi

Parameters:

  • (String) value

Returns:

See Also:



85
86
87
# File 'lib/openpgp/buffer.rb', line 85

def write_mpi
  # TODO
end

- (Buffer) write_number

Parameters:

  • (Integer) value

Returns:

See Also:



68
69
70
# File 'lib/openpgp/buffer.rb', line 68

def write_number
  # TODO
end

- (Buffer) write_s2k(s2k)

Parameters:

Returns:



97
# File 'lib/openpgp/buffer.rb', line 97

def write_s2k(s2k) s2k.write(self) end

- (Buffer) write_string(value)

Parameters:

  • (String, #to_s) value

Returns:



30
31
32
33
34
# File 'lib/openpgp/buffer.rb', line 30

def write_string(value)
  value = value.to_s
  self << [value.size].pack('C')
  self << value unless value.empty?
end

- (Buffer) write_timestamp(value)

Parameters:

  • (Integer, #to_i) value

Returns:

See Also:



47
48
49
# File 'lib/openpgp/buffer.rb', line 47

def write_timestamp(value)
  self << [value.to_i].pack('N')
end

- (Buffer) write_unpacked

Parameters:

  • (Integer) value

Returns:



110
111
112
# File 'lib/openpgp/buffer.rb', line 110

def write_unpacked
  # TODO
end