Class: EchSpec::Log::MessageStack
- Inherits:
-
Object
- Object
- EchSpec::Log::MessageStack
- Defined in:
- lib/echspec/log.rb
Class Method Summary collapse
-
.msg2name(msg) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity.
-
.obj2json(obj) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
- #<<(msg) ⇒ Object
-
#initialize ⇒ MessageStack
constructor
A new instance of MessageStack.
- #marshal ⇒ Object
Constructor Details
#initialize ⇒ MessageStack
Returns a new instance of MessageStack.
4 5 6 |
# File 'lib/echspec/log.rb', line 4 def initialize @stack = [] end |
Class Method Details
.msg2name(msg) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/echspec/log.rb', line 21 def self.msg2name(msg) case msg in TTTLS13::Message::ClientHello if msg.ch_inner? 'ClientHelloInner' in TTTLS13::Message::ClientHello 'ClientHello' in TTTLS13::Message::ServerHello if msg.hrr? 'HelloRetryRequest' in TTTLS13::Message::ServerHello 'ServerHello' in TTTLS13::Message::ChangeCipherSpec 'ChangeCipherSpec' in TTTLS13::Message::EncryptedExtensions 'EncryptedExtensions' in TTTLS13::Message::Certificate 'Certificate' in TTTLS13::Message::CertificateVerify 'CertificateVerify' in TTTLS13::Message::Finished 'Finished' in TTTLS13::Message::EndOfEarlyData 'EndOfEarlyData' in TTTLS13::Message::Alert 'Alert' end end |
.obj2json(obj) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity
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 77 78 79 80 |
# File 'lib/echspec/log.rb', line 52 def self.obj2json(obj) case obj in OpenSSL::X509::Certificate obj.to_pem.gsub("\n", '\n') in Numeric | TrueClass | FalseClass obj.pretty_print_inspect in '' '""' in String "\"0x#{obj.unpack1('H*')}\"" in NilClass 'null' in Array s = obj.map { |i| obj2json(i) }.join(',') "[#{s}]" in Hash s = obj.map { |k, v| "#{obj2json(k)}:#{obj2json(v)}" }.join(',') "{#{s}}" in Object if !obj.instance_variables.empty? arr = obj.instance_variables.map do |i| k = i[1..] v = obj2json(obj.instance_variable_get(i)) "\"#{k}\":#{v}" end "{#{arr.join(',')}}" else "\"$#{obj.class.name}\"" end end |
Instance Method Details
#<<(msg) ⇒ Object
9 10 11 |
# File 'lib/echspec/log.rb', line 9 def <<(msg) @stack << msg end |
#marshal ⇒ Object
13 14 15 16 17 |
# File 'lib/echspec/log.rb', line 13 def marshal arr = [] arr = @stack.reduce(arr) { |sum, msg| sum << "\"#{MessageStack.msg2name(msg)}\":#{MessageStack.obj2json(msg)}" } "{#{arr.reverse.join(',')}}" end |