Class: ECHConfig::ECHConfigContents::HpkeKeyConfig
- Inherits:
-
Object
- Object
- ECHConfig::ECHConfigContents::HpkeKeyConfig
- Extended by:
- T::Sig
- Defined in:
- lib/ech_config/ech_config_contents/hpke_key_config.rb,
lib/ech_config/ech_config_contents/hpke_key_config.rb
Overview
typed: true frozen_string_literal: true
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
Instance Method Summary collapse
- #encode ⇒ Object
-
#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.
23 24 25 26 27 28 29 30 31 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 23 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) ⇒ Object
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 77 78 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 45 def self.decode(octet) raise ::ECHConfig::DecodeError if octet.empty? config_id = octet.slice(0, 1)&.unpack1('C') 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') 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') i += 2 raise ::ECHConfig::DecodeError if i + 2 > octet.length cs_bin = octet.slice(i, cs_len) i += cs_len cipher_suites = HpkeSymmetricCipherSuite.decode_vectors(cs_bin || '') hpke_key_config = new( config_id, kem_id, public_key, cipher_suites ) [hpke_key_config, octet[i..]] end |
Instance Method Details
#encode ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ech_config/ech_config_contents/hpke_key_config.rb', line 34 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 |