Class: ECHConfig
- Inherits:
-
Object
- Object
- ECHConfig
- Defined in:
- lib/ech_config/version.rb,
lib/ech_config.rb,
lib/ech_config.rb,
sig/generated/ech_config.rbs,
sig/generated/ech_config.rbs,
sig/generated/ech_config/version.rbs
Overview
rbs_inline: enabled
Defined Under Namespace
Classes: DecodeError, ECHConfigContents, Error, UnsupportedVersion
Constant Summary collapse
- VERSION =
'0.0.5'
Instance Attribute Summary collapse
-
#echconfig_contents ⇒ Object
readonly
Returns the value of attribute echconfig_contents.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.decode_vectors(octet) ⇒ Array[ECHConfig]
rubocop:disable Metrics/CyclomaticComplexity.
Instance Method Summary collapse
- #encode ⇒ String
-
#initialize(version, echconfig_contents) ⇒ ECHConfig
constructor
A new instance of ECHConfig.
Constructor Details
#initialize(version, echconfig_contents) ⇒ ECHConfig
Returns a new instance of ECHConfig.
22 23 24 25 26 27 28 29 30 |
# File 'lib/ech_config.rb', line 22 def initialize(version, echconfig_contents) v = version.unpack1('n') # https://datatracker.ietf.org/doc/html/rfc9849#section-4 raise ::ECHConfig::UnsupportedVersion \ unless v > "\xfe\x0a".unpack1('n') && v <= "\xfe\x0d".unpack1('n') # steep:ignore @version = version @echconfig_contents = echconfig_contents end |
Instance Attribute Details
#echconfig_contents ⇒ Object (readonly)
Returns the value of attribute echconfig_contents.
17 18 19 |
# File 'lib/ech_config.rb', line 17 def echconfig_contents @echconfig_contents end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
17 18 19 |
# File 'lib/ech_config.rb', line 17 def version @version end |
Class Method Details
.decode_vectors(octet) ⇒ Array[ECHConfig]
rubocop:disable Metrics/CyclomaticComplexity
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ech_config.rb', line 40 def self.decode_vectors(octet) i = 0 echconfigs = [] # @type var echconfigs: Array[ECHConfig] while i < octet.length raise ::ECHConfig::DecodeError if i + 4 > octet.length version = octet.slice(i, 2) raise ::ECHConfig::DecodeError if version.nil? length = octet.slice(i + 2, 2)&.unpack1('n') # @type var length: Integer i += 4 raise ::ECHConfig::DecodeError if i + length > octet.length echconfig_contents = ECHConfigContents.decode(octet.slice(i, length) || '') i += length echconfigs << new(version, echconfig_contents) end raise ::ECHConfig::DecodeError if i != octet.length echconfigs end |
Instance Method Details
#encode ⇒ String
33 34 35 |
# File 'lib/ech_config.rb', line 33 def encode @version + @echconfig_contents.encode.then { |s| [s.length].pack('n') + s } end |