aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1kit/types/set_of.rb
blob: 341810cd0d9160f4845fd6726c74c3f837ba2c0b (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::SetOf < ASN1Kit::Type
  asn1_tag :IMPLICIT, :UNIVERSAL, 17
  asn1_alias "SET 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::CompileSetOf
  refine ASN1Kit::SetOf.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