svcb_rr_patch 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 607172ae2b63afd7c66a3cfe87456873eb1f436c28f0380a52edeeb31d9f3902
4
- data.tar.gz: b8a3b83f4820b78fb3efcb27b675a3cf07a58f360fe7d3c3a93fdd7161ced077
3
+ metadata.gz: c3af5857ef38bc6a54ad9abedb5c1227ea008b56e049393d16277103cba4b823
4
+ data.tar.gz: 8a9152efcf7694b8e6ace3a2fce298854f4020292b3f880c2ec9da4d19b8f25b
5
5
  SHA512:
6
- metadata.gz: 7125f6c9205f872a12574801bf5026073cd4d028640afbaefdf2a2ee69f11cc832167d4612341c475605306705af0742bb724fc241f482c85af8fe1e8a4f61d1
7
- data.tar.gz: 9217eca73420740086db7877bd5ff05e024ece6f6ecda1ad0d6b30e50cb1966da733b32f3daab8518a1180d25c6a0de1a8c7dab4105e132e186ae21a956e419b
6
+ metadata.gz: 912e4053675275418be0a343010b56e00e912c42ea20f24c89877f6754ee246231a91884e10ae62756185e0e64fc0c030fcdb019203a038088087e27f0d6c3fc
7
+ data.tar.gz: d56504d2fc39255d4ed9dc805d478b05054251af35b89384db816d340b1c22e400b531b9bee63865776d05fb550f3ec846eb8b0235412fb357776e6fedc284eb
data/README.md CHANGED
@@ -36,10 +36,36 @@ irb(main):004:1* Resolv::DNS::Resource::IN::HTTPS
36
36
  irb(main):005:0> )
37
37
  =>
38
38
  [#<Resolv::DNS::Resource::IN::HTTPS:0x0000000000000001
39
- @svc_params={"alpn"=>h3,h3-29,h3-28,h3-27,h2, "ipv4hint"=>104.18.26.46,104.18.27.46, "ipv6hint"=>2606:4700::6812:1a2e,2606:4700::6812:1b2e},
39
+ @svc_params=
40
+ #<SvcbRrPatch::SvcParams::Hash:0x0000000000000002
41
+ @hash=
42
+ {"alpn"=>#<SvcbRrPatch::SvcParams::Alpn:0x0000000000000003 @protocols=["http/1.1", "h2"]>,
43
+ "ipv4hint"=>#<SvcbRrPatch::SvcParams::Ipv4hint:0x0000000000000004 @addresses=[#<Resolv::IPv4 162.159.137.85>, #<Resolv::IPv4 162.159.138.85>]>,
44
+ "ech"=>
45
+ #<SvcbRrPatch::SvcParams::Ech:0x0000000000000005
46
+ @echconfiglist=
47
+ [#<SvcbRrPatch::SvcParams::Ech::ECHConfig:0x0000000000000006
48
+ @echconfig_contents=
49
+ #<SvcbRrPatch::SvcParams::Ech::ECHConfigContents:0x0000000000000007
50
+ @extensions=[],
51
+ @key_config=
52
+ #<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig:0x0000000000000008
53
+ @cipher_suites=
54
+ [#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite:0x0000000000000009
55
+ @aead_id=#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite::HpkeAeadId:0x0000000000000010 @uint16=1>,
56
+ @kdf_id=#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite::HpkeKdfId:0x0000000000000011 @uint16=1>>],
57
+ @config_id=238,
58
+ @kem_id=#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeKemId:0x0000000000000012 @uint16=32>,
59
+ @public_key=
60
+ #<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkePublicKey:0x0000000000000013
61
+ @opaque="I\x19\xD0\xCFP\b>e\xDF\xE1Q\xE8+i\x89\x8AJ\xA2b'\xD0j\xB9+\xDE\xE2\xDE\xF8\xFA\xAD\xBBm">>,
62
+ @maximum_name_length=0,
63
+ @public_name="cloudflare-esni.com">,
64
+ @version="\xFE\r">]>,
65
+ "ipv6hint"=>#<SvcbRrPatch::SvcParams::Ipv6hint:0x0000000000000014 @addresses=[#<Resolv::IPv6 2606:4700:7::a29f:8955>, #<Resolv::IPv6 2606:4700:7::a29f:8a55>]>}>,
40
66
  @svc_priority=1,
41
67
  @target_name="",
42
- @ttl=300>]
68
+ @ttl=58>]
43
69
  ```
44
70
 
45
71
 
@@ -21,7 +21,7 @@ class Resolv::DNS::Resource::IN::HTTPS < Resolv::DNS::Resource::IN::SVCB
21
21
  return new(svc_priority, target_name, {}) if svc_priority.zero?
22
22
 
23
23
  # the SvcParams, consuming the remainder of the record
24
- svc_params = ::SvcbRrPatch::SvcParams.decode(msg.get_bytes)
24
+ svc_params = ::SvcbRrPatch::SvcParams::Hash.decode(msg.get_bytes)
25
25
  new(svc_priority, target_name, svc_params)
26
26
  end
27
27
  end
@@ -37,7 +37,7 @@ class SvcbRrPatch::SvcParams::Alpn
37
37
  end
38
38
 
39
39
  # :nodoc:
40
- def inspect
40
+ def to_s
41
41
  @protocols.join(',')
42
42
  end
43
43
  end
@@ -25,7 +25,7 @@ class SvcbRrPatch::SvcParams::Ech
25
25
  # https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06#section-9
26
26
  # In presentation format, the value is a single ECHConfigList encoded in
27
27
  # Base64.
28
- def inspect
28
+ def to_s
29
29
  Base64.strict_encode64(encode)
30
30
  end
31
31
  end
@@ -20,7 +20,7 @@ class SvcbRrPatch::SvcParams::Ipv4hint
20
20
  end
21
21
 
22
22
  # :nodoc:
23
- def inspect
23
+ def to_s
24
24
  @addresses.join(',')
25
25
  end
26
26
  end
@@ -20,7 +20,7 @@ class SvcbRrPatch::SvcParams::Ipv6hint
20
20
  end
21
21
 
22
22
  # :nodoc:
23
- def inspect
23
+ def to_s
24
24
  @addresses.join(',')
25
25
  end
26
26
  end
@@ -17,18 +17,12 @@ class SvcbRrPatch::SvcParams::Mandatory
17
17
  def self.decode(octet)
18
18
  keys = octet.scan(/.{1,2}/)
19
19
  .map { |s| s.unpack1('n') }
20
- .filter { |i| i < 7 || i >= 65280 && i < 65535 }
21
20
  new(keys)
22
21
  end
23
22
 
24
23
  # :nodoc:
25
- def inspect
26
- @keys.map do |i|
27
- if i < 7 || i >= 65280 && i < 65535
28
- SvcbRrPatch::SvcParams::PARAMETER_REGISTRY[i]
29
- else
30
- ''
31
- end
32
- end.join(',')
24
+ def to_s
25
+ @keys.map { |i| SvcbRrPatch::SvcParams::PARAMETER_REGISTRY[i] }
26
+ .join(',')
33
27
  end
34
28
  end
@@ -20,7 +20,7 @@ class SvcbRrPatch::SvcParams::Port
20
20
  end
21
21
 
22
22
  # :nodoc:
23
- def inspect
23
+ def to_s
24
24
  @port.to_s
25
25
  end
26
26
  end
@@ -12,85 +12,109 @@ module SvcbRrPatch::SvcParams
12
12
  ipv6hint
13
13
  ]
14
14
  # rubocop:disable Security/Eval
15
+ (8...65280).each do |nnnn|
16
+ eval "registry[nnnn] = \"undefine#{nnnn}\"", binding, __FILE__, __LINE__
17
+ end
15
18
  (65280...65535).each do |nnnn|
16
19
  eval "registry[nnnn] = \"key#{nnnn}\"", binding, __FILE__, __LINE__
17
20
  end
18
21
  # rubocop:enable Security/Eval
19
22
  registry
20
23
  }.call.freeze
24
+
25
+ PARAMETER_REGISTRY_INVERT = lambda {
26
+ Hash[(0..PARAMETER_REGISTRY.size - 1).zip(PARAMETER_REGISTRY)].invert
27
+ }.call.freeze
21
28
  end
22
29
 
23
30
  Dir[File.dirname(__FILE__) + '/svc_params/*.rb'].sort.each { |f| require f }
24
31
 
25
32
  module SvcbRrPatch::SvcParams
26
- # @return [String]
27
- def self.encode(svc_params)
28
- h = Hash[(0..PARAMETER_REGISTRY.size - 1).zip(PARAMETER_REGISTRY)].invert
33
+ class Hash
34
+ def initialize(hash)
35
+ @hash = hash
36
+ end
29
37
 
30
- svc_params
31
- .map { |k, v| [h[k], v] }
32
- .sort { |lh, rh| lh.first <=> rh.first }
33
- .map do |k, v|
34
- [k].pack('n') + v.encode.then { |s| [s.length].pack('n') + s }
35
- end
36
- .join
37
- end
38
+ # @return [String]
39
+ def encode
40
+ @hash
41
+ .map { |k, v| [PARAMETER_REGISTRY_INVERT[k], v] }
42
+ .sort { |lh, rh| lh.first <=> rh.first }
43
+ .map do |k, v|
44
+ [k].pack('n') + v.encode.then { |s| [s.length].pack('n') + s }
45
+ end
46
+ .join
47
+ end
48
+
49
+ # @param octet [String]
50
+ #
51
+ # @return [Hash]
52
+ def self.decode(octet)
53
+ svc_params = {}
54
+ i = 0
55
+ while i < octet.length
56
+ raise ::Resolv::DNS::DecodeError if i + 4 > octet.length
38
57
 
39
- # @param octet [String]
40
- #
41
- # @return [Hash] Integer => SvcbRrPatch::$Object
42
- # rubocop:disable Metrics/AbcSize
43
- def self.decode(octet)
44
- svc_params = {}
45
- i = 0
46
- h = Hash[(0..PARAMETER_REGISTRY.size - 1).zip(PARAMETER_REGISTRY)].invert
47
- while i < octet.length
48
- raise ::Resolv::DNS::DecodeError if i + 4 > octet.length
58
+ k = octet.slice(i, 2).unpack1('n')
59
+ # SvcParamKeys SHALL appear in increasing numeric order.
60
+ raise ::Resolv::DNS::DecodeError unless svc_params.keys.find do |key|
61
+ PARAMETER_REGISTRY_INVERT[key] >= k
62
+ end.nil?
49
63
 
50
- k = octet.slice(i, 2).unpack1('n')
51
- # SvcParamKeys SHALL appear in increasing numeric order.
52
- raise ::Resolv::DNS::DecodeError \
53
- unless svc_params.keys.find { |already| h[already] >= k }.nil?
64
+ i += 2
65
+ vlen = octet.slice(i, 2).unpack1('n')
66
+ i += 2
67
+ raise ::Resolv::DNS::DecodeError if i + vlen > octet.length
54
68
 
55
- i += 2
56
- vlen = octet.slice(i, 2).unpack1('n')
57
- i += 2
58
- raise ::Resolv::DNS::DecodeError if i + vlen > octet.length
69
+ v = octet.slice(i, vlen)
70
+ i += vlen
71
+ # Values are in a format specific to the SvcParamKey.
72
+ svc_param_key = PARAMETER_REGISTRY[k]
73
+ svc_param_values = decode_svc_params(svc_param_key, v)
74
+ svc_params.store(svc_param_key, svc_param_values)
75
+ end
76
+ raise ::Resolv::DNS::DecodeError if i != octet.length
59
77
 
60
- v = octet.slice(i, vlen)
61
- i += vlen
62
- # Values are in a format specific to the SvcParamKey.
63
- svc_param_key = PARAMETER_REGISTRY[k]
64
- svc_param_values = decode_svc_params(svc_param_key, v)
65
- svc_params.store(svc_param_key, svc_param_values)
78
+ new(svc_params)
66
79
  end
67
- raise ::Resolv::DNS::DecodeError if i != octet.length
68
80
 
69
- svc_params
70
- end
71
- # rubocop:enable Metrics/AbcSize
81
+ # :nodoc:
82
+ # rubocop:disable Metrics/CyclomaticComplexity
83
+ def self.decode_svc_params(key, octet)
84
+ case key
85
+ when 'mandatory'
86
+ Mandatory.decode(octet)
87
+ when 'alpn'
88
+ Alpn.decode(octet)
89
+ when 'no-default-alpn'
90
+ NoDefaultAlpn.decode(octet)
91
+ when 'port'
92
+ Port.decode(octet)
93
+ when 'ipv4hint'
94
+ Ipv4hint.decode(octet)
95
+ when 'ech'
96
+ Ech.decode(octet)
97
+ when 'ipv6hint'
98
+ Ipv6hint.decode(octet)
99
+ else
100
+ octet
101
+ end
102
+ end
103
+ # rubocop:enable Metrics/CyclomaticComplexity
104
+
105
+ # :nodoc:
106
+ def [](key)
107
+ @hash[key]
108
+ end
109
+
110
+ # :nodoc:
111
+ def keys
112
+ @hash.keys
113
+ end
72
114
 
73
- # :nodoc:
74
- # rubocop:disable Metrics/CyclomaticComplexity
75
- def self.decode_svc_params(key, octet)
76
- case key
77
- when 'mandatory'
78
- Mandatory.decode(octet)
79
- when 'alpn'
80
- Alpn.decode(octet)
81
- when 'no-default-alpn'
82
- NoDefaultAlpn.decode(octet)
83
- when 'port'
84
- Port.decode(octet)
85
- when 'ipv4hint'
86
- Ipv4hint.decode(octet)
87
- when 'ech'
88
- Ech.decode(octet)
89
- when 'ipv6hint'
90
- Ipv6hint.decode(octet)
91
- else
92
- octet
115
+ # :nodoc:
116
+ def to_s
117
+ @hash.map { |k, v| "#{k}=#{v}" }.join(' ')
93
118
  end
94
119
  end
95
- # rubocop:enable Metrics/CyclomaticComplexity
96
120
  end
@@ -10,7 +10,7 @@ class Resolv::DNS::Resource::IN::SVCB < Resolv::DNS::Resource
10
10
 
11
11
  # @param svc_priority [Integer]
12
12
  # @param target_name [String]
13
- # @param svc_params [Map]
13
+ # @param svc_params [Hash]
14
14
  def initialize(svc_priority, target_name, svc_params)
15
15
  # https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06
16
16
  @svc_priority = svc_priority
@@ -37,7 +37,7 @@ class Resolv::DNS::Resource::IN::SVCB < Resolv::DNS::Resource
37
37
  def encode_rdata(msg)
38
38
  msg.put_bytes([@svc_priority].pack('n'))
39
39
  msg.put_string(@target_name)
40
- msg.put_string(::SvcbRrPatch::SvcParams.encode(@svc_params))
40
+ msg.put_string(@svc_params.encode)
41
41
  end
42
42
 
43
43
  class << self
@@ -48,7 +48,7 @@ class Resolv::DNS::Resource::IN::SVCB < Resolv::DNS::Resource
48
48
  return new(svc_priority, target_name, {}) if svc_priority.zero?
49
49
 
50
50
  # the SvcParams, consuming the remainder of the record
51
- svc_params = ::SvcbRrPatch::SvcParams.decode(msg.get_bytes)
51
+ svc_params = ::SvcbRrPatch::SvcParams::Hash.decode(msg.get_bytes)
52
52
  new(svc_priority, target_name, svc_params)
53
53
  end
54
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SvcbRrPatch
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
data/spec/alpn_spec.rb CHANGED
@@ -25,7 +25,7 @@ RSpec.describe SvcbRrPatch::SvcParams::Alpn do
25
25
 
26
26
  it 'could encode' do
27
27
  expect(alpn.encode).to eq octet
28
- expect(alpn.inspect).to eq 'h3-29,h3-28,h3-27,h2'
28
+ expect(alpn.to_s).to eq 'h3-29,h3-28,h3-27,h2'
29
29
  end
30
30
  end
31
31
  end
@@ -33,7 +33,7 @@ RSpec.describe SvcbRrPatch::SvcParams::Ipv4hint do
33
33
 
34
34
  it 'could encode' do
35
35
  expect(ipv4hint.encode).to eq octet
36
- expect(ipv4hint.inspect).to eq '192.0.2.1,192.0.2.2'
36
+ expect(ipv4hint.to_s).to eq '192.0.2.1,192.0.2.2'
37
37
  end
38
38
  end
39
39
  end
@@ -36,7 +36,7 @@ RSpec.describe SvcbRrPatch::SvcParams::Ipv6hint do
36
36
 
37
37
  it 'could encode' do
38
38
  expect(ipv6hint.encode).to eq octet
39
- expect(ipv6hint.inspect).to eq '2001:db8::1,2001:db8::2'
39
+ expect(ipv6hint.to_s).to eq '2001:db8::1,2001:db8::2'
40
40
  end
41
41
  end
42
42
  end
@@ -5,16 +5,16 @@ require_relative 'spec_helper'
5
5
 
6
6
  RSpec.describe SvcbRrPatch::SvcParams::Mandatory do
7
7
  let(:octet) do
8
- "\x00\x05\x00\x06\xff\xa4"
8
+ "\x00\x05\x00\x06\x00\x08\xff\xa4"
9
9
  end
10
10
 
11
11
  let(:keys) do
12
- h = Hash[
13
- (0..SvcbRrPatch::SvcParams::PARAMETER_REGISTRY.size - 1)
14
- .zip(SvcbRrPatch::SvcParams::PARAMETER_REGISTRY)
15
- ].invert
16
-
17
- [h['ech'], h['ipv6hint'], h['key65444']]
12
+ [
13
+ SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['ech'],
14
+ SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['ipv6hint'],
15
+ SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['undefine8'],
16
+ SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['key65444']
17
+ ]
18
18
  end
19
19
 
20
20
  context '#decode' do
@@ -34,7 +34,7 @@ RSpec.describe SvcbRrPatch::SvcParams::Mandatory do
34
34
 
35
35
  it 'could encode' do
36
36
  expect(mandatory.encode).to eq octet
37
- expect(mandatory.inspect).to eq 'ech,ipv6hint,key65444'
37
+ expect(mandatory.to_s).to eq 'ech,ipv6hint,undefine8,key65444'
38
38
  end
39
39
  end
40
40
  end
@@ -30,7 +30,7 @@ RSpec.describe SvcbRrPatch::SvcParams::NoDefaultAlpn do
30
30
  expect(no_default_alpn)
31
31
  .to be_a(SvcbRrPatch::SvcParams::NoDefaultAlpn)
32
32
  expect(no_default_alpn.encode).to eq octet
33
- expect(no_default_alpn.inspect).to eq 'h3-29,h3-28,h3-27,h2'
33
+ expect(no_default_alpn.to_s).to eq 'h3-29,h3-28,h3-27,h2'
34
34
  end
35
35
  end
36
36
  end
data/spec/port_spec.rb CHANGED
@@ -25,7 +25,7 @@ RSpec.describe SvcbRrPatch::SvcParams::Port do
25
25
 
26
26
  it 'could encode' do
27
27
  expect(port.encode).to eq octet
28
- expect(port.inspect).to eq '443'
28
+ expect(port.to_s).to eq '443'
29
29
  end
30
30
  end
31
31
  end
@@ -45,7 +45,7 @@ RSpec.describe SvcbRrPatch::SvcParams do
45
45
 
46
46
  context '#decode' do
47
47
  let(:svc_params) do
48
- SvcbRrPatch::SvcParams.decode(octet)
48
+ SvcbRrPatch::SvcParams::Hash.decode(octet)
49
49
  end
50
50
 
51
51
  it 'could decode' do
@@ -60,16 +60,18 @@ RSpec.describe SvcbRrPatch::SvcParams do
60
60
 
61
61
  context '#encode' do
62
62
  let(:svc_params) do
63
- {
63
+ h = {
64
64
  'alpn' => alpn,
65
65
  'ipv4hint' => ipv4hint,
66
66
  'ipv6hint' => ipv6hint,
67
67
  'key65333' => key65333
68
68
  }
69
+ SvcbRrPatch::SvcParams::Hash.new(h)
69
70
  end
70
71
 
71
72
  it 'could encode' do
72
- expect(SvcbRrPatch::SvcParams.encode(svc_params)).to eq octet
73
+ expect(svc_params.encode).to eq octet
74
+ puts svc_params.inspect
73
75
  end
74
76
  end
75
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svcb_rr_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - thekuwayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-12 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler