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:



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

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.



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

def description
  @description
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

Class Method Details

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

Parameters:

  • binary (String)

Returns:

Raises:



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

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)


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

def serialize
  @level + @description
end

#to_errorTTTLS13::Error::ErrorAlerts



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

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