aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1kit/types/set.rb
blob: a2eaf1a271199f3ab70f9a09948d225c2e607a8f (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
# coding: ASCII-8BIT

class ASN1Kit::Set < ASN1Kit::Type
  asn1_tag :IMPLICIT, :UNIVERSAL, 17
  asn1_alias "SET"

  class << self
    def [](*component_types)
      ret = Class.new(self)
      hash = component_types.map { |c| [c.name, c] }.to_h
      ret.const_set(:COMPONENT_TYPES, hash)
      ret
    end

    private def inspect_inner
      ctypes = self::COMPONENT_TYPES.values.map { |c| c.inspect }.join(", ")
      "{ #{ctypes} }"
    end
  end

  def to_der
    content = self.class::COMPONENT_TYPES.map { |name, type, opts|
      next nil unless @value[name]
      @value[name].to_der
    }.compact.join
    der_header(content.bytesize, :constructed) << content
  end
end