aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1kit/types/sequence_of.rb
blob: 93e6e61aad9f73f5d680943df0e52461ca3af96b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding: ASCII-8BIT

class ASN1Kit::SequenceOf < ASN1Kit::Type
  asn1_tag :IMPLICIT, :UNIVERSAL, 16
  asn1_alias "SEQUENCE OF"

  class << self
    def [](type)
      ret = Class.new(self)
      ret.const_set(:COMPONENT_TYPE, type)
      ret
    end

    private def inspect_inner
      self::COMPONENT_TYPE.inspect_abbrev
    end
  end

  def to_der
    content = @components.map { |c| c.to_der }.join
    der_header(content.bytesize, :constructed) << content
  end
end

module ASN1Kit::Internal::CompileSequenceOf
  refine ASN1Kit::SequenceOf.singleton_class do
    def _compile_fixup(state)
      type = self::COMPONENT_TYPE
      if type.is_a?(ASN1Kit::Internal::TypeReference)
        type = type.unwrap(state)
        state.resolve(type)
        remove_const(:COMPONENT_TYPE)
        const_set(:COMPONENT_TYPE, type)
      end
    end
  end
end