Class: Dnsruby::RR::NXT
- Inherits:
-
Dnsruby::RR
- Object
- Dnsruby::RR
- Dnsruby::RR::NXT
- Defined in:
- lib/dnsruby/resource/NXT.rb
Overview
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.
Defined Under Namespace
Modules: NxtTypes Classes: TypeBitmap
Constant Summary collapse
- REQUIRED_KEYS =
[:next_domain, :types]
Constants inherited from Dnsruby::RR
Instance Attribute Summary collapse
-
#next_domain ⇒ Object
Returns the value of attribute next_domain.
-
#types ⇒ Object
Returns the value of attribute types.
Attributes inherited from Dnsruby::RR
#klass, #name, #rdata, #ttl, #type
Class Method Summary collapse
-
.build_rdata(next_domain, types) ⇒ Object
Builds rdata from the provided information.
- .decode_rdata(message_decoder) ⇒ Object
-
.new_from_data(*params_data) ⇒ Object
Create an instance from an ordered parameter list, e.g.: rdata = RR::NXT.build_rdata(‘a.dnsruby.com.’, [Types::SOA, Types::NXT]).
-
.new_from_hash(params_hash) ⇒ Object
Create an instance from a hash of parameters, e.g.:.
-
.new_from_string(params_string) ⇒ Object
Create an instance from a string containing parameters, e.g.: b.dnsruby.com.
Instance Method Summary collapse
- #build_rdata ⇒ Object
- #encode_rdata(message_encoder, _canonical) ⇒ Object
- #from_data(data) ⇒ Object
- #from_hash(params_hash) ⇒ Object
- #from_string(string) ⇒ Object
-
#rdata_to_string ⇒ Object
From the RFC: NXT has the following format: foo.nil.
Methods inherited from Dnsruby::RR
#<=>, #==, #clone, create, #eql?, find_class, get_class, get_num, #hash, implemented_rrs, #init_defaults, #rdlength, #sameRRset, #to_s
Instance Attribute Details
#next_domain ⇒ Object
Returns the value of attribute next_domain.
29 30 31 |
# File 'lib/dnsruby/resource/NXT.rb', line 29 def next_domain @next_domain end |
#types ⇒ Object
Returns the value of attribute types.
29 30 31 |
# File 'lib/dnsruby/resource/NXT.rb', line 29 def types @types end |
Class Method Details
.build_rdata(next_domain, types) ⇒ Object
Builds rdata from the provided information.
94 95 96 97 98 99 100 101 102 |
# 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 = ''.b binary_string << next_domain.canonical binary_string << BitMapping.reverse_binary_string_bits(types.to_binary_string) binary_string end |
.decode_rdata(message_decoder) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/dnsruby/resource/NXT.rb', line 122 def self.decode_rdata() start_index = .index rdata_len = -> do rdata_length_str = .data[start_index - 2, 2] rdata_length_str.unpack('n').first end next_domain_and_bitmap = -> do next_domain = .get_name bitmap_start_index = .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 \ ? .data.size \ : rdata_len.() - (bitmap_start_index - start_index) bitmap = .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) ⇒ Object
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)
86 87 88 |
# 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) ⇒ Object
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.
70 71 72 73 |
# 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) ⇒ Object
Create an instance from a string containing parameters, e.g.: b.dnsruby.com. 10800 IN NXT A.dnsruby.com. SOA NXT
77 78 79 |
# File 'lib/dnsruby/resource/NXT.rb', line 77 def self.new_from_string(params_string) RR.new_from_string(params_string) end |
Instance Method Details
#build_rdata ⇒ Object
118 119 120 |
# File 'lib/dnsruby/resource/NXT.rb', line 118 def build_rdata self.class.build_rdata(next_domain, types) end |
#encode_rdata(message_encoder, _canonical) ⇒ Object
114 115 116 |
# File 'lib/dnsruby/resource/NXT.rb', line 114 def encode_rdata(, _canonical) .put_bytes(build_rdata) end |
#from_data(data) ⇒ Object
41 42 43 44 |
# 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) ⇒ Object
33 34 35 36 37 38 39 |
# 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) ⇒ Object
46 47 48 49 50 |
# 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 ⇒ Object
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.
110 111 112 |
# File 'lib/dnsruby/resource/NXT.rb', line 110 def rdata_to_string "#{next_domain} #{NxtTypes.codes_to_names(types).join(' ')}" end |