Class: Dnsruby::RR::CAA
- Inherits:
-
RR
- Object
- RR
- Dnsruby::RR::CAA
- Defined in:
- lib/dnsruby/resource/CAA.rb
Overview
Class for CAA resource records. RFC 8659
Constant Summary collapse
Instance Attribute Summary collapse
-
#property_tag ⇒ Object
The property tag.
-
#property_value ⇒ Object
The value for the property_tag.
Class Method Summary collapse
-
.decode_rdata(msg) ⇒ Object
:nodoc: all.
Instance Method Summary collapse
-
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all.
- #flag ⇒ Object
-
#flag=(value) ⇒ Object
The value for the flag.
-
#from_data(data) ⇒ Object
:nodoc: all.
-
#from_hash(hash) ⇒ Object
:nodoc: all.
-
#from_string(input) ⇒ Object
:nodoc: all.
-
#rdata_to_string ⇒ Object
:nodoc: all.
Instance Attribute Details
#property_tag ⇒ Object
The property tag. Tags are extensible ASCII letters and digits.
25 26 27 |
# File 'lib/dnsruby/resource/CAA.rb', line 25 def property_tag @property_tag end |
#property_value ⇒ Object
The value for the property_tag
27 28 29 |
# File 'lib/dnsruby/resource/CAA.rb', line 27 def property_value @property_value end |
Class Method Details
.decode_rdata(msg) ⇒ Object
:nodoc: all
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dnsruby/resource/CAA.rb', line 79 def self.decode_rdata(msg) #:nodoc: all flag, = msg.get_unpack('C') property_tag = msg.get_string # The final string has no length byte - its length is implicit as the remainder of the packet length property_value = msg.get_bytes record = self.new([flag, property_tag, property_value]) # Keep the public construction-time rdata String used by Comparable # and older serializers, without reparsing arbitrary wire value bytes. record.rdata = record.rdata_to_string record end |
Instance Method Details
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all
71 72 73 74 75 76 77 |
# File 'lib/dnsruby/resource/CAA.rb', line 71 def encode_rdata(msg, canonical=false) #:nodoc: all validate_fields msg.put_pack('C', flag) msg.put_string(@property_tag) # We don't put a length byte on the final string. msg.put_bytes(@property_value) end |
#flag ⇒ Object
43 44 45 |
# File 'lib/dnsruby/resource/CAA.rb', line 43 def flag @flag.to_i end |
#flag=(value) ⇒ Object
The value for the flag
29 30 31 |
# File 'lib/dnsruby/resource/CAA.rb', line 29 def flag=(value) @flag = value.to_i end |
#from_data(data) ⇒ Object
:nodoc: all
37 38 39 40 41 |
# File 'lib/dnsruby/resource/CAA.rb', line 37 def from_data(data) #:nodoc: all flag, @property_tag, @property_value = data self.flag = flag validate_fields end |
#from_hash(hash) ⇒ Object
:nodoc: all
33 34 35 |
# File 'lib/dnsruby/resource/CAA.rb', line 33 def from_hash(hash) #:nodoc: all from_data([hash[:flag], hash[:property_tag], hash[:property_value]]) end |
#from_string(input) ⇒ Object
:nodoc: all
47 48 49 50 51 52 53 54 55 |
# File 'lib/dnsruby/resource/CAA.rb', line 47 def from_string(input) #:nodoc: all # A CAA value is one character-string, with no 255-octet limit. matches = /\A\s*(\d+)\s+([A-Za-z0-9]+)\s+("(?:\\.|[^"\\])*"|(?:\\.|[^\s"\\])+)\s*\z/m.match(input.b) raise DecodeError, "Cannot parse CAA record: #{input[0...1000]}" unless matches value = matches[3] value = value[1...-1] if value.start_with?('"') from_data([matches[1], matches[2], decode_value(value)]) end |
#rdata_to_string ⇒ Object
:nodoc: all
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dnsruby/resource/CAA.rb', line 57 def rdata_to_string #:nodoc: all value = +''.b @property_value.each_byte do |octet| if octet == 34 || octet == 92 value << 92 << octet elsif octet < 32 || octet > 126 value << format('\\%03d', octet) else value << octet end end "#{flag} #{@property_tag} \"#{value}\"" end |