Class: TTTLS13::Message::CompressedCertificate
- Inherits:
-
Object
- Object
- TTTLS13::Message::CompressedCertificate
- Defined in:
- lib/tttls1.3/message/compressed_certificate.rb
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
-
#certificate_message ⇒ Object
readonly
Returns the value of attribute certificate_message.
-
#msg_type ⇒ Object
readonly
Returns the value of attribute msg_type.
Class Method Summary collapse
-
.deserialize(binary) ⇒ TTTLS13::Message::CompressedCertificate
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
-
#initialize(certificate_message:, algorithm:) ⇒ CompressedCertificate
constructor
A new instance of CompressedCertificate.
- #serialize ⇒ String (also: #fragment)
Constructor Details
#initialize(certificate_message:, algorithm:) ⇒ CompressedCertificate
Returns a new instance of CompressedCertificate.
14 15 16 17 18 |
# File 'lib/tttls1.3/message/compressed_certificate.rb', line 14 def initialize(certificate_message:, algorithm:) @msg_type = HandshakeType::COMPRESSED_CERTIFICATE @certificate_message = @algorithm = algorithm end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
10 11 12 |
# File 'lib/tttls1.3/message/compressed_certificate.rb', line 10 def algorithm @algorithm end |
#certificate_message ⇒ Object (readonly)
Returns the value of attribute certificate_message.
9 10 11 |
# File 'lib/tttls1.3/message/compressed_certificate.rb', line 9 def @certificate_message end |
#msg_type ⇒ Object (readonly)
Returns the value of attribute msg_type.
8 9 10 |
# File 'lib/tttls1.3/message/compressed_certificate.rb', line 8 def msg_type @msg_type end |
Class Method Details
.deserialize(binary) ⇒ TTTLS13::Message::CompressedCertificate
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity
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/tttls1.3/message/compressed_certificate.rb', line 46 def self.deserialize(binary) raise Error::ErrorAlerts, :internal_error if binary.nil? raise Error::ErrorAlerts, :decode_error if binary.length < 5 raise Error::ErrorAlerts, :internal_error \ unless binary[0] == HandshakeType::COMPRESSED_CERTIFICATE msg_len = Convert.bin2i(binary.slice(1, 3)) algorithm = binary.slice(4, 2) uncompressed_length = Convert.bin2i(binary.slice(6, 3)) ccm_len = Convert.bin2i(binary.slice(9, 3)) ct_bin = '' case algorithm when Extension::CertificateCompressionAlgorithm::ZLIB ct_bin = Zlib::Inflate.inflate(binary.slice(12, ccm_len)) else # TODO: BROTLI, ZSTD raise Error::ErrorAlerts, :bad_certificate end raise Error::ErrorAlerts, :bad_certificate \ unless ct_bin.length == uncompressed_length raise Error::ErrorAlerts, :decode_error \ unless ccm_len + 12 == binary.length && msg_len + 4 == binary.length = Certificate.deserialize( HandshakeType::CERTIFICATE + ct_bin.prefix_uint24_length ) CompressedCertificate.new( certificate_message: , algorithm: algorithm ) end |
Instance Method Details
#serialize ⇒ String Also known as: fragment
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tttls1.3/message/compressed_certificate.rb', line 21 def serialize binary = '' binary += @algorithm ct_bin = @certificate_message.serialize[4..] binary += ct_bin.length.to_uint24 case @algorithm when Extension::CertificateCompressionAlgorithm::ZLIB binary += Zlib::Deflate.deflate(ct_bin).prefix_uint24_length else # TODO: orig_msgs, ZSTD raise Error::ErrorAlerts, :internal_error end @msg_type + binary.prefix_uint24_length end |