Class: ECHConfig::ECHConfigContents::HpkeKeyConfig
- Inherits:
-
Object
- Object
- ECHConfig::ECHConfigContents::HpkeKeyConfig
- Defined in:
- lib/ech_config/ech_config_contents/hpke_key_config.rb,
lib/ech_config/ech_config_contents/hpke_key_config.rb,
sig/generated/ech_config/ech_config_contents/hpke_key_config.rbs,
sig/generated/ech_config/ech_config_contents/hpke_key_config.rbs
Overview
rbs_inline: enabled
Defined Under Namespace
Classes: HpkeKemId, HpkePublicKey, HpkeSymmetricCipherSuite
Instance Attribute Summary collapse
-
#cipher_suites ⇒ Object
readonly
Returns the value of attribute cipher_suites.
-
#config_id ⇒ Object
readonly
Returns the value of attribute config_id.
-
#kem_id ⇒ Object
readonly
Returns the value of attribute kem_id.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
Class Method Summary collapse
-
.decode(octet) ⇒ [ ECHConfig::ECHConfigContents::HpkeKeyConfig, String | nil ]
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
- #encode ⇒ String
-
#initialize(config_id, kem_id, public_key, cipher_suites) ⇒ HpkeKeyConfig
constructor
A new instance of HpkeKeyConfig.
Constructor Details
#initialize(config_id, kem_id, public_key, cipher_suites) ⇒ HpkeKeyConfig
Returns a new instance of HpkeKeyConfig.
20 21 22 23 24 25 26 27 28 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 20 def initialize(config_id, kem_id, public_key, cipher_suites) @config_id = config_id @kem_id = kem_id @public_key = public_key @cipher_suites = cipher_suites end |
Instance Attribute Details
#cipher_suites ⇒ Object (readonly)
Returns the value of attribute cipher_suites.
13 14 15 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 13 def cipher_suites @cipher_suites end |
#config_id ⇒ Object (readonly)
Returns the value of attribute config_id.
13 14 15 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 13 def config_id @config_id end |
#kem_id ⇒ Object (readonly)
Returns the value of attribute kem_id.
13 14 15 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 13 def kem_id @kem_id end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
13 14 15 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 13 def public_key @public_key end |
Class Method Details
.decode(octet) ⇒ [ ECHConfig::ECHConfigContents::HpkeKeyConfig, String | nil ]
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 73 74 75 76 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 43 def self.decode(octet) raise ::ECHConfig::DecodeError if octet.empty? config_id = octet.slice(0, 1)&.unpack1('C') #: Integer i = 1 raise ::ECHConfig::DecodeError if i + 2 > octet.length kem_id = HpkeKemId.decode(octet.slice(i, 2) || '') i += 2 raise ::ECHConfig::DecodeError if i + 2 > octet.length pk_len = octet.slice(i, 2)&.unpack1('n') #: Integer i += 2 raise ::ECHConfig::DecodeError if i + pk_len > octet.length public_key = HpkePublicKey.decode(octet.slice(i, pk_len) || '') i += pk_len raise ::ECHConfig::DecodeError if i + 2 > octet.length cs_len = octet.slice(i, 2)&.unpack1('n') #: Integer i += 2 raise ::ECHConfig::DecodeError if i + 2 > octet.length cs_bin = octet.slice(i, cs_len) #: String i += cs_len cipher_suites = HpkeSymmetricCipherSuite.decode_vectors(cs_bin) hpke_key_config = new( config_id, kem_id, public_key, cipher_suites ) return hpke_key_config, octet[i..] end |
Instance Method Details
#encode ⇒ String
31 32 33 34 35 36 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 31 def encode [@config_id].pack('C') \ + @kem_id.encode \ + @public_key.encode \ + @cipher_suites.map(&:encode).join.then { |s| [s.length].pack('n') + s } end |