aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1kit/module.rb
blob: 09808d9734c791b599301c4e396e4ac9dd2d1f13 (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
module ASN1Kit
  class Module
    attr_reader :name, :oid

    def initialize(name, symbols = {}, oid: nil)
      @name = name
      @oid = oid if oid
      @symbols = symbols
    end

    def add_type(name, type)
      raise "invalid type: #{type.inspect}" unless type.is_a?(Class) && type < Type
      @symbols[name] = type
    end

    def add_value(name, value)
      raise "invalid value: #{value.inspect}" unless value.is_a?(Type)
      @symbols[name] = value
    end

    def [](name)
      @symbols[name]
    end
  end
end