Class: RASN1::Types::Constructed Abstract

Inherits:
Base
  • Object
show all
Defined in:
lib/rasn1/types/constructed.rb

Overview

This class is abstract.

This class SHOULD be used as base class for all ASN.1 primitive types.

Base class for all ASN.1 constructed types

Author:

  • Sylvain Daubert

Direct Known Subclasses

Sequence, SequenceOf

Constant Summary collapse

ASN1_PC =

Constructed value

0x20

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

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, #parse!, #primitive?, #specific_initializer, start_tracing, stop_tracing, #tagged?, #to_der, #trace, 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

Returns:

See Also:

Since:

  • 0.12.0



16
17
18
19
20
21
22
23
24
25
# File 'lib/rasn1/types/constructed.rb', line 16

def can_build? # rubocop:disable Metrics/CyclomaticComplexity
  return super unless @value.is_a?(Array) && optional?
  return false unless super

  @value.any? do |el|
    el.can_build? && (
      el.primitive? ||
        (el.value.respond_to?(:empty?) ? !el.value.empty? : !el.value.nil?))
  end
end

#inspect(level = 0) ⇒ String

Parameters:

  • level (::Integer) (defaults to: 0)

    (default: 0)

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rasn1/types/constructed.rb', line 29

def inspect(level=0)
  case @value
  when Array
    str = common_inspect(level)
    str << "\n"
    level = level.abs + 1
    @value.each do |item|
      case item
      when Base, Model, Wrapper
        str << "#{item.inspect(level)}\n"
      else
        str << '  ' * level
        str << "#{item.inspect}\n"
      end
    end
    str
  else
    super
  end
end