rasn1 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rasn1/errors.rb +2 -2
- data/lib/rasn1/model.rb +113 -78
- data/lib/rasn1/tracer.rb +25 -5
- data/lib/rasn1/types/any.rb +24 -3
- data/lib/rasn1/types/base.rb +132 -36
- data/lib/rasn1/types/bit_string.rb +18 -5
- data/lib/rasn1/types/boolean.rb +14 -3
- data/lib/rasn1/types/choice.rb +39 -23
- data/lib/rasn1/types/constrained.rb +4 -3
- data/lib/rasn1/types/constructed.rb +4 -2
- data/lib/rasn1/types/enumerated.rb +9 -8
- data/lib/rasn1/types/generalized_time.rb +35 -8
- data/lib/rasn1/types/integer.rb +67 -11
- data/lib/rasn1/types/null.rb +7 -3
- data/lib/rasn1/types/numeric_string.rb +14 -2
- data/lib/rasn1/types/object_id.rb +15 -4
- data/lib/rasn1/types/octet_string.rb +3 -3
- data/lib/rasn1/types/primitive.rb +4 -0
- data/lib/rasn1/types/printable_string.rb +9 -2
- data/lib/rasn1/types/sequence.rb +7 -3
- data/lib/rasn1/types/sequence_of.rb +28 -8
- data/lib/rasn1/types/set_of.rb +1 -1
- data/lib/rasn1/types/utc_time.rb +7 -2
- data/lib/rasn1/types.rb +5 -5
- data/lib/rasn1/version.rb +1 -1
- data/lib/rasn1/wrapper.rb +38 -7
- data/lib/rasn1.rb +4 -3
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56e418f5906034865b82fd6dd271da80be89d601e4298230b3e36919d13dae22
|
|
4
|
+
data.tar.gz: d1f5d699c1e88e10b82a43fd3b9e0105041cb16ab11701751a6183088c2cca33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a0efd01e244b3e61260eb50ab1317e2f200a2d2a311ae51293f2e409f20086857ff334edd2019358f7929cc14ae657124733848c99abdce80ad67b91c1377a15
|
|
7
|
+
data.tar.gz: 83ae40e970a4c185fe9652d10e38ac9cd1effa4c28a0362172cf619c675ce400be4bf2935e889b35ace98f3cfb0cee7ce8923d0dc571e5cc6df0cca829036f4e
|
data/lib/rasn1/errors.rb
CHANGED
|
@@ -26,7 +26,7 @@ module RASN1
|
|
|
26
26
|
|
|
27
27
|
# CHOICE error: {Types::Choice#chosen} not set
|
|
28
28
|
class ChoiceError < RASN1::Error
|
|
29
|
-
# @param [Types::Base]
|
|
29
|
+
# @param object [Types::Base]
|
|
30
30
|
def initialize(object)
|
|
31
31
|
@object = object
|
|
32
32
|
super()
|
|
@@ -42,7 +42,7 @@ module RASN1
|
|
|
42
42
|
# @version 0.11.0
|
|
43
43
|
# @author Sylvain Daubert
|
|
44
44
|
class ConstraintError < Error
|
|
45
|
-
# @param [Types::Base]
|
|
45
|
+
# @param object [Types::Base]
|
|
46
46
|
def initialize(object)
|
|
47
47
|
@object = object
|
|
48
48
|
super()
|
data/lib/rasn1/model.rb
CHANGED
|
@@ -70,9 +70,9 @@ module RASN1
|
|
|
70
70
|
class Model # rubocop:disable Metrics/ClassLength
|
|
71
71
|
# @private Base Element
|
|
72
72
|
BaseElem = Struct.new(:name, :proc, :content) do
|
|
73
|
-
# @param [String,Symbol]
|
|
74
|
-
# @param [Proc]
|
|
75
|
-
# @param [Array,nil]
|
|
73
|
+
# @param name [String,Symbol]
|
|
74
|
+
# @param proc [Proc]
|
|
75
|
+
# @param content [Array,nil]
|
|
76
76
|
def initialize(name, proc, content)
|
|
77
77
|
check_duplicates(content.map(&:name) + [name]) unless content.nil?
|
|
78
78
|
super
|
|
@@ -80,13 +80,17 @@ module RASN1
|
|
|
80
80
|
|
|
81
81
|
private
|
|
82
82
|
|
|
83
|
-
# @
|
|
83
|
+
# @param names [Array<String, Symbol>]
|
|
84
|
+
# @return [Array<String,Symbol>] The duplicate names found in the array
|
|
84
85
|
def find_all_duplicate_names(names)
|
|
85
86
|
names.group_by { |name| name }
|
|
86
87
|
.select { |_name, values| values.length > 1 }
|
|
87
88
|
.keys
|
|
88
89
|
end
|
|
89
90
|
|
|
91
|
+
# @param names [Array<String, Symbol>]
|
|
92
|
+
# @return [void]
|
|
93
|
+
# @raise [ModelValidationError] duplicate names in model definition
|
|
90
94
|
def check_duplicates(names)
|
|
91
95
|
duplicates = find_all_duplicate_names(names)
|
|
92
96
|
raise ModelValidationError, "Duplicate name #{duplicates.first} found" if duplicates.any?
|
|
@@ -113,16 +117,16 @@ module RASN1
|
|
|
113
117
|
attr_reader :options
|
|
114
118
|
|
|
115
119
|
# Use another model in this model
|
|
116
|
-
# @param [String,Symbol]
|
|
117
|
-
# @param [Class]
|
|
120
|
+
# @param name [String,Symbol]
|
|
121
|
+
# @param model_klass [Class]
|
|
118
122
|
# @return [Elem]
|
|
119
123
|
def model(name, model_klass)
|
|
120
124
|
@root = ModelElem.new(name, model_klass)
|
|
121
125
|
end
|
|
122
126
|
|
|
123
127
|
# Use a {Wrapper} around a {Types::Base} or a {Model} object
|
|
124
|
-
# @param [Types::Base,Model]
|
|
125
|
-
# @param [Hash]
|
|
128
|
+
# @param element [Types::Base,Model]
|
|
129
|
+
# @param options [Hash]
|
|
126
130
|
# @return [WrapElem]
|
|
127
131
|
# @since 0.12
|
|
128
132
|
def wrapper(element, options={})
|
|
@@ -140,7 +144,7 @@ module RASN1
|
|
|
140
144
|
# class Model2 < Model1
|
|
141
145
|
# root_options implicit: 1
|
|
142
146
|
# end
|
|
143
|
-
# @param [Hash]
|
|
147
|
+
# @param options [Hash]
|
|
144
148
|
# @return [void]
|
|
145
149
|
# @since 0.12.0 may change name through +:name+
|
|
146
150
|
def root_options(options)
|
|
@@ -152,7 +156,7 @@ module RASN1
|
|
|
152
156
|
end
|
|
153
157
|
|
|
154
158
|
# On inheritance, create +@root+ class variable
|
|
155
|
-
# @param [Class]
|
|
159
|
+
# @param klass [Class]
|
|
156
160
|
# @return [void]
|
|
157
161
|
def inherited(klass)
|
|
158
162
|
super
|
|
@@ -161,8 +165,8 @@ module RASN1
|
|
|
161
165
|
end
|
|
162
166
|
|
|
163
167
|
# @private
|
|
164
|
-
# @param [String,Symbol]
|
|
165
|
-
# @param [Class]
|
|
168
|
+
# @param accel_name [String,Symbol]
|
|
169
|
+
# @param klass [Class]
|
|
166
170
|
# @since 0.11.0
|
|
167
171
|
# @since 0.12.0 track source location on error (adfoster-r7)
|
|
168
172
|
def define_type_accel_base(accel_name, klass)
|
|
@@ -178,8 +182,8 @@ module RASN1
|
|
|
178
182
|
end
|
|
179
183
|
|
|
180
184
|
# @private
|
|
181
|
-
# @param [String,Symbol]
|
|
182
|
-
# @param [Class]
|
|
185
|
+
# @param accel_name [String,Symbol]
|
|
186
|
+
# @param klass [Class]
|
|
183
187
|
# @since 0.11.0
|
|
184
188
|
# @since 0.12.0 track source location on error (adfoster-r7)
|
|
185
189
|
def define_type_accel_of(accel_name, klass)
|
|
@@ -195,8 +199,8 @@ module RASN1
|
|
|
195
199
|
end
|
|
196
200
|
|
|
197
201
|
# Define an accelarator to access a type in a model definition
|
|
198
|
-
# @param [String]
|
|
199
|
-
# @param [Class]
|
|
202
|
+
# @param accel_name [String]
|
|
203
|
+
# @param klass [Class] class to instanciate
|
|
200
204
|
# @since 0.11.0
|
|
201
205
|
# @since 0.12.0 track source location on error (adfoster-r7)
|
|
202
206
|
def define_type_accel(accel_name, klass)
|
|
@@ -207,8 +211,8 @@ module RASN1
|
|
|
207
211
|
end
|
|
208
212
|
end
|
|
209
213
|
|
|
210
|
-
# @param [Symbol,String] name
|
|
211
|
-
# @param [Hash]
|
|
214
|
+
# @param name [Symbol,String] name of object in model
|
|
215
|
+
# @param options [Hash]
|
|
212
216
|
# @return [Elem]
|
|
213
217
|
# @note This method is named +objectid+ and not +object_id+ to not override
|
|
214
218
|
# +Object#object_id+.
|
|
@@ -219,8 +223,8 @@ module RASN1
|
|
|
219
223
|
@root = BaseElem.new(name, proc, nil)
|
|
220
224
|
end
|
|
221
225
|
|
|
222
|
-
# @param [Symbol,String] name
|
|
223
|
-
# @param [Hash]
|
|
226
|
+
# @param name [Symbol,String] name of object in model
|
|
227
|
+
# @param options [Hash]
|
|
224
228
|
# @return [Elem]
|
|
225
229
|
# @see Types::Any#initialize
|
|
226
230
|
def any(name, options={})
|
|
@@ -238,8 +242,8 @@ module RASN1
|
|
|
238
242
|
end
|
|
239
243
|
|
|
240
244
|
# Parse a DER/BER encoded string
|
|
241
|
-
# @param [String]
|
|
242
|
-
# @param [Boolean]
|
|
245
|
+
# @param str [String]
|
|
246
|
+
# @param ber [Boolean] accept BER encoding or not
|
|
243
247
|
# @return [Model]
|
|
244
248
|
# @raise [ASN1Error] error on parsing
|
|
245
249
|
def parse(str, ber: false)
|
|
@@ -253,20 +257,20 @@ module RASN1
|
|
|
253
257
|
|
|
254
258
|
# @!method sequence(name, options)
|
|
255
259
|
# @!scope class
|
|
256
|
-
# @param [Symbol,String] name
|
|
257
|
-
# @param [Hash]
|
|
260
|
+
# @param name [Symbol,String] name of object in model
|
|
261
|
+
# @param options [Hash]
|
|
258
262
|
# @return [Elem]
|
|
259
263
|
# @see Types::Sequence#initialize
|
|
260
264
|
# @!method set(name, options)
|
|
261
265
|
# @!scope class
|
|
262
|
-
# @param [Symbol,String] name
|
|
263
|
-
# @param [Hash]
|
|
266
|
+
# @param name [Symbol,String] name of object in model
|
|
267
|
+
# @param options [Hash]
|
|
264
268
|
# @return [Elem]
|
|
265
269
|
# @see Types::Set#initialize
|
|
266
270
|
# @!method choice(name, options)
|
|
267
271
|
# @!scope class
|
|
268
|
-
# @param [Symbol,String] name
|
|
269
|
-
# @param [Hash]
|
|
272
|
+
# @param name [Symbol,String] name of object in model
|
|
273
|
+
# @param options [Hash]
|
|
270
274
|
# @return [Elem]
|
|
271
275
|
# @see Types::Choice#initialize
|
|
272
276
|
%w[sequence set choice].each do |type|
|
|
@@ -275,16 +279,16 @@ module RASN1
|
|
|
275
279
|
|
|
276
280
|
# @!method sequence_of(name, type, options)
|
|
277
281
|
# @!scope class
|
|
278
|
-
# @param [Symbol,String] name
|
|
279
|
-
# @param [Model, Types::Base] type
|
|
280
|
-
# @param [Hash]
|
|
282
|
+
# @param name [Symbol,String] name of object in model
|
|
283
|
+
# @param type [Model, Types::Base] type for SEQUENCE OF
|
|
284
|
+
# @param options [Hash]
|
|
281
285
|
# @return [Elem]
|
|
282
286
|
# @see Types::SequenceOf#initialize
|
|
283
287
|
# @!method set_of(name, type, options)
|
|
284
288
|
# @!scope class
|
|
285
|
-
# @param [Symbol,String] name
|
|
286
|
-
# @param [Model, Types::Base] type
|
|
287
|
-
# @param [Hash]
|
|
289
|
+
# @param name [Symbol,String] name of object in model
|
|
290
|
+
# @param type [Model, Types::Base] type for SET OF
|
|
291
|
+
# @param options [Hash]
|
|
288
292
|
# @return [Elem]
|
|
289
293
|
# @see Types::SetOf#initialize
|
|
290
294
|
%w[sequence set].each do |type|
|
|
@@ -293,80 +297,80 @@ module RASN1
|
|
|
293
297
|
|
|
294
298
|
# @!method boolean(name, options)
|
|
295
299
|
# @!scope class
|
|
296
|
-
# @param [Symbol,String] name
|
|
297
|
-
# @param [Hash]
|
|
300
|
+
# @param name [Symbol,String] name of object in model
|
|
301
|
+
# @param options [Hash]
|
|
298
302
|
# @return [Elem]
|
|
299
303
|
# @see Types::Boolean#initialize
|
|
300
304
|
# @!method integer(name, options)
|
|
301
305
|
# @!scope class
|
|
302
|
-
# @param [Symbol,String] name
|
|
303
|
-
# @param [Hash]
|
|
306
|
+
# @param name [Symbol,String] name of object in model
|
|
307
|
+
# @param options [Hash]
|
|
304
308
|
# @return [Elem]
|
|
305
309
|
# @see Types::Integer#initialize
|
|
306
310
|
# @!method bit_string(name, options)
|
|
307
311
|
# @!scope class
|
|
308
|
-
# @param [Symbol,String] name
|
|
309
|
-
# @param [Hash]
|
|
312
|
+
# @param name [Symbol,String] name of object in model
|
|
313
|
+
# @param options [Hash]
|
|
310
314
|
# @return [Elem]
|
|
311
315
|
# @see Types::BitString#initialize
|
|
312
316
|
# @!method bmp_string(name, options)
|
|
313
317
|
# @!scope class
|
|
314
|
-
# @param [Symbol,String] name
|
|
315
|
-
# @param [Hash]
|
|
318
|
+
# @param name [Symbol,String] name of object in model
|
|
319
|
+
# @param options [Hash]
|
|
316
320
|
# @return [Elem]
|
|
317
321
|
# @see Types::BmpString#initialize
|
|
318
322
|
# @!method octet_string(name, options)
|
|
319
323
|
# @!scope class
|
|
320
|
-
# @param [Symbol,String] name
|
|
321
|
-
# @param [Hash]
|
|
324
|
+
# @param name [Symbol,String] name of object in model
|
|
325
|
+
# @param options [Hash]
|
|
322
326
|
# @return [Elem]
|
|
323
327
|
# @see Types::OctetString#initialize
|
|
324
328
|
# @!method null(name, options)
|
|
325
329
|
# @!scope class
|
|
326
|
-
# @param [Symbol,String] name
|
|
327
|
-
# @param [Hash]
|
|
330
|
+
# @param name [Symbol,String] name of object in model
|
|
331
|
+
# @param options [Hash]
|
|
328
332
|
# @return [Elem]
|
|
329
333
|
# @see Types::Null#initialize
|
|
330
334
|
# @!method enumerated(name, options)
|
|
331
335
|
# @!scope class
|
|
332
|
-
# @param [Symbol,String] name
|
|
333
|
-
# @param [Hash]
|
|
336
|
+
# @param name [Symbol,String] name of object in model
|
|
337
|
+
# @param options [Hash]
|
|
334
338
|
# @return [Elem]
|
|
335
339
|
# @see Types::Enumerated#initialize
|
|
336
340
|
# @!method universal_string(name, options)
|
|
337
341
|
# @!scope class
|
|
338
|
-
# @param [Symbol,String] name
|
|
339
|
-
# @param [Hash]
|
|
342
|
+
# @param name [Symbol,String] name of object in model
|
|
343
|
+
# @param options [Hash]
|
|
340
344
|
# @return [Elem]
|
|
341
345
|
# @see Types::UniversalString#initialize
|
|
342
346
|
# @!method utf8_string(name, options)
|
|
343
347
|
# @!scope class
|
|
344
|
-
# @param [Symbol,String] name
|
|
345
|
-
# @param [Hash]
|
|
348
|
+
# @param name [Symbol,String] name of object in model
|
|
349
|
+
# @param options [Hash]
|
|
346
350
|
# @return [Elem]
|
|
347
351
|
# @see Types::Utf8String#initialize
|
|
348
352
|
# @!method numeric_string(name, options)
|
|
349
353
|
# @!scope class
|
|
350
|
-
# @param [Symbol,String] name
|
|
351
|
-
# @param [Hash]
|
|
354
|
+
# @param name [Symbol,String] name of object in model
|
|
355
|
+
# @param options [Hash]
|
|
352
356
|
# @return [Elem]
|
|
353
357
|
# @see Types::NumericString#initialize
|
|
354
358
|
# @!method printable_string(name, options)
|
|
355
359
|
# @!scope class
|
|
356
|
-
# @param [Symbol,String] name
|
|
357
|
-
# @param [Hash]
|
|
360
|
+
# @param name [Symbol,String] name of object in model
|
|
361
|
+
# @param options [Hash]
|
|
358
362
|
# @return [Elem]
|
|
359
363
|
# @see Types::PrintableString#initialize
|
|
360
364
|
# @!method visible_string(name, options)
|
|
361
365
|
# @!scope class
|
|
362
|
-
# @param [Symbol,String] name
|
|
363
|
-
# @param [Hash]
|
|
366
|
+
# @param name [Symbol,String] name of object in model
|
|
367
|
+
# @param options [Hash]
|
|
364
368
|
# @return [Elem]
|
|
365
369
|
# @see Types::VisibleString#initialize
|
|
366
370
|
# @!method ia5_string(name, options)
|
|
367
371
|
# @!scope class
|
|
368
|
-
# @param [Symbol,String] name
|
|
369
|
-
# @param [Hash]
|
|
372
|
+
# @param name [Symbol,String] name of object in model
|
|
373
|
+
# @param options [Hash]
|
|
370
374
|
# @return [Elem]
|
|
371
375
|
# @see Types::IA5String#initialize
|
|
372
376
|
Types.primitives.each do |prim|
|
|
@@ -380,7 +384,7 @@ module RASN1
|
|
|
380
384
|
attr_reader :root
|
|
381
385
|
|
|
382
386
|
# Create a new instance of a {Model}
|
|
383
|
-
# @param [Hash]
|
|
387
|
+
# @param args [Hash]
|
|
384
388
|
def initialize(args={})
|
|
385
389
|
@elements = {}
|
|
386
390
|
generate_root(args)
|
|
@@ -390,11 +394,11 @@ module RASN1
|
|
|
390
394
|
|
|
391
395
|
# @overload [](name)
|
|
392
396
|
# Access an element of the model by its name
|
|
393
|
-
# @param [Symbol]
|
|
397
|
+
# @param name [Symbol]
|
|
394
398
|
# @return [Model, Types::Base, Wrapper]
|
|
395
399
|
# @overload [](idx)
|
|
396
400
|
# Access an element of root element by its index. Root element must be a {Types::Sequence} or {Types::SequenceOf}.
|
|
397
|
-
# @param [Integer]
|
|
401
|
+
# @param idx [Integer]
|
|
398
402
|
# @return [Model, Types::Base, Wrapper]
|
|
399
403
|
def [](name_or_idx)
|
|
400
404
|
case name_or_idx
|
|
@@ -409,8 +413,8 @@ module RASN1
|
|
|
409
413
|
end
|
|
410
414
|
|
|
411
415
|
# Set value of element +name+. Element should be a {Types::Base}.
|
|
412
|
-
# @param [String,Symbol]
|
|
413
|
-
# @param [Object]
|
|
416
|
+
# @param name [String,Symbol]
|
|
417
|
+
# @param value [Object]
|
|
414
418
|
# @return [Object] value
|
|
415
419
|
def []=(name, value)
|
|
416
420
|
# Here, use #[] to force generation for lazy elements
|
|
@@ -420,7 +424,8 @@ module RASN1
|
|
|
420
424
|
end
|
|
421
425
|
|
|
422
426
|
# clone @elements and initialize @root from this new @element.
|
|
423
|
-
|
|
427
|
+
# @return [void]
|
|
428
|
+
def initialize_copy(*)
|
|
424
429
|
@elements = @elements.clone
|
|
425
430
|
@root = @elements[@root_name]
|
|
426
431
|
end
|
|
@@ -455,8 +460,8 @@ module RASN1
|
|
|
455
460
|
end
|
|
456
461
|
|
|
457
462
|
# Parse a DER/BER encoded string, and modify object in-place.
|
|
458
|
-
# @param [String]
|
|
459
|
-
# @param [Boolean]
|
|
463
|
+
# @param der [String]
|
|
464
|
+
# @param ber [Boolean] accept BER encoding or not
|
|
460
465
|
# @return [Integer] number of parsed bytes
|
|
461
466
|
# @raise [ASN1Error] error on parsing
|
|
462
467
|
def parse!(der, ber: false)
|
|
@@ -464,6 +469,7 @@ module RASN1
|
|
|
464
469
|
end
|
|
465
470
|
|
|
466
471
|
# @private
|
|
472
|
+
# @!macro do_parse
|
|
467
473
|
# @see Types::Base#do_parse
|
|
468
474
|
def do_parse(der, ber: false)
|
|
469
475
|
root.do_parse(der, ber: ber)
|
|
@@ -474,8 +480,8 @@ module RASN1
|
|
|
474
480
|
# @return [Object,nil]
|
|
475
481
|
# @overload value(name, *args)
|
|
476
482
|
# Direct access to the value of +name+ (nested) element of model.
|
|
477
|
-
# @param [String,Symbol]
|
|
478
|
-
# @param [Array<Integer,String,Symbol>]
|
|
483
|
+
# @param name [String,Symbol]
|
|
484
|
+
# @param args [Array<Integer,String,Symbol>] more argument to access element. May be
|
|
479
485
|
# used to access content of a SequenceOf or a SetOf
|
|
480
486
|
# @return [Object,nil]
|
|
481
487
|
# @return [Object,nil]
|
|
@@ -508,10 +514,11 @@ module RASN1
|
|
|
508
514
|
end
|
|
509
515
|
end
|
|
510
516
|
|
|
511
|
-
# Return a hash image of model
|
|
512
|
-
# @return [Hash]
|
|
513
517
|
# Delegate some methods to root element
|
|
514
|
-
# @param [Symbol]
|
|
518
|
+
# @param meth [Symbol]
|
|
519
|
+
# @param args [Array]
|
|
520
|
+
# @param kwargs [Hash]
|
|
521
|
+
# @return [Object]
|
|
515
522
|
def method_missing(meth, *args, **kwargs)
|
|
516
523
|
if root.respond_to?(meth)
|
|
517
524
|
root.send(meth, *args, **kwargs)
|
|
@@ -520,18 +527,20 @@ module RASN1
|
|
|
520
527
|
end
|
|
521
528
|
end
|
|
522
529
|
|
|
530
|
+
# @param meth [Symbol]
|
|
523
531
|
# @return [Boolean]
|
|
524
532
|
def respond_to_missing?(meth, *)
|
|
525
533
|
root.respond_to?(meth) || super
|
|
526
534
|
end
|
|
527
535
|
|
|
536
|
+
# @param level [Integer]
|
|
528
537
|
# @return [String]
|
|
529
538
|
def inspect(level=0)
|
|
530
539
|
"#{' ' * level}(#{type}) #{root.inspect(-level)}"
|
|
531
540
|
end
|
|
532
541
|
|
|
533
542
|
# Objects are equal if they have same class AND same DER
|
|
534
|
-
# @param [Base]
|
|
543
|
+
# @param other [Base]
|
|
535
544
|
# @return [Boolean]
|
|
536
545
|
def ==(other)
|
|
537
546
|
(other.class == self.class) && (other.to_der == self.to_der)
|
|
@@ -540,7 +549,7 @@ module RASN1
|
|
|
540
549
|
protected
|
|
541
550
|
|
|
542
551
|
# Initialize model elements from +args+
|
|
543
|
-
# @param [Hash,Array]
|
|
552
|
+
# @param args [Hash,Array]
|
|
544
553
|
# @return [void]
|
|
545
554
|
def lazy_initialize(args)
|
|
546
555
|
case args
|
|
@@ -552,7 +561,7 @@ module RASN1
|
|
|
552
561
|
end
|
|
553
562
|
|
|
554
563
|
# Initialize an element from a hash
|
|
555
|
-
# @param [Hash]
|
|
564
|
+
# @param args [Hash]
|
|
556
565
|
# @return [void]
|
|
557
566
|
def lazy_initialize_hash(args)
|
|
558
567
|
args.each do |name, value|
|
|
@@ -568,7 +577,7 @@ module RASN1
|
|
|
568
577
|
end
|
|
569
578
|
|
|
570
579
|
# Initialize an sequence element from an array
|
|
571
|
-
# @param [Array]
|
|
580
|
+
# @param ary [Array]
|
|
572
581
|
# @return [void]
|
|
573
582
|
def lazy_initialize_array(ary)
|
|
574
583
|
raise Error, 'Only sequence types may be initialized with an array' unless SEQUENCE_TYPES.any? { |klass| root.is_a?(klass) }
|
|
@@ -579,7 +588,7 @@ module RASN1
|
|
|
579
588
|
end
|
|
580
589
|
|
|
581
590
|
# Give a (nested) element from its name
|
|
582
|
-
# @param [String, Symbol]
|
|
591
|
+
# @param name [String, Symbol]
|
|
583
592
|
# @return [Model, Types::Base, nil]
|
|
584
593
|
def by_name(name)
|
|
585
594
|
elt = self[name]
|
|
@@ -597,6 +606,8 @@ module RASN1
|
|
|
597
606
|
|
|
598
607
|
private
|
|
599
608
|
|
|
609
|
+
# @param args [Hash]
|
|
610
|
+
# @return [void]
|
|
600
611
|
def generate_root(args)
|
|
601
612
|
opts = args.slice(:name, :explicit, :implicit, :optional, :class, :default, :constructed, :tag_value)
|
|
602
613
|
root = self.class.class_eval { @root }
|
|
@@ -607,6 +618,9 @@ module RASN1
|
|
|
607
618
|
@elements[@root_name] = @root
|
|
608
619
|
end
|
|
609
620
|
|
|
621
|
+
# @param elt [BaseElem, ModelElem,WrapElem]
|
|
622
|
+
# @param opts [Hash]
|
|
623
|
+
# @return[Types::Base,Model,Wrapper]
|
|
610
624
|
def generate_element(elt, opts={})
|
|
611
625
|
case elt
|
|
612
626
|
when BaseElem
|
|
@@ -619,6 +633,9 @@ module RASN1
|
|
|
619
633
|
end
|
|
620
634
|
end
|
|
621
635
|
|
|
636
|
+
# @param elt [WrapElem]
|
|
637
|
+
# @param opts [Hash]
|
|
638
|
+
# @return[Wrapper]
|
|
622
639
|
def generate_wrapper_element(elt, opts)
|
|
623
640
|
wrapped = elt.element.is_a?(ModelElem) ? elt.element.klass : generate_element(elt.element)
|
|
624
641
|
options = elt.options.merge(opts)
|
|
@@ -629,6 +646,9 @@ module RASN1
|
|
|
629
646
|
wrapper
|
|
630
647
|
end
|
|
631
648
|
|
|
649
|
+
# @param elt [BaseElem]
|
|
650
|
+
# @param opts [Hash]
|
|
651
|
+
# @return[Types::Base]
|
|
632
652
|
def generate_base_element(elt, opts)
|
|
633
653
|
element = elt.proc.call(opts)
|
|
634
654
|
return element if elt.content.nil?
|
|
@@ -643,6 +663,8 @@ module RASN1
|
|
|
643
663
|
# @author sdaubert
|
|
644
664
|
# @author lemontree55
|
|
645
665
|
# @author adfoster-r7
|
|
666
|
+
# @param element [Model, Types::Base, Wrapper,nil]
|
|
667
|
+
# @return [Hash]
|
|
646
668
|
def private_to_h(element=nil) # rubocop:disable Metrics/CyclomaticComplexity
|
|
647
669
|
my_element = element || root
|
|
648
670
|
value = case my_element
|
|
@@ -666,6 +688,8 @@ module RASN1
|
|
|
666
688
|
end
|
|
667
689
|
end
|
|
668
690
|
|
|
691
|
+
# @param elt [Model]
|
|
692
|
+
# @return [Hash]
|
|
669
693
|
def model_to_h(elt)
|
|
670
694
|
hsh = elt.to_h
|
|
671
695
|
if root.is_a?(Types::Choice)
|
|
@@ -675,6 +699,8 @@ module RASN1
|
|
|
675
699
|
end
|
|
676
700
|
end
|
|
677
701
|
|
|
702
|
+
# @param elt [Types::SequenceOf]
|
|
703
|
+
# @return [Array<Hash>]
|
|
678
704
|
def sequence_of_to_h(elt)
|
|
679
705
|
if elt.of_type < Model
|
|
680
706
|
elt.value&.map { |el| el.to_h.values.first }
|
|
@@ -683,6 +709,8 @@ module RASN1
|
|
|
683
709
|
end
|
|
684
710
|
end
|
|
685
711
|
|
|
712
|
+
# @param seq [Types::Sequence]
|
|
713
|
+
# @return [Hash]
|
|
686
714
|
def sequence_to_h(seq)
|
|
687
715
|
ary = seq.value&.map do |el|
|
|
688
716
|
next if el.optional? && el.value.nil?
|
|
@@ -699,6 +727,9 @@ module RASN1
|
|
|
699
727
|
ary.compact.to_h
|
|
700
728
|
end
|
|
701
729
|
|
|
730
|
+
# @param elt [Types::Choice]
|
|
731
|
+
# @return [Hash]
|
|
732
|
+
# @raise [ChoiceError] no chosen element
|
|
702
733
|
def choice_to_h(elt)
|
|
703
734
|
raise ChoiceError.new(elt) if elt.chosen.nil?
|
|
704
735
|
|
|
@@ -706,10 +737,14 @@ module RASN1
|
|
|
706
737
|
{ chosen.name => private_to_h(chosen) }
|
|
707
738
|
end
|
|
708
739
|
|
|
740
|
+
# @param key [String,Symbol]
|
|
741
|
+
# @return [Symbol]
|
|
709
742
|
def unwrap_keyname(key)
|
|
710
743
|
key.to_s.delete_suffix('_wrapper').to_sym
|
|
711
744
|
end
|
|
712
745
|
|
|
746
|
+
# @param wrap [Wrapper]
|
|
747
|
+
# @return [Hash]
|
|
713
748
|
def wrapper_to_h(wrap)
|
|
714
749
|
el = wrap.element
|
|
715
750
|
case el
|