Class: RetroIDL::ASN::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/retro_idl/asn/tag.rb

Overview

X.680 section 31.2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Tag

Returns a new instance of Tag.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/retro_idl/asn/tag.rb', line 23

def initialize(**opts)

    errors = false

    @mod = nil
    @tag = nil
    @symbol = nil
    @encodingReference = opts[:encodingReference]
    @tagClass = opts[:class]
    @location = opts[:location]
    @tagType = opts[:type]
    

    if opts[:classNumber][:ref]

        if RetroIDL::ASN.is_identifier?(@location, opts[:classNumber][:ref])

            @symbol = opts[:classNumber][:ref]

        else

            errors = true

        end

    else

        @tagClassNumber = opts[:classNumber][:number]

        if @tagClassNumber < 0

            ASN.putError(opts[:classNumber][:location], "ClassNumber must be an integer >= 0")
            errors = true
            
        end
        
    end

    if errors

        raise ASNError.new

    end

end

Instance Attribute Details

#encodingReferenceString (readonly)

Returns EncodingReference.

Returns:

  • (String)

    EncodingReference



70
71
72
# File 'lib/retro_idl/asn/tag.rb', line 70

def encodingReference
  @encodingReference
end

#tagClass:IMPLICIT, :EXPLICIT (readonly)

Returns tag.

Returns:

  • (:IMPLICIT, :EXPLICIT)

    tag



73
74
75
# File 'lib/retro_idl/asn/tag.rb', line 73

def tagClass
  @tagClass
end

Instance Method Details

resolve symbols to definitions in module

Parameters:

  • mod (MODULE)

    module this type belongs to

  • stack (Array)

    objects called before this object for depth first search of recursion

Returns:

  • (MODULE)

    object has been linked

  • (nil)

    object has not been linked



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/retro_idl/asn/tag.rb', line 104

def link(mod, stack)

    if @mod.nil? or @mod != mod

        @mod = nil

        if @symbol

            if mod.symbols(@symbol).nil?

                ASN.putError(@location, SYMBOL_UNDEFINED_ERROR)

            else

                @mod = mod.symbols(@symbol).link(mod, stack)

            end

        end

    else

        @mod

    end

end

#tagClassNumberInteger

Return the tag ClassNumber

Returns:

  • (Integer)

    ClassNumber

Raises:

  • (ASNError)

    tag has not been linked



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/retro_idl/asn/tag.rb', line 81

def tagClassNumber

    if @mod

        if @symbol

            @symbol.value

        else

            @tagClassNumber

        end

    else
        
        raise ASNError.new LINK_ERROR

    end

end

#to_sString

Convert object to ASN.1 syntax representation

Returns:

  • (String)

    ASN.1 syntax representation

Raises:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/retro_idl/asn/tag.rb', line 133

def to_s

    result = "["

    if @encodingReference

        result << " #{@encodingReference} :"

    end

    if @tagClass

        result << " #{@tagClass}"

    end

    if @symbol

        result << " #{@symbol}"

    else

        result << " #{@tagClassNumber}"

    end

    result << " ] #{@tagType}"

end