class OpenPGP::Buffer

Public Class Methods

new(*args, &block) click to toggle source

@yield [buffer] @yieldparam [Buffer] buffer

Calls superclass method
# File lib/openpgp/buffer.rb, line 16
def initialize(*args, &block)
  super
  block.call(self) if block_given?
end
write(*args, &block) click to toggle source

@return [String]

# File lib/openpgp/buffer.rb, line 8
def self.write(*args, &block)
  buffer = self.new(*args, &block)
  buffer.string
end

Public Instance Methods

read_byte() click to toggle source

@return [String]

# File lib/openpgp/buffer.rb, line 130
def read_byte
  getbyte
end
read_bytes(count) click to toggle source

@param [Integer] count @return [String]

# File lib/openpgp/buffer.rb, line 117
def read_bytes(count)
  read(count)
end
read_mpi() click to toggle source

@return [String] @see tools.ietf.org/html/rfc4880#section-3.2

# 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
read_number(count, base = nil) click to toggle source

@param [Integer] count @param [Integer] base @return [Integer] @see tools.ietf.org/html/rfc4880#section-3.1

# 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
read_s2k() click to toggle source

@return [S2K] @see tools.ietf.org/html/rfc4880#section-3.7

# File lib/openpgp/buffer.rb, line 92
def read_s2k()     S2K.parse(self) end
read_string() click to toggle source

@return [String]

# File lib/openpgp/buffer.rb, line 23
def read_string
  read_bytes(length = read_byte)
end
read_timestamp() click to toggle source

@return [Integer] @see tools.ietf.org/html/rfc4880#section-3.5

# File lib/openpgp/buffer.rb, line 39
def read_timestamp
  read_unpacked(4, 'N')
end
read_unpacked(count, format) click to toggle source

@param [Integer] count @param [String] format @return [Integer]

# File lib/openpgp/buffer.rb, line 103
def read_unpacked(count, format)
  read_bytes(count).unpack(format).first
end
string() click to toggle source

@return [String]

Calls superclass method
# 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
write_byte(value) click to toggle source

@param [#chr, to_s] value @return [Buffer]

# File lib/openpgp/buffer.rb, line 137
def write_byte(value)
  self << (value.respond_to?(:chr) ? value : value.to_s[0]).chr
end
write_bytes(value) click to toggle source

@param [String] value @return [Buffer]

# File lib/openpgp/buffer.rb, line 124
def write_bytes(value)
  self << value
end
write_mpi() click to toggle source

@param [String] value @return [Buffer] @see tools.ietf.org/html/rfc4880#section-3.2

# File lib/openpgp/buffer.rb, line 85
def write_mpi
  # TODO
end
write_number() click to toggle source

@param [Integer] value @return [Buffer] @see tools.ietf.org/html/rfc4880#section-3.1

# File lib/openpgp/buffer.rb, line 68
def write_number
  # TODO
end
write_s2k(s2k) click to toggle source

@param [S2K] s2k @return [Buffer]

# File lib/openpgp/buffer.rb, line 97
def write_s2k(s2k) s2k.write(self) end
write_string(value) click to toggle source

@param [String, to_s] value @return [Buffer]

# 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
write_timestamp(value) click to toggle source

@param [Integer, to_i] value @return [Buffer] @see tools.ietf.org/html/rfc4880#section-3.5

# File lib/openpgp/buffer.rb, line 47
def write_timestamp(value)
  self << [value.to_i].pack('N')
end
write_unpacked() click to toggle source

@param [Integer] value @return [Buffer]

# File lib/openpgp/buffer.rb, line 110
def write_unpacked
  # TODO
end