Class: TTTLS13::Message::Alert

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

Overview

rubocop: enable Layout/HashAlignment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level: nil, description:) ⇒ Alert

Returns a new instance of Alert.

Parameters:



49
50
51
52
53
54
55
56
57
58
# File 'lib/tttls1.3/message/alert.rb', line 49

def initialize(level: nil, description:)
  @level = level
  @description = description
  if @level.nil? && (@description == ALERT_DESCRIPTION[:user_canceled] ||
                     @description == ALERT_DESCRIPTION[:close_notify])
    @level = AlertLevel::WARNING
  elsif @level.nil?
    @level = AlertLevel::FATAL
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



45
46
47
# File 'lib/tttls1.3/message/alert.rb', line 45

def description
  @description
end

#levelObject (readonly)

Returns the value of attribute level.



44
45
46
# File 'lib/tttls1.3/message/alert.rb', line 44

def level
  @level
end

Class Method Details

.deserialize(binary) ⇒ TTTLS13::Message::Alert

Parameters:

  • binary (String)

Returns:

Raises:



70
71
72
73
74
75
76
77
# File 'lib/tttls1.3/message/alert.rb', line 70

def self.deserialize(binary)
  raise Error::ErrorAlerts, :internal_error if binary.nil?
  raise Error::ErrorAlerts, :decode_error unless binary.length == 2

  level = binary[0]
  description = binary[1]
  Alert.new(level: level, description: description)
end

Instance Method Details

#serializeString

Returns:

  • (String)


61
62
63
# File 'lib/tttls1.3/message/alert.rb', line 61

def serialize
  @level + @description
end

#to_errorTTTLS13::Error::ErrorAlerts



80
81
82
83
# File 'lib/tttls1.3/message/alert.rb', line 80

def to_error
  desc = ALERT_DESCRIPTION.invert[@description]
  Error::ErrorAlerts.new(desc)
end