Class: TTTLS13::Message::Extensions
- Inherits:
-
Hash
- Object
- Hash
- TTTLS13::Message::Extensions
- Defined in:
- lib/tttls1.3/message/extensions.rb
Class Method Summary collapse
-
.deserialize(binary, msg_type) ⇒ TTTLS13::Message::Extensions
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
- #<<(ex) ⇒ TTTLS13::Message::Extension::$Object
- #[](key) ⇒ Object
- #fetch(key, default = nil) ⇒ TTTLS13::Message::Extension::$Object
-
#initialize(extensions = []) ⇒ Extensions
constructor
A new instance of Extensions.
-
#serialize ⇒ String
NOTE: “pre_shared_key” MUST be the last extension in the ClientHello.
- #super_fetch ⇒ Object
Constructor Details
#initialize(extensions = []) ⇒ Extensions
Returns a new instance of Extensions.
15 16 17 18 19 |
# File 'lib/tttls1.3/message/extensions.rb', line 15 def initialize(extensions = []) extensions.each do |ex| super[ex.extension_type] = ex end end |
Class Method Details
.deserialize(binary, msg_type) ⇒ TTTLS13::Message::Extensions
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity
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 79 80 81 82 |
# File 'lib/tttls1.3/message/extensions.rb', line 48 def self.deserialize(binary, msg_type) raise Error::ErrorAlerts, :internal_error if binary.nil? exs = Extensions.new i = 0 while i < binary.length raise Error::ErrorAlerts, :decode_error if i + 4 > binary.length extension_type = binary.slice(i, 2) i += 2 ex_len = Convert.bin2i(binary.slice(i, 2)) i += 2 raise Error::ErrorAlerts, :decode_error if i + ex_len > binary.length ex_bin = binary.slice(i, ex_len) ex = deserialize_extension(ex_bin, extension_type, msg_type) if ex.nil? # ignore unparsable binary, but only transcript ex = Extension::UnknownExtension.new(extension_type: extension_type, extension_data: ex_bin) end # There MUST NOT be more than one extension of the same type in a # given extension block. raise Error::ErrorAlerts, :unsupported_extension \ if exs.include?(extension_type) exs[extension_type] = ex i += ex_len end raise Error::ErrorAlerts, :decode_error unless i == binary.length exs end |
Instance Method Details
#<<(ex) ⇒ TTTLS13::Message::Extension::$Object
103 104 105 |
# File 'lib/tttls1.3/message/extensions.rb', line 103 def <<(ex) store(ex.extension_type, ex) end |
#[](key) ⇒ Object
96 97 98 |
# File 'lib/tttls1.3/message/extensions.rb', line 96 def [](key) fetch(key) end |
#fetch(key, default = nil) ⇒ TTTLS13::Message::Extension::$Object
90 91 92 93 94 |
# File 'lib/tttls1.3/message/extensions.rb', line 90 def fetch(key, default = nil) return nil if super_fetch(key, nil).is_a?(Extension::UnknownExtension) super_fetch(key, default) end |
#serialize ⇒ String
NOTE: “pre_shared_key” MUST be the last extension in the ClientHello
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tttls1.3/message/extensions.rb', line 27 def serialize except_ch_psk = values.reject do |ex| ex.extension_type == ExtensionType::PRE_SHARED_KEY && ex.msg_type == HandshakeType::CLIENT_HELLO end binary = except_ch_psk.map(&:serialize).join psk = super_fetch(ExtensionType::PRE_SHARED_KEY, nil) binary += psk.serialize if psk&.msg_type == HandshakeType::CLIENT_HELLO binary.prefix_uint16_length end |
#super_fetch ⇒ Object
21 |
# File 'lib/tttls1.3/message/extensions.rb', line 21 alias super_fetch fetch |