Class: TTTLS13::Message::Alert
- Inherits:
-
Object
- Object
- TTTLS13::Message::Alert
- Defined in:
- lib/tttls1.3/message/alert.rb
Overview
rubocop: enable Layout/HashAlignment
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(level: nil, description:) ⇒ Alert
constructor
A new instance of Alert.
- #serialize ⇒ String
- #to_error ⇒ TTTLS13::Error::ErrorAlerts
Constructor Details
#initialize(level: nil, description:) ⇒ Alert
Returns a new instance of Alert.
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
46 47 48 |
# File 'lib/tttls1.3/message/alert.rb', line 46 def description @description end |
#level ⇒ Object (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
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
#serialize ⇒ String
62 63 64 |
# File 'lib/tttls1.3/message/alert.rb', line 62 def serialize @level + @description end |
#to_error ⇒ TTTLS13::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 |