Class: ECHConfig::ECHConfigContents
- Inherits:
-
Object
- Object
- ECHConfig::ECHConfigContents
- Defined in:
- lib/ech_config/ech_config_contents.rb,
lib/ech_config/ech_config_contents.rb,
sig/generated/ech_config/ech_config_contents.rbs,
sig/generated/ech_config/ech_config_contents.rbs
Overview
rbs_inline: enabled
Defined Under Namespace
Classes: Extensions, HpkeKeyConfig
Instance Attribute Summary collapse
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#key_config ⇒ Object
readonly
Returns the value of attribute key_config.
-
#maximum_name_length ⇒ Object
readonly
Returns the value of attribute maximum_name_length.
-
#public_name ⇒ Object
readonly
Returns the value of attribute public_name.
Class Method Summary collapse
-
.decode(octet) ⇒ ECHConfig::ECHConfigContents
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
- #encode ⇒ String
-
#initialize(key_config, maximum_name_length, public_name, extensions) ⇒ ECHConfigContents
constructor
A new instance of ECHConfigContents.
Constructor Details
#initialize(key_config, maximum_name_length, public_name, extensions) ⇒ ECHConfigContents
Returns a new instance of ECHConfigContents.
20 21 22 23 24 25 26 27 28 |
# File 'lib/ech_config/ech_config_contents.rb', line 20 def initialize(key_config, maximum_name_length, public_name, extensions) @key_config = key_config @maximum_name_length = maximum_name_length @public_name = public_name @extensions = extensions end |
Instance Attribute Details
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
13 14 15 |
# File 'lib/ech_config/ech_config_contents.rb', line 13 def extensions @extensions end |
#key_config ⇒ Object (readonly)
Returns the value of attribute key_config.
13 14 15 |
# File 'lib/ech_config/ech_config_contents.rb', line 13 def key_config @key_config end |
#maximum_name_length ⇒ Object (readonly)
Returns the value of attribute maximum_name_length.
13 14 15 |
# File 'lib/ech_config/ech_config_contents.rb', line 13 def maximum_name_length @maximum_name_length end |
#public_name ⇒ Object (readonly)
Returns the value of attribute public_name.
13 14 15 |
# File 'lib/ech_config/ech_config_contents.rb', line 13 def public_name @public_name end |
Class Method Details
.decode(octet) ⇒ ECHConfig::ECHConfigContents
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ech_config/ech_config_contents.rb', line 43 def self.decode(octet) key_config, octet = HpkeKeyConfig.decode(octet) octet ||= '' raise ::ECHConfig::DecodeError if octet.nil? || octet.length < 2 maximum_name_length = octet.slice(0, 1)&.unpack1('C') #: Integer raise ::ECHConfig::DecodeError if maximum_name_length.nil? pn_len = octet.slice(1, 1)&.unpack1('C') #: Integer i = 2 raise ::ECHConfig::DecodeError if i + pn_len > octet.length public_name = octet.slice(i, pn_len) raise ::ECHConfig::DecodeError if public_name.nil? i += pn_len raise ::ECHConfig::DecodeError if i + 2 > octet.length ex_len = octet.slice(i, 2)&.unpack1('n') #: Integer i += 2 raise ::ECHConfig::DecodeError if i + ex_len != octet.length extensions = Extensions.store(octet.slice(i, ex_len) || '') new( key_config, maximum_name_length, public_name, extensions ) end |
Instance Method Details
#encode ⇒ String
31 32 33 34 35 36 |
# File 'lib/ech_config/ech_config_contents.rb', line 31 def encode @key_config.encode \ + [@maximum_name_length].pack('C') \ + @public_name.then { |s| [s.length].pack('C') + s } \ + @extensions.load.then { |s| [s.length].pack('n') + s } end |