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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c08cdf722e9b7662ef2bd5158658fecde6e1834af4d9e2c9651ee13136916383
4
- data.tar.gz: 55f0019a6325ff72ce6c1f791d46d488e53416168db23c4a9ffecbc93cf32c03
3
+ metadata.gz: d8aaca93facba30994eb952b5df2eb4a2cfdbbebc39d84ca60f3f9f0449e84fc
4
+ data.tar.gz: 2006cdbcd04330fe31bc5d440d062b4f32ee07c3b7dff21d666dfab2e7a0e461
5
5
  SHA512:
6
- metadata.gz: de89acb4c79a7ea05c5801400b9b8973b6ab0481ab1107cb8122254541dc9f5ffeb806c28d8f2aca7266c8be5a02003d1ddaa4f9b7bb451619956546a96bffe6
7
- data.tar.gz: c7ebbd8871eda39c362fd9950dc5ce85b5152dbff3230c97367dde58c1aa2fcacd521c70d15544ed28387a9cf28e6ee33d36a41755dec16bc896308a46c50470
6
+ metadata.gz: 5e3e8e31202c26775712a897a14fb3524720ff8727219fd107a0eb9458eff2179af55ee098a1f98fdc49054b3aeffa64101b762108242e52d90f4b3e8f5002e1
7
+ data.tar.gz: 0fc64ce3e167051e614bb4c0de0cb437ff031ae913f8b737a2256d3bfb977c903508951d2c8cf4b757b6e69ee1903e8ac729a97d3195e3f05c2b3fc1bc3399a0
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
3
  - 2.3
5
4
  - 2.4
6
5
  - 2.5
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
- octet_string(:data, explicit: 0),
59
- model(:a_record, Record)]
58
+ octet_string(:data, explicit: 0),
59
+ model(:a_record, Record)]
60
60
  end
61
61
  ```
62
62
 
@@ -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(encode_tag, tag)
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(expected_tag, tag)
422
- msg = "Expected #{tag2name(expected_tag)} but get #{tag2name(tag)}"
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.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
@@ -5,6 +5,12 @@ module RASN1
5
5
  # @author Sylvain Daubert
6
6
  class SetOf < SequenceOf
7
7
  TAG = Set::TAG
8
+
9
+ # A SET OF is encoded as a SET.
10
+ # @return ['SET']
11
+ def self.encoded_type
12
+ Set.encoded_type
13
+ end
8
14
  end
9
15
  end
10
16
  end
data/lib/rasn1/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RASN1
2
- VERSION = "0.6.3"
2
+ VERSION = '0.6.4'
3
3
  end
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.3
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-07-04 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard