dns-zonefile 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e03fd7e584a66f2ad1dfa8b55214bb4c84e2eacce69cb99d4717b195fccff9d
4
- data.tar.gz: 64727fe7326f916e0b49d25bc662285220b3c6bc77c2cdc161ea6baaa36d912f
3
+ metadata.gz: dd9e724e734aee2290ed838fd531986b9023f8240fcbd94d2ed150de8a15d108
4
+ data.tar.gz: 69ddce22ad9489e91395a237b69c06d1ae836cc6bb91af9b5cf0ae35d79dfb57
5
5
  SHA512:
6
- metadata.gz: def79e0087a99c705347dca181448696cbc0d44587c111241128c8b56250847505cefe5b34661fd6ebe26952b14ef037a86ab9d031ce7164cfa1bde06d4cbefc
7
- data.tar.gz: 9106004e78e04153b04f94b5e054595faad619804c8584192d7b2ea328128cbb1306cc1098dce919df50f7c1d8a2905ad13432959896913e3d394b12ac3943db
6
+ metadata.gz: 9eb5b44b4ac7f3087caa36d67fa4393a3c91e6380fa825cddaaf9b91e3000e619d89d354d7117f9b4914b3189a087539aa4954a9bdf80c9ac3199735ef163d35
7
+ data.tar.gz: ef00e8c2abc08e5c47e6105a4530741621b2798b693ebe4a30cbc20880640623d352754465f2aa2eb30321e17fcbbc91009c1fa1602a1413a5c5aced8065f3bd
@@ -1,5 +1,5 @@
1
1
  module DNS
2
2
  module Zonefile
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
data/lib/dns/zonefile.rb CHANGED
@@ -52,6 +52,8 @@ module DNS
52
52
  when "SRV" then @records << SRV.new(@vars, e)
53
53
  when "SPF" then @records << SPF.new(@vars, e)
54
54
  when "SSHFP" then @records << SSHFP.new(@vars, e)
55
+ when "SVCB" then @records << SVCB.new(@vars, e)
56
+ when "HTTPS" then @records << HTTPS.new(@vars, e)
55
57
  when "TLSA" then @records << TLSA.new(@vars, e)
56
58
  when "TXT" then @records << TXT.new(@vars, e)
57
59
  when "SOA" then
@@ -287,6 +289,42 @@ module DNS
287
289
  end
288
290
  end
289
291
 
292
+ class SVCB < Record
293
+ attr_accessor :host, :priority, :target_name
294
+ attr_reader :svcparams
295
+
296
+ def initialize(vars, zonefile_record)
297
+ @vars = vars
298
+ if zonefile_record
299
+ self.host = qualify_host(zonefile_record.host.to_s)
300
+ @vars[:last_host] = host
301
+ self.ttl = zonefile_record.ttl.to_i
302
+ self.klass = zonefile_record.klass.to_s
303
+ self.priority = zonefile_record.priority.to_i
304
+ self.target_name = zonefile_record.target.to_s == "." ? "." : qualify_host(zonefile_record.target.to_s)
305
+ @svcparams = parse_svcparams(zonefile_record.svcparams.to_s)
306
+ else
307
+ @svcparams = {}
308
+ end
309
+ end
310
+
311
+ # Parses SvcParams string (e.g. "alpn=h2,h3 ipv4hint=192.0.2.1") into a Hash of name => value.
312
+ # Handles quoted values (e.g. ech="base64...").
313
+ def parse_svcparams(str)
314
+ return {} if str.to_s.strip.empty?
315
+
316
+ # Key is word chars + hyphen; value is either "quoted" (with \ " and \ \ escapes) or unquoted (no spaces)
317
+ str.strip.scan(/([\w-]+)=(?:"((?:[^"\\]|\\.)*)"|([^\s]*))|([\w-]+)(?=\s|$)/).each_with_object({}) do |(key_with_val, quoted, unquoted, key_only), params|
318
+ key = key_with_val || key_only
319
+ value = quoted ? quoted.gsub(/\\"/, '"').gsub(/\\\\/, '\\') : (unquoted || "")
320
+ params[key] = value
321
+ end
322
+ end
323
+ end
324
+
325
+ class HTTPS < SVCB
326
+ end
327
+
290
328
  class TLSA < Record
291
329
  attr_accessor :host, :usage, :selector, :matching_type, :certificate_data
292
330
 
@@ -56,7 +56,7 @@ grammar Zonefile
56
56
  end
57
57
 
58
58
  rule resource_record
59
- record:(a_record / aaaa_record / caa_record / cname_record / mx_record / naptr_record / ns_record / ptr_record / srv_record / spf_record / sshfp_record / tlsa_record / txt_record / soa_record) space* comment? linebreak {
59
+ record:(a_record / aaaa_record / caa_record / cname_record / mx_record / naptr_record / ns_record / ptr_record / srv_record / spf_record / sshfp_record / svcb_record / https_record / tlsa_record / txt_record / soa_record) space* comment? linebreak {
60
60
  def zone
61
61
  p = parent
62
62
  while p.respond_to?(:parent) && p.parent
@@ -299,6 +299,66 @@ grammar Zonefile
299
299
  }
300
300
  end
301
301
 
302
+ rule svcb_record
303
+ (
304
+ host space ms_age ttl klass "SVCB" space priority:integer space target:svcb_target space svcparam_data:svcb_svcparams /
305
+ host space ms_age klass ttl "SVCB" space priority:integer space target:svcb_target space svcparam_data:svcb_svcparams /
306
+ host space ms_age ttl klass "SVCB" space priority:integer space target:svcb_target /
307
+ host space ms_age klass ttl "SVCB" space priority:integer space target:svcb_target
308
+ ) {
309
+ def to_s
310
+ base = "#{host} #{ttl} #{klass} SVCB #{priority} #{target}"
311
+ respond_to?(:svcparam_data) && svcparam_data ? "#{base} #{svcparam_data}" : base
312
+ end
313
+
314
+ def record_type
315
+ "SVCB"
316
+ end
317
+
318
+ def svcparams
319
+ (respond_to?(:svcparam_data) && svcparam_data) ? svcparam_data.to_s.strip : ""
320
+ end
321
+ }
322
+ end
323
+
324
+ rule https_record
325
+ (
326
+ host space ms_age ttl klass "HTTPS" space priority:integer space target:svcb_target space svcparam_data:svcb_svcparams /
327
+ host space ms_age klass ttl "HTTPS" space priority:integer space target:svcb_target space svcparam_data:svcb_svcparams /
328
+ host space ms_age ttl klass "HTTPS" space priority:integer space target:svcb_target /
329
+ host space ms_age klass ttl "HTTPS" space priority:integer space target:svcb_target
330
+ ) {
331
+ def to_s
332
+ base = "#{host} #{ttl} #{klass} HTTPS #{priority} #{target}"
333
+ respond_to?(:svcparam_data) && svcparam_data ? "#{base} #{svcparam_data}" : base
334
+ end
335
+
336
+ def record_type
337
+ "HTTPS"
338
+ end
339
+
340
+ def svcparams
341
+ (respond_to?(:svcparam_data) && svcparam_data) ? svcparam_data.to_s.strip : ""
342
+ end
343
+ }
344
+ end
345
+
346
+ rule svcb_target
347
+ ("." / host) {
348
+ def to_s
349
+ text_value
350
+ end
351
+ }
352
+ end
353
+
354
+ rule svcb_svcparams
355
+ [^;\n\r]+ {
356
+ def to_s
357
+ text_value.strip
358
+ end
359
+ }
360
+ end
361
+
302
362
  rule tlsa_record
303
363
  (
304
364
  host space ms_age ttl klass "TLSA" space usage:integer space selector:integer space matching_type:integer space certificate_data:tlsa_certificate_data /
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns-zonefile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig R Webster