svcb_rr_patch 0.0.1 → 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: fe01826cf1fe78d4b2d6db7d53bb474234121dceba9f7cd8dc26b25ca2d3e00a
4
- data.tar.gz: 7acaffe658b58b44b2d22c66fafe904acacf15d1b68a5a1288db11dfacad886c
3
+ metadata.gz: c3af5857ef38bc6a54ad9abedb5c1227ea008b56e049393d16277103cba4b823
4
+ data.tar.gz: 8a9152efcf7694b8e6ace3a2fce298854f4020292b3f880c2ec9da4d19b8f25b
5
5
  SHA512:
6
- metadata.gz: eea644f426005af15be66fc9dbdcb9d60530e6ce77014a8345ebb52c561a71b2d352a2e29f373311724074a53c72d399007406348b8f421b1e9658a31c1b0c93
7
- data.tar.gz: 8b60ace84e7fe2ab8c67ee7aea3cf412d1926740de83a60f5fd5820f06bad4e7202ea64349d74aa623c3475b0ccc74a4dd0de65eefe7266b851a24623923be06
6
+ metadata.gz: 912e4053675275418be0a343010b56e00e912c42ea20f24c89877f6754ee246231a91884e10ae62756185e0e64fc0c030fcdb019203a038088087e27f0d6c3fc
7
+ data.tar.gz: d56504d2fc39255d4ed9dc805d478b05054251af35b89384db816d340b1c22e400b531b9bee63865776d05fb550f3ec846eb8b0235412fb357776e6fedc284eb
data/README.md CHANGED
@@ -6,18 +6,18 @@
6
6
 
7
7
  `svcb_rr_patch` is the patch that adds SVCB Resource Record and HTTPS Resource Record.
8
8
 
9
- - https://tools.ietf.org/html/draft-ietf-dnsop-svcb-https-06
9
+ - https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06
10
10
 
11
- `svcb_rr_patch` supports "ech" SvcParamKey that ECHConfig.version is 0xfe0a.
11
+ `svcb_rr_patch` supports "ech" SvcParamKey that ECHConfig.version is `0xfe0d`.
12
12
 
13
- - https://datatracker.ietf.org/doc/html/draft-ietf-tls-esni-10#section-4
13
+ - https://datatracker.ietf.org/doc/html/draft-ietf-tls-esni-13#section-4
14
14
 
15
15
 
16
16
  ## Installation
17
17
 
18
18
  he gem is available at [rubygems.org](https://rubygems.org/gems/svcb_rr_patch). You can install it the following.
19
19
 
20
- ```bash
20
+ ```sh-session
21
21
  $ gem install svcb_rr_patch
22
22
  ```
23
23
 
@@ -26,15 +26,46 @@ $ gem install svcb_rr_patch
26
26
 
27
27
  You can resolve HTTPS resources.
28
28
 
29
- ```bash
29
+ ```sh-session
30
30
  $ irb
31
31
  irb(main):001:0> require 'svcb_rr_patch'
32
32
  => true
33
33
  irb(main):002:1* Resolv::DNS.new.getresources(
34
34
  irb(main):003:1* "blog.cloudflare.com",
35
35
  irb(main):004:1* Resolv::DNS::Resource::IN::HTTPS
36
- irb(main):005:0> ) { |rr| pp rr }
37
- => [#<Resolv::DNS::Resource::IN::HTTPS:0x0000000000000001 @svc_priority=1, @svc_domain_name="", @svc_field_value={"alpn"=>#<SvcbRrPatch::SvcParams::Alpn:0x0000000000000002 @protocols=["h3-29", "h3-28", "h3-27", "h2"]>, "ipv4hint"=>#<SvcbRrPatch::SvcParams::Ipv4hint:0x0000000000000003 @addresses=[#<Resolv::IPv4 104.18.26.46>, #<Resolv::IPv4 104.18.27.46>]>, "ipv6hint"=>#<SvcbRrPatch::SvcParams::Ipv6hint:0x0000000000000004 @addresses=[#<Resolv::IPv6 2606:4700::6812:1a2e>, #<Resolv::IPv6 2606:4700::6812:1b2e>]>}, @ttl=300>]
36
+ irb(main):005:0> )
37
+ =>
38
+ [#<Resolv::DNS::Resource::IN::HTTPS:0x0000000000000001
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>]>}>,
66
+ @svc_priority=1,
67
+ @target_name="",
68
+ @ttl=58>]
38
69
  ```
39
70
 
40
71
 
@@ -9,7 +9,7 @@ class Resolv::DNS::Resource::IN::HTTPS < Resolv::DNS::Resource::IN::SVCB
9
9
  ClassHash[[TypeValue, ClassValue]] = self
10
10
 
11
11
  def initialize(svc_priority, target_name, svc_params)
12
- # https://tools.ietf.org/html/draft-ietf-dnsop-svcb-https-06
12
+ # https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06
13
13
  super(svc_priority, target_name, svc_params)
14
14
  end
15
15
 
@@ -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
@@ -35,4 +35,9 @@ class SvcbRrPatch::SvcParams::Alpn
35
35
  protocols = decode_protocols(octet)
36
36
  new(protocols)
37
37
  end
38
+
39
+ # :nodoc:
40
+ def to_s
41
+ @protocols.join(',')
42
+ end
38
43
  end
@@ -30,24 +30,20 @@ class SvcbRrPatch::SvcParams::Ech::ECHConfigContents
30
30
  # @return [String]
31
31
  def encode
32
32
  @key_config.encode \
33
- + [@maximum_name_length].pack('n') \
34
- + @public_name.then { |s| [s.length].pack('n') + s } \
33
+ + [@maximum_name_length].pack('C') \
34
+ + @public_name.then { |s| [s.length].pack('C') + s } \
35
35
  + @extensions.map(&:encode).join.then { |s| [s.length].pack('n') + s }
36
36
  end
37
37
 
38
38
  # :nodoc
39
39
  # rubocop:disable Metrics/AbcSize
40
- # rubocop:disable Metrics/CyclomaticComplexity
41
40
  def self.decode(octet)
42
41
  key_config, octet = HpkeKeyConfig.decode(octet)
43
42
  raise ::Resolv::DNS::DecodeError if octet.length < 2
44
43
 
45
- maximum_name_length = octet.slice(0, 2).unpack1('n')
44
+ maximum_name_length = octet.slice(0, 1).unpack1('C')
45
+ pn_len = octet.slice(1, 1).unpack1('C')
46
46
  i = 2
47
- raise ::Resolv::DNS::DecodeError if i + 2 > octet.length
48
-
49
- pn_len = octet.slice(i, 2).unpack1('n')
50
- i += 2
51
47
  raise ::Resolv::DNS::DecodeError if i + pn_len > octet.length
52
48
 
53
49
  public_name = octet.slice(i, pn_len)
@@ -70,5 +66,4 @@ class SvcbRrPatch::SvcParams::Ech::ECHConfigContents
70
66
  )
71
67
  end
72
68
  # rubocop:enable Metrics/AbcSize
73
- # rubocop:enable Metrics/CyclomaticComplexity
74
69
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SvcbRrPatch::SvcParams::Ech
4
- attr_reader :echconfigs
4
+ attr_reader :echconfiglist
5
5
 
6
6
  # @param echconfiglist [Array of ECHConfig]
7
7
  def initialize(echconfiglist)
@@ -21,6 +21,13 @@ class SvcbRrPatch::SvcParams::Ech
21
21
  echconfiglist = ECHConfig.decode_vectors(octet.slice(2..))
22
22
  new(echconfiglist)
23
23
  end
24
+
25
+ # https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06#section-9
26
+ # In presentation format, the value is a single ECHConfigList encoded in
27
+ # Base64.
28
+ def to_s
29
+ Base64.strict_encode64(encode)
30
+ end
24
31
  end
25
32
 
26
33
  require_relative 'ech/echconfig_contents'
@@ -18,4 +18,9 @@ class SvcbRrPatch::SvcParams::Ipv4hint
18
18
  addresses = octet.scan(/.{1,4}/).map { |s| Resolv::IPv4.new(s) }
19
19
  new(addresses)
20
20
  end
21
+
22
+ # :nodoc:
23
+ def to_s
24
+ @addresses.join(',')
25
+ end
21
26
  end
@@ -18,4 +18,9 @@ class SvcbRrPatch::SvcParams::Ipv6hint
18
18
  addresses = octet.scan(/.{1,16}/).map { |s| Resolv::IPv6.new(s) }
19
19
  new(addresses)
20
20
  end
21
+
22
+ # :nodoc:
23
+ def to_s
24
+ @addresses.join(',')
25
+ end
21
26
  end
@@ -15,7 +15,14 @@ class SvcbRrPatch::SvcParams::Mandatory
15
15
 
16
16
  # :nodoc:
17
17
  def self.decode(octet)
18
- keys = octet.scan(/.{1,2}/).map { |s| s.unpack1('n') }
18
+ keys = octet.scan(/.{1,2}/)
19
+ .map { |s| s.unpack1('n') }
19
20
  new(keys)
20
21
  end
22
+
23
+ # :nodoc:
24
+ def to_s
25
+ @keys.map { |i| SvcbRrPatch::SvcParams::PARAMETER_REGISTRY[i] }
26
+ .join(',')
27
+ end
21
28
  end
@@ -18,4 +18,9 @@ class SvcbRrPatch::SvcParams::Port
18
18
  port = octet.unpack1('n')
19
19
  new(port)
20
20
  end
21
+
22
+ # :nodoc:
23
+ def to_s
24
+ @port.to_s
25
+ end
21
26
  end
@@ -12,85 +12,109 @@ module SvcbRrPatch::SvcParams
12
12
  ipv6hint
13
13
  ]
14
14
  # rubocop:disable Security/Eval
15
- (65280..65535).each do |nnnn|
15
+ (8...65280).each do |nnnn|
16
+ eval "registry[nnnn] = \"undefine#{nnnn}\"", binding, __FILE__, __LINE__
17
+ end
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 'no name'
78
- NoName.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,9 +10,9 @@ 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
- # https://tools.ietf.org/html/draft-ietf-dnsop-svcb-https-06
15
+ # https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06
16
16
  @svc_priority = svc_priority
17
17
  @target_name = target_name
18
18
  @svc_params = svc_params
@@ -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.1'
4
+ VERSION = '0.0.5'
5
5
  end
data/lib/svcb_rr_patch.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'base64'
3
4
  require 'resolv'
4
5
 
5
6
  require 'svcb_rr_patch/version'
data/spec/alpn_spec.rb CHANGED
@@ -25,6 +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.to_s).to eq 'h3-29,h3-28,h3-27,h2'
28
29
  end
29
30
  end
30
31
  end
@@ -5,7 +5,7 @@ require_relative 'spec_helper'
5
5
 
6
6
  RSpec.describe SvcbRrPatch::SvcParams::Ipv4hint do
7
7
  let(:octet) do
8
- "\xc0\xa8\x00\x01\xc0\xa8\x00\x02"
8
+ "\xc0\x00\x02\x01\xc0\x00\x02\x02"
9
9
  end
10
10
 
11
11
  context '#decode' do
@@ -15,8 +15,8 @@ RSpec.describe SvcbRrPatch::SvcParams::Ipv4hint do
15
15
 
16
16
  it 'could decode' do
17
17
  expect(ipv4hint.addresses).to eq [
18
- Resolv::IPv4.create('192.168.0.1'),
19
- Resolv::IPv4.create('192.168.0.2')
18
+ Resolv::IPv4.create('192.0.2.1'),
19
+ Resolv::IPv4.create('192.0.2.2')
20
20
  ]
21
21
  end
22
22
  end
@@ -25,14 +25,15 @@ RSpec.describe SvcbRrPatch::SvcParams::Ipv4hint do
25
25
  let(:ipv4hint) do
26
26
  SvcbRrPatch::SvcParams::Ipv4hint.new(
27
27
  [
28
- Resolv::IPv4.create('192.168.0.1'),
29
- Resolv::IPv4.create('192.168.0.2')
28
+ Resolv::IPv4.create('192.0.2.1'),
29
+ Resolv::IPv4.create('192.0.2.2')
30
30
  ]
31
31
  )
32
32
  end
33
33
 
34
34
  it 'could encode' do
35
35
  expect(ipv4hint.encode).to eq octet
36
+ expect(ipv4hint.to_s).to eq '192.0.2.1,192.0.2.2'
36
37
  end
37
38
  end
38
39
  end
@@ -5,7 +5,10 @@ require_relative 'spec_helper'
5
5
 
6
6
  RSpec.describe SvcbRrPatch::SvcParams::Ipv6hint do
7
7
  let(:octet) do
8
- "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
8
+ <<-BIN.split.map(&:hex).map(&:chr).join
9
+ 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01
10
+ 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 02
11
+ BIN
9
12
  end
10
13
 
11
14
  context '#decode' do
@@ -14,20 +17,26 @@ RSpec.describe SvcbRrPatch::SvcParams::Ipv6hint do
14
17
  end
15
18
 
16
19
  it 'could decode' do
17
- expect(ipv6hint.addresses)
18
- .to eq [Resolv::IPv6.create('101:101:101:101:101:101:101:101')]
20
+ expect(ipv6hint.addresses).to eq [
21
+ Resolv::IPv6.create('2001:db8::1'),
22
+ Resolv::IPv6.create('2001:db8::2')
23
+ ]
19
24
  end
20
25
  end
21
26
 
22
27
  context '#encode' do
23
28
  let(:ipv6hint) do
24
29
  SvcbRrPatch::SvcParams::Ipv6hint.new(
25
- [Resolv::IPv6.create('101:101:101:101:101:101:101:101')]
30
+ [
31
+ Resolv::IPv6.create('2001:db8::1'),
32
+ Resolv::IPv6.create('2001:db8::2')
33
+ ]
26
34
  )
27
35
  end
28
36
 
29
37
  it 'could encode' do
30
38
  expect(ipv6hint.encode).to eq octet
39
+ expect(ipv6hint.to_s).to eq '2001:db8::1,2001:db8::2'
31
40
  end
32
41
  end
33
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\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['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,6 +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.to_s).to eq 'ech,ipv6hint,undefine8,key65444'
37
38
  end
38
39
  end
39
40
  end
@@ -30,6 +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.to_s).to eq 'h3-29,h3-28,h3-27,h2'
33
34
  end
34
35
  end
35
36
  end
data/spec/port_spec.rb CHANGED
@@ -25,6 +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.to_s).to eq '443'
28
29
  end
29
30
  end
30
31
  end
@@ -8,8 +8,8 @@ RSpec.describe SvcbRrPatch::SvcParams do
8
8
  <<-BIN.split.map(&:hex).map(&:chr).join
9
9
  00 01 00 15 05 68 33 2d 32 39 05 68 33 2d 32 38
10
10
  05 68 33 2d 32 37 02 68 32 00 04 00 08 c0 a8 00
11
- 01 c0 a8 00 02 00 06 00 10 01 01 01 01 01 01 01
12
- 01 01 01 01 01 01 01 01 01 ff 35 00 03 01 02 03
11
+ 01 c0 a8 00 02 00 06 00 10 20 01 0d b8 00 00 00
12
+ 00 00 00 00 00 00 00 00 01 ff 35 00 03 01 02 03
13
13
  BIN
14
14
  end
15
15
 
@@ -28,7 +28,7 @@ RSpec.describe SvcbRrPatch::SvcParams do
28
28
 
29
29
  let(:ipv6hint) do
30
30
  SvcbRrPatch::SvcParams::Ipv6hint.new(
31
- [Resolv::IPv6.create('101:101:101:101:101:101:101:101')]
31
+ [Resolv::IPv6.create('2001:db8::1')]
32
32
  )
33
33
  end
34
34
 
@@ -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.1
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: 2021-07-21 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
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.2.3
89
+ rubygems_version: 3.2.22
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: the patch that adds SVCB Resource Record and HTTPS Resource Record