Class: Resolv::DNS::Message::MessageEncoder
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/resolv.rb |
Class Method Summary
- .new {|_self| ... } ⇒ MessageEncoder constructor
Instance Method Summary
Constructor Details
.new {|_self| ... } ⇒ MessageEncoder
# File 'lib/resolv.rb', line 1607
def initialize @data = ''.dup @names = {} yield self end
Instance Method Details
#put_bytes(d)
[ GitHub ]# File 'lib/resolv.rb', line 1617
def put_bytes(d) @data << d end
#put_label(d)
[ GitHub ]# File 'lib/resolv.rb', line 1672
def put_label(d) s = d.to_s # Label::Str applies this limit when a label is built, so what is left # for here is a raw string handed straight to put_labels. The two ways # an over-long label goes wrong differ: 64 to 255 octets write a length # octet in the reserved or compression pointer range, and 256 or more # wrap it mod 256. Either way the encoded name stops being the name the # caller asked for. [RFC 1035 2.3.4, 4.1.4] if s.bytesize > 63 raise ArgumentError, "DNS label is too long (#{s.bytesize} bytes, max 63): #{s.inspect}" end self.put_string(s) end
#put_labels(d, compress: true)
[ GitHub ]#put_length16
[ GitHub ]# File 'lib/resolv.rb', line 1625
def put_length16 length_index = @data.length @data << "\0\0" data_start = @data.length yield data_end = @data.length @data[length_index, 2] = [data_end - data_start].pack("n") end
#put_name(d, compress: true)
[ GitHub ]# File 'lib/resolv.rb', line 1652
def put_name(d, compress: true) put_labels(d.to_a, compress: compress) end
#put_pack(template, *d)
[ GitHub ]# File 'lib/resolv.rb', line 1621
def put_pack(template, *d) @data << d.pack(template) end
#put_string(d)
[ GitHub ]# File 'lib/resolv.rb', line 1634
def put_string(d) s = d.to_s # A character-string is prefixed by a single length octet, so it can # hold at most 255 octets. [RFC 1035 3.3] Reject anything longer to # avoid silently truncating the length to its low 8 bits (mod 256). if s.bytesize > 255 raise ArgumentError, "character-string is too long (#{s.bytesize} bytes, max 255): #{s.inspect}" end self.put_pack("C", s.bytesize) @data << s end
#put_string_list(ds)
[ GitHub ]# File 'lib/resolv.rb', line 1646
def put_string_list(ds) ds.each {|d| self.put_string(d) } end
#to_s
[ GitHub ]# File 'lib/resolv.rb', line 1613
def to_s return @data end