rasn1 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +2 -2
- data/lib/rasn1/types/base.rb +22 -5
- data/lib/rasn1/types/enumerated.rb +6 -0
- data/lib/rasn1/types/sequence_of.rb +7 -1
- data/lib/rasn1/types/set_of.rb +6 -0
- data/lib/rasn1/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8aaca93facba30994eb952b5df2eb4a2cfdbbebc39d84ca60f3f9f0449e84fc
|
4
|
+
data.tar.gz: 2006cdbcd04330fe31bc5d440d062b4f32ee07c3b7dff21d666dfab2e7a0e461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e3e8e31202c26775712a897a14fb3524720ff8727219fd107a0eb9458eff2179af55ee098a1f98fdc49054b3aeffa64101b762108242e52d90f4b3e8f5002e1
|
7
|
+
data.tar.gz: 0fc64ce3e167051e614bb4c0de0cb437ff031ae913f8b737a2256d3bfb977c903508951d2c8cf4b757b6e69ee1903e8ac729a97d3195e3f05c2b3fc1bc3399a0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -55,8 +55,8 @@ More comple classes may be designed by nesting simple classes. For example:
|
|
55
55
|
class ComplexRecord < RASN1::Model
|
56
56
|
sequence :cplx_record,
|
57
57
|
content: [boolean(:bool),
|
58
|
-
|
59
|
-
|
58
|
+
octet_string(:data, explicit: 0),
|
59
|
+
model(:a_record, Record)]
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
data/lib/rasn1/types/base.rb
CHANGED
@@ -2,7 +2,7 @@ module RASN1
|
|
2
2
|
module Types
|
3
3
|
|
4
4
|
# @abstract This is base class for all ASN.1 types.
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# Subclasses SHOULD define:
|
7
7
|
# * a TAG constant defining ASN.1 tag number,
|
8
8
|
# * a private method {#value_to_der} converting its {#value} to DER,
|
@@ -74,6 +74,12 @@ module RASN1
|
|
74
74
|
@type = self.to_s.gsub(/.*::/, '').gsub(/([a-z0-9])([A-Z])/, '\1 \2').upcase
|
75
75
|
end
|
76
76
|
|
77
|
+
# Get ASN.1 type used to encode this one
|
78
|
+
# @return [String]
|
79
|
+
def self.encode_type
|
80
|
+
type
|
81
|
+
end
|
82
|
+
|
77
83
|
# Parse a DER or BER string
|
78
84
|
# @param [String] der_or_ber string to parse
|
79
85
|
# @param [Hash] options
|
@@ -222,6 +228,7 @@ module RASN1
|
|
222
228
|
if explicit?
|
223
229
|
# Delegate to #explicit type to generate sub-tag
|
224
230
|
type = explicit_type
|
231
|
+
type.value = @value
|
225
232
|
type.parse!(data)
|
226
233
|
@value = type.value
|
227
234
|
else
|
@@ -374,7 +381,7 @@ module RASN1
|
|
374
381
|
elsif !@default.nil?
|
375
382
|
@value = @default
|
376
383
|
else
|
377
|
-
raise_tag_error(
|
384
|
+
raise_tag_error(tag)
|
378
385
|
end
|
379
386
|
false
|
380
387
|
else
|
@@ -418,11 +425,21 @@ module RASN1
|
|
418
425
|
self.class.new
|
419
426
|
end
|
420
427
|
|
421
|
-
def raise_tag_error(
|
422
|
-
msg = "Expected #{
|
428
|
+
def raise_tag_error(tag)
|
429
|
+
msg = "Expected #{self2name} but get #{tag2name(tag)}"
|
423
430
|
raise ASN1Error, msg
|
424
431
|
end
|
425
432
|
|
433
|
+
def self2name
|
434
|
+
name = CLASSES.key(tag & 0xc0).to_s.upcase
|
435
|
+
name << " #{tag & Constructed::ASN1_PC > 0 ? 'CONSTRUCTED' : 'PRIMITIVE'}"
|
436
|
+
if implicit? || explicit?
|
437
|
+
name << ' 0x%02X' % (tag & 0x1f)
|
438
|
+
else
|
439
|
+
name << ' ' << self.class.type
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
426
443
|
def tag2name(tag)
|
427
444
|
return 'no tag' if tag.nil? or tag.empty?
|
428
445
|
|
@@ -432,7 +449,7 @@ module RASN1
|
|
432
449
|
type = Types.constants.map { |c| Types.const_get(c) }.
|
433
450
|
select { |klass| klass < Primitive || klass < Constructed }.
|
434
451
|
find { |klass| klass::TAG == itag & 0x1f }
|
435
|
-
name << " #{type.nil? ? "0x%02X" % (itag & 0x1f) : type.
|
452
|
+
name << " #{type.nil? ? "0x%02X" % (itag & 0x1f) : type.encode_type }"
|
436
453
|
end
|
437
454
|
end
|
438
455
|
end
|
@@ -21,6 +21,12 @@ module RASN1
|
|
21
21
|
# @return [Hash]
|
22
22
|
attr_reader :enum
|
23
23
|
|
24
|
+
# An ENUMERATED is encoded as an INTEGER.
|
25
|
+
# @return ['INTEGER']
|
26
|
+
def self.encode_type
|
27
|
+
Integer.encode_type
|
28
|
+
end
|
29
|
+
|
24
30
|
# @overload initialize(options={})
|
25
31
|
# @option options [Hash] :enum enumeration hash. Keys are names, and values
|
26
32
|
# are integers. This key is mandatory.
|
@@ -36,7 +36,7 @@ module RASN1
|
|
36
36
|
# seqof << { bool: false, int: 65535 }
|
37
37
|
# # Generate DER string
|
38
38
|
# der = seqof.to_der # => String
|
39
|
-
# # parse
|
39
|
+
# # parse
|
40
40
|
# seqof.parse! der
|
41
41
|
#
|
42
42
|
# After parsing, a SEQUENCE OF may be accessed as an Array:
|
@@ -50,6 +50,12 @@ module RASN1
|
|
50
50
|
# @return [Class, Base]
|
51
51
|
attr_reader :of_type
|
52
52
|
|
53
|
+
# A SEQUENCE OF is encoded as a SEQUENCE.
|
54
|
+
# @return ['SEQUENCE']
|
55
|
+
def self.encoded_type
|
56
|
+
Sequence.encoded_type
|
57
|
+
end
|
58
|
+
|
53
59
|
# @param [Symbol, String] name name for this tag in grammar
|
54
60
|
# @param [Class, Base] of_type base type for sequence of
|
55
61
|
# @see Base#initialize
|
data/lib/rasn1/types/set_of.rb
CHANGED
data/lib/rasn1/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasn1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Daubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|