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::MAX_TAG, Base::UNDUPPABLE_TYPES
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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rasn1/types/any.rb', line 39 def inspect(level=0) lvl = level >= 0 ? level : 0 str = ' ' * lvl str << "#{@name} " unless @name.nil? str << if @value.nil? '(ANY) NULL' elsif @value.is_a?(OctetString) || @value.is_a?(BitString) "(ANY) #{@value.type}: #{value.value.inspect}" elsif @value.class < Base "(ANY) #{@value.type}: #{value.value}" else "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 32 33 34 35 36 37 |
# File 'lib/rasn1/types/any.rb', line 27 def parse!(der, ber: false) if der.nil? || der.empty? return 0 if optional? raise ASN1Error, 'Expected ANY but get nothing' end 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 optional? ? '' : Null.new.to_der else @value.to_s end end |