class OpenPGP::Buffer
Public Class Methods
@yield [buffer] @yieldparam [Buffer] buffer
# File lib/openpgp/buffer.rb, line 16 def initialize(*args, &block) super block.call(self) if block_given? end
@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
@return [String]
# File lib/openpgp/buffer.rb, line 130 def read_byte getbyte end
@param [Integer] count @return [String]
# File lib/openpgp/buffer.rb, line 117 def read_bytes(count) read(count) end
@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
@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
@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
@return [String]
# File lib/openpgp/buffer.rb, line 23 def read_string read_bytes(length = read_byte) end
@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
@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
@return [String]
# 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
@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
@param [String] value @return [Buffer]
# File lib/openpgp/buffer.rb, line 124 def write_bytes(value) self << value end
@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
@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
@param [S2K] s2k @return [Buffer]
# File lib/openpgp/buffer.rb, line 97 def write_s2k(s2k) s2k.write(self) end
@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
@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
@param [Integer] value @return [Buffer]
# File lib/openpgp/buffer.rb, line 110 def write_unpacked # TODO end