class Dnsruby::RR::NXT

Class for NXT resource records.

NXT-specific data types, present in RDATA, are:

next_domain: the next domain name, as a Name instance
types: array of record types as numbers

RFC 2535 (www.ietf.org/rfc/rfc2535.txt)

The RFC mentions that a low bit of zero in the type RDATA indicates that the highest type code does not exceed 127, and that a low bit of 1 indicates that some mechanism other than a bitmap is being used. This class does not support such non-bitmap mechanisms, and assumes there will always be a bitmap.

Constants

REQUIRED_KEYS

Attributes

next_domain[RW]
types[RW]

Public Class Methods

build_rdata(next_domain, types) click to toggle source

Builds rdata from the provided information. @param next_domain either a string or a Name @param types an array of types (where each type is the numeric type code)

or a TypeBitmap
# File lib/dnsruby/resource/NXT.rb, line 94
def self.build_rdata(next_domain, types)
  next_domain = Name.create(next_domain) if next_domain.is_a?(String)
  types = TypeBitmap.from_type_codes(types) if types.is_a?(Array)

  binary_string = ''.force_encoding('ASCII-8BIT')
  binary_string << next_domain.canonical
  binary_string << BitMapping.reverse_binary_string_bits(types.to_binary_string)
  binary_string
end
decode_rdata(message_decoder) click to toggle source
# File lib/dnsruby/resource/NXT.rb, line 122
def self.decode_rdata(message_decoder)

  start_index = message_decoder.index

  rdata_len = -> do
    rdata_length_str = message_decoder.data[start_index - 2, 2]
    rdata_length_str.unpack('n').first
  end

  next_domain_and_bitmap = -> do
    next_domain = message_decoder.get_name
    bitmap_start_index = message_decoder.index

    # If we're being called from new_from_data, the MessageDecoder
    # contains only the rdata, not the entire message, and there will
    # be no encoded length for us to read.
    called_from_new_from_data = (start_index == 0)
    bitmap_length = called_from_new_from_data \
        ? message_decoder.data.size \
        : rdata_len.() - (bitmap_start_index - start_index)

    bitmap = message_decoder.get_bytes(bitmap_length)
    bitmap = BitMapping.reverse_binary_string_bits(bitmap)
    [next_domain, bitmap]
  end

  next_domain, type_bitmap = next_domain_and_bitmap.()
  types = TypeBitmap.from_binary_string(type_bitmap).to_type_array
  new(next_domain: next_domain, types: types)
end
new_from_data(*params_data) click to toggle source

Create an instance from an ordered parameter list, e.g.: rdata = RR::NXT.build_rdata('a.dnsruby.com.', [Types::SOA, Types::NXT])

rr = RR::NXT.new_from_data('b.dnsruby.com.', Types::NXT,

Classes::IN, 10800, rdata.size, rdata, 0)
# File lib/dnsruby/resource/NXT.rb, line 86
def self.new_from_data(*params_data)
  RR.new_from_data(*params_data)
end
new_from_hash(params_hash) click to toggle source

Create an instance from a hash of parameters, e.g.:

rr = RR::NXT.new_from_hash(

name: 'b.dnsruby.com.',
ttl: 10800,
klass: Classes::IN,
next_domain: 'a.dnsruby.com.',
types: [Types::SOA, Types::NXT])

Since the type is assumed to be NXT, it will be assigned automatically, and any other value will be overwritten. Therefore, having it present in the hash is not necessary.

# File lib/dnsruby/resource/NXT.rb, line 70
def self.new_from_hash(params_hash)
  params_hash[:type] = Types::NXT
  RR.new_from_hash(params_hash)
end
new_from_string(params_string) click to toggle source

Create an instance from a string containing parameters, e.g.: b.dnsruby.com. 10800 IN NXT A.dnsruby.com. SOA NXT

# File lib/dnsruby/resource/NXT.rb, line 77
def self.new_from_string(params_string)
  RR.new_from_string(params_string)
end

Public Instance Methods

build_rdata() click to toggle source
# File lib/dnsruby/resource/NXT.rb, line 118
def build_rdata
  self.class.build_rdata(next_domain, types)
end
encode_rdata(message_encoder, _canonical) click to toggle source
# File lib/dnsruby/resource/NXT.rb, line 114
def encode_rdata(message_encoder, _canonical)
  message_encoder.put_bytes(build_rdata)
end
from_data(data) click to toggle source
# File lib/dnsruby/resource/NXT.rb, line 41
def from_data(data)
  next_domain, types = data
  from_hash(next_domain: next_domain, types: types)
end
from_hash(params_hash) click to toggle source
# File lib/dnsruby/resource/NXT.rb, line 33
def from_hash(params_hash)
  unless REQUIRED_KEYS.all? { |key| params_hash[key] }
    raise ArgumentError.new("NXT hash must contain all of: #{REQUIRED_KEYS.join(', ')}.")
  end
  @next_domain = Name.create(params_hash[:next_domain]) unless @next_domain.is_a?(Name)
  @types       = params_hash[:types]
end
from_string(string) click to toggle source
# File lib/dnsruby/resource/NXT.rb, line 46
def from_string(string)
  next_domain, *type_names = string.split  # type names are all but first
  types = NxtTypes::names_to_codes(type_names)
  from_hash(next_domain: next_domain, types: types)
end
rdata_to_string() click to toggle source

From the RFC: NXT has the following format: foo.nil. NXT big.foo.nil NS KEY SOA NXT <owner> NXT <next_domain> <record types>

We handle the rdata, the RR superclass does the rest.

# File lib/dnsruby/resource/NXT.rb, line 110
def rdata_to_string
  "#{next_domain} #{NxtTypes.codes_to_names(types).join(' ')}"
end