Class: TTTLS13::Message::Extension::SupportedGroups

Inherits:
Object
  • Object
show all
Defined in:
lib/tttls1.3/message/extension/supported_groups.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(named_group_list) ⇒ SupportedGroups

Returns a new instance of SupportedGroups.

Parameters:

Raises:



15
16
17
18
19
20
# File 'lib/tttls1.3/message/extension/supported_groups.rb', line 15

def initialize(named_group_list)
  @extension_type = ExtensionType::SUPPORTED_GROUPS
  @named_group_list = named_group_list || []
  raise Error::ErrorAlerts, :internal_error \
    if @named_group_list.empty? || @named_group_list.length >= 2**15 - 1
end

Instance Attribute Details

#extension_typeObject (readonly)

Returns the value of attribute extension_type.



9
10
11
# File 'lib/tttls1.3/message/extension/supported_groups.rb', line 9

def extension_type
  @extension_type
end

#named_group_listObject (readonly)

Returns the value of attribute named_group_list.



10
11
12
# File 'lib/tttls1.3/message/extension/supported_groups.rb', line 10

def named_group_list
  @named_group_list
end

Class Method Details

.deserialize(binary) ⇒ TTTLS13::Message::Extension::SupportedGroups?

rubocop: disable Metrics/CyclomaticComplexity

Parameters:

  • binary (String)

Returns:

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tttls1.3/message/extension/supported_groups.rb', line 35

def self.deserialize(binary)
  raise Error::ErrorAlerts, :internal_error if binary.nil?

  return nil if binary.length < 2

  nglist_len = Convert.bin2i(binary.slice(0, 2))
  i = 2
  named_group_list = []
  while i < nglist_len + 2
    return nil if i + 2 > binary.length

    named_group_list << binary.slice(i, 2)
    i += 2
  end
  return nil unless i == binary.length &&
                    nglist_len + 2 == binary.length

  SupportedGroups.new(named_group_list)
end

Instance Method Details

#serializeString

Returns:

  • (String)


23
24
25
26
27
# File 'lib/tttls1.3/message/extension/supported_groups.rb', line 23

def serialize
  binary = @named_group_list.join.prefix_uint16_length

  @extension_type + binary.prefix_uint16_length
end