Class: RASN1::Types::Any
Overview
ASN.1 ANY: accepts any types
If ‘any#value` is `nil` and Any object is not Base#optional?, `any` will be encoded as a Null object.
Constant Summary
Constants inherited from Base
Base::CLASSES, Base::CLASS_MASK, Base::INDEFINITE_LENGTH, Base::MULTI_OCTETS_ID
Instance Attribute Summary
Attributes inherited from Base
#asn1_class, #default, #name, #options
Instance Method Summary collapse
- #can_build? ⇒ Boolean
- #inspect(level = 0) ⇒ String
-
#parse!(der, ber: false) ⇒ Integer
Parse a DER string.
-
#to_der ⇒ String
DER-formated string.
- #trace ⇒ String
Methods inherited from Base
#==, constrained?, #constructed?, #do_parse_explicit_with_tracing, #do_parse_with_tracing, encoded_type, #explicit?, #id, #implicit?, #initialize, #initialize_copy, #optional?, parse, #primitive?, #specific_initializer, start_tracing, stop_tracing, #tagged?, #type, type, #value, #value=, #value?, #value_size, #void_value
Constructor Details
This class inherits a constructor from RASN1::Types::Base
Instance Method Details
#can_build? ⇒ Boolean
24 25 26 |
# File 'lib/rasn1/types/any.rb', line 24 def can_build? value? || !optional? end |
#inspect(level = 0) ⇒ String
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rasn1/types/any.rb', line 40 def inspect(level=0) str = common_inspect(level) str << if !value? 'NULL' elsif @value.is_a?(OctetString) || @value.is_a?(BitString) "#{@value.type}: #{value.value.inspect}" elsif @value.class < Base "#{@value.type}: #{value.value}" else value.to_s.inspect end end |
#parse!(der, ber: false) ⇒ Integer
Parse a DER string. This method updates object: Base#value will be a DER string.
33 34 35 36 |
# File 'lib/rasn1/types/any.rb', line 33 def parse!(der, ber: false) total_length, _data = do_parse(der, ber) total_length end |
#to_der ⇒ String
Returns DER-formated string.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rasn1/types/any.rb', line 11 def to_der if value? case @value when Base, Model @value.to_der else @value.to_s end else optional? ? '' : Null.new.to_der end end |
#trace ⇒ String
55 56 57 58 59 |
# File 'lib/rasn1/types/any.rb', line 55 def trace return trace_any if value? msg_type(no_id: true) << ' NONE' end |