Class: RASN1::Types::Any
Overview
ASN.1 ANY: accepts any types
If ‘any#value` is `nil`, `any` will be encoded as a Null object.
Constant Summary
Constants inherited from Base
Base::CLASSES, Base::INDEFINITE_LENGTH, Base::MAX_TAG
Instance Attribute Summary
Attributes inherited from Base
#asn1_class, #default, #name, #value
Instance Method Summary collapse
- #inspect(level = 0) ⇒ Object
-
#parse!(der, ber: false) ⇒ Integer
Parse a DER string.
-
#to_der ⇒ String
DER-formated string.
Methods inherited from Base
#==, #constructed?, encode_type, #explicit?, #implicit?, #initialize, #initialize_copy, #optional?, parse, #primitive?, #tag, #tagged?, type, #type, #value_size
Constructor Details
This class inherits a constructor from RASN1::Types::Base
Instance Method Details
#inspect(level = 0) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rasn1/types/any.rb', line 33 def inspect(level=0) str = '' str << ' ' * level if level > 0 str << "#{@name} " unless @name.nil? if @value.nil? str << "(ANY) NULL" elsif @value.is_a?(OctetString) or @value.is_a?(BitString) str << "(ANY) #{@value.type}: #{value.value.inspect}" elsif @value.class < Base str << "(ANY) #{@value.type}: #{value.value}" else str << "ANY: #{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.
27 28 29 30 31 |
# File 'lib/rasn1/types/any.rb', line 27 def parse!(der, ber: false) total_length, = get_data(der, ber) @value = der[0, total_length] total_length end |
#to_der ⇒ String
Returns DER-formated string.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rasn1/types/any.rb', line 11 def to_der case @value when Base, Model @value.to_der when nil Null.new.to_der else @value.to_s end end |