rasn1 0.9.0 → 0.10.0

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: b0f5f3f69aaae20cfd16576f565bc52d198bea49921a0db15e3e2a95a4947853
4
- data.tar.gz: c3c1f6b2d5019febcbff3812611d624094b7aaefc238bd70109d4c278be3af8c
3
+ metadata.gz: 0d38c6038ef58e60eb51d02fc20416188918a736386c4273a713f1be2d2535a1
4
+ data.tar.gz: fd3b045acdd39707540c3909f24aa8a2e2ae6ed11e46339f90903b7ef96da0df
5
5
  SHA512:
6
- metadata.gz: 51e54a40d6608074e76ba0d18d51462e82fba109a4258b9082875bafe36476060186d2081cabb4e2d17e1140f53a4700906a053fdb05638ceb060560a337d05b
7
- data.tar.gz: 434ca0398606fb411351a2d43b6701b70f9512043abea8768e21832a2a1800be8347efef50b17b01239ce953b49cb21b64860e2d252cc64e9c696a514de564ea
6
+ metadata.gz: f21443bccf45e549a1999bedcef1858ff175ab9e65bdb09f048ad4723d4ac64be80338cbff491ddaf31654aabaa1ad567af4925edf24297e757a42c901684ff2
7
+ data.tar.gz: ad0a89d6a6d634b83fe89f45f64f327f5740f68be8dfe6ca143bcfcf028e387c9859ec665da82e5f0f8d3576133ef74cf63b24d511da19e2589a53909bcf95ce
@@ -58,7 +58,7 @@ module RASN1
58
58
  return unless @value.is_a?(Array)
59
59
 
60
60
  case idx_or_name
61
- when Integer
61
+ when ::Integer
62
62
  @value[idx_or_name.to_i]
63
63
  when String, Symbol
64
64
  @value.find { |elt| elt.name == idx_or_name }
@@ -13,7 +13,8 @@ module RASN1
13
13
  # # Create a SEQUENCE OF INTEGER
14
14
  # seqof = RASN1::Types::SequenceOf.new(RASN1::Types::Integer)
15
15
  # # Set integer values
16
- # seqof.value = [1, 2, 3, 4]
16
+ # seqof.value = [1, 2, 3, 4].map { |i| RASN1::Types::Integer.new(value: i) }
17
+ # seqof << 5 # infer a RASN1::Types::Integer with given value
17
18
  #
18
19
  # == Use with {Constructed} types
19
20
  # SEQUENCE OF may be used to create sequence of composed types. For example:
@@ -79,9 +80,13 @@ module RASN1
79
80
  end
80
81
 
81
82
  # Add an item to SEQUENCE OF
82
- # @param [Array,Hash, Model]
83
+ # @param [Object] obj
84
+ # @note
85
+ # * if a SEQUENCE OF primitive type, +obj+ is an instance of primitive type or equivalent Ruby type
86
+ # * if a SEQUENCE OF composed type, +obj+ is an array of ruby type instances
87
+ # * if a SEQUENCE OF model, +obj+ is either a Model or a Hash
83
88
  def <<(obj)
84
- return push_array_of_primitive(obj) if of_type_class < Primitive
89
+ return push_primitive(obj) if of_type_class < Primitive
85
90
  return push_composed_array(obj) if composed_of_type?
86
91
 
87
92
  push_model(obj)
@@ -112,7 +117,7 @@ module RASN1
112
117
  str << item.inspect(level)
113
118
  str << "\n" unless str.end_with?("\n")
114
119
  else
115
- str << ' ' * level + "#{item.inspect}\n"
120
+ str << (' ' * level) << "#{item.inspect}\n"
116
121
  end
117
122
  end
118
123
  str
@@ -151,10 +156,14 @@ module RASN1
151
156
  self.class.new(self.of_type)
152
157
  end
153
158
 
154
- def push_array_of_primitive(obj)
155
- raise ASN1Error, 'object to add should be an Array' unless obj.is_a?(Array)
156
-
157
- @value += obj.map { |item| of_type_class.new(value: item) }
159
+ def push_primitive(obj)
160
+ @value <<
161
+ case obj
162
+ when Primitive
163
+ obj
164
+ else
165
+ of_type_class.new(value: obj)
166
+ end
158
167
  end
159
168
 
160
169
  def push_composed_array(obj)
data/lib/rasn1/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RASN1
4
- VERSION = '0.9.0'
4
+ VERSION = '0.10.0'
5
5
  end
data/lib/rasn1.rb CHANGED
@@ -17,7 +17,7 @@ module RASN1
17
17
  class ClassError < Error
18
18
  # @return [String]
19
19
  def message
20
- "Tag class should be a symbol: #{Types::Base::CLASSES.keys.join(', ')}"
20
+ "Tag class should be a symbol among: #{Types::Base::CLASSES.keys.join(', ')}"
21
21
  end
22
22
  end
23
23
 
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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Daubert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-27 00:00:00.000000000 Z
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake