rasn2 0.16.0 → 1.0.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/{rasn1 → rasn2}/errors.rb +2 -2
  3. data/lib/rasn2/helpers/colorize.rb +119 -0
  4. data/lib/{rasn1 → rasn2}/model.rb +16 -12
  5. data/lib/{rasn1 → rasn2}/schema_parser.rb +10 -10
  6. data/lib/{rasn1 → rasn2}/tracer.rb +15 -14
  7. data/lib/{rasn1 → rasn2}/types/any.rb +18 -34
  8. data/lib/{rasn1 → rasn2}/types/base.rb +120 -82
  9. data/lib/{rasn1 → rasn2}/types/bit_string.rb +3 -6
  10. data/lib/{rasn1 → rasn2}/types/bmp_string.rb +1 -1
  11. data/lib/{rasn1 → rasn2}/types/boolean.rb +2 -2
  12. data/lib/{rasn1 → rasn2}/types/choice.rb +5 -5
  13. data/lib/{rasn1 → rasn2}/types/constrained.rb +2 -2
  14. data/lib/{rasn1 → rasn2}/types/constructed.rb +1 -24
  15. data/lib/{rasn1 → rasn2}/types/enumerated.rb +3 -3
  16. data/lib/{rasn1 → rasn2}/types/generalized_time.rb +1 -1
  17. data/lib/{rasn1 → rasn2}/types/ia5_string.rb +5 -1
  18. data/lib/{rasn1 → rasn2}/types/integer.rb +3 -2
  19. data/lib/{rasn1 → rasn2}/types/null.rb +6 -5
  20. data/lib/{rasn1 → rasn2}/types/numeric_string.rb +1 -1
  21. data/lib/{rasn1 → rasn2}/types/object_id.rb +1 -1
  22. data/lib/{rasn1 → rasn2}/types/octet_string.rb +3 -6
  23. data/lib/{rasn1 → rasn2}/types/primitive.rb +1 -1
  24. data/lib/{rasn1 → rasn2}/types/printable_string.rb +1 -1
  25. data/lib/{rasn1 → rasn2}/types/sequence.rb +6 -6
  26. data/lib/{rasn1 → rasn2}/types/sequence_of.rb +20 -25
  27. data/lib/{rasn1 → rasn2}/types/set.rb +5 -5
  28. data/lib/{rasn1 → rasn2}/types/set_of.rb +1 -1
  29. data/lib/{rasn1 → rasn2}/types/tag.rb +13 -28
  30. data/lib/{rasn1 → rasn2}/types/universal_string.rb +1 -1
  31. data/lib/{rasn1 → rasn2}/types/utc_time.rb +1 -1
  32. data/lib/{rasn1 → rasn2}/types/utf8_string.rb +1 -1
  33. data/lib/{rasn1 → rasn2}/types/visible_string.rb +1 -1
  34. data/lib/{rasn1 → rasn2}/types.rb +7 -5
  35. data/lib/{rasn1 → rasn2}/value_notation.rb +5 -5
  36. data/lib/rasn2/version.rb +6 -0
  37. data/lib/{rasn1 → rasn2}/wrapper.rb +8 -15
  38. data/lib/{rasn1.rb → rasn2.rb} +14 -14
  39. metadata +40 -40
  40. data/lib/rasn1/helpers/colorize.rb +0 -76
  41. data/lib/rasn1/version.rb +0 -6
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  module Types
5
5
  # ASN.1 SEQUENCE OF
6
6
  #
@@ -11,28 +11,28 @@ module RASN1
11
11
  # Integers ::= SEQUENCE OF INTEGER
12
12
  # do:
13
13
  # # Create a SEQUENCE OF INTEGER
14
- # seqof = RASN1::Types::SequenceOf.new(RASN1::Types::Integer)
14
+ # seqof = RASN2::Types::SequenceOf.new(RASN2::Types::Integer)
15
15
  # # Set integer values
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
16
+ # seqof.value = [1, 2, 3, 4].map { |i| RASN2::Types::Integer.new(value: i) }
17
+ # seqof << 5 # infer a RASN2::Types::Integer with given value
18
18
  #
19
19
  # == Use with {Constructed} types
20
20
  # SEQUENCE OF may be used to create sequence of composed types. For example:
21
- # composed_type = RASN1::Types::Sequence.new
22
- # commposed_type.value = [RASN1::Types::Integer,
23
- # RASN1::Types::OctetString]
24
- # seqof = RASN1::Types::SequenceOf.new(composed_type)
21
+ # composed_type = RASN2::Types::Sequence.new
22
+ # commposed_type.value = [RASN2::Types::Integer,
23
+ # RASN2::Types::OctetString]
24
+ # seqof = RASN2::Types::SequenceOf.new(composed_type)
25
25
  # seqof << [0, 'data0']
26
26
  # seqof << [1, 'data1']
27
27
  #
28
28
  # == Use with {Model}
29
29
  # SEQUENCE OF may also be used with a Model type:
30
- # class MyModel < RASN1::Model
30
+ # class MyModel < RASN2::Model
31
31
  # sequence :seq,
32
32
  # content: [boolean(:bool), integer(:int)]
33
33
  # end
34
34
  #
35
- # seqof = RASN1::Types::SequenceOf.new(:record, MyModel)
35
+ # seqof = RASN2::Types::SequenceOf.new(:record, MyModel)
36
36
  # # set values
37
37
  # seqof << { bool: true, int: 12 }
38
38
  # seqof << { bool: false, int: 65535 }
@@ -107,22 +107,17 @@ module RASN1
107
107
 
108
108
  # @param [::Integer] level
109
109
  # @return [String]
110
- def inspect(level=0)
111
- str = common_inspect(level)
112
- str << "\n"
113
- level = level.abs + 1
114
- @value.each do |item|
115
- case item
116
- when Base, Model
117
- next if item.optional? && item.value.nil?
118
-
119
- str << item.inspect(level)
120
- str << "\n" unless str.end_with?("\n")
121
- else
122
- str << (' ' * level) << "#{item.inspect}\n"
123
- end
110
+ def inspect(level=0, color: false)
111
+ new_level = level.abs + 1
112
+ begin_colorizer(color)
113
+ name = @name ? "#{colorize_name(@name)} " : ''
114
+ lines = []
115
+ lines << "#{" " * level}#{name}SEQUENCE OF:"
116
+ lines += @value.map do |item|
117
+ item.inspect(new_level, color: color)
124
118
  end
125
- str
119
+ end_colorizer
120
+ lines.join("\n")
126
121
  end
127
122
 
128
123
  # Make sequence of value from +der+ string
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  module Types
5
5
  # ASN.1 set
6
6
  #
@@ -13,11 +13,11 @@ module RASN1
13
13
  # house [1] IMPLICIT INTEGER DEFAULT 0
14
14
  # }
15
15
  # do:
16
- # set = RASN1::Types::Set.new
16
+ # set = RASN2::Types::Set.new
17
17
  # set.value = [
18
- # RASN1::Types::Integer
19
- # RASN1::Types::Integer(explicit: 0, optional: true),
20
- # RASN1::Types::Integer(implicit: 1, default: 0)
18
+ # RASN2::Types::Integer
19
+ # RASN2::Types::Integer(explicit: 0, optional: true),
20
+ # RASN2::Types::Integer(implicit: 1, default: 0)
21
21
  # ]
22
22
  # @author Sylvain Daubert
23
23
  class Set < Sequence
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  module Types
5
5
  # ASN.1 SET OF
6
6
  # @author Sylvain Daubert
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  module Types
5
5
  # ASN.1 Tag constructed type.
6
6
  #
@@ -24,7 +24,7 @@ module RASN1
24
24
  # generic = Tag.new(tag: :private, value: [Integer.new, OctetString.new])
25
25
  # # or equivalently
26
26
  # generic = Tag.new(any_private: true, value: [Integer.new])
27
- class Tag < Constructed
27
+ class Tag < Base
28
28
  # Placeholder ID — not used directly; tag is always dynamic.
29
29
  ID = 0
30
30
 
@@ -72,22 +72,6 @@ module RASN1
72
72
  end
73
73
  end
74
74
 
75
- # Parse constructed content from DER
76
- # @param [String] der
77
- # @param [Boolean] ber
78
- # @return [void]
79
- def der_to_value(der, ber: false) # rubocop:disable Lint/UnusedMethodArgument
80
- if @value.is_a?(Array) && !@value.empty?
81
- nb_bytes = 0
82
- @value.each do |element|
83
- nb_bytes += element.parse!(der[nb_bytes..])
84
- end
85
- else
86
- @value = der
87
- der.length
88
- end
89
- end
90
-
91
75
  private
92
76
 
93
77
  def extract_tag_binding(options)
@@ -114,6 +98,12 @@ module RASN1
114
98
  end
115
99
 
116
100
  def check_id(der)
101
+ asn1_class, pc, tag_id, size = Types.decode_identifier_octets(der)
102
+ @asn1_class = asn1_class
103
+ @constructed = pc
104
+ @tag = tag_id
105
+ @tag_size = size
106
+
117
107
  return check_any_private_id(der) if @any_private && @accepted_tags.empty?
118
108
  return check_multi_tag_id(der) if @accepted_tags.length > 1
119
109
 
@@ -123,10 +113,7 @@ module RASN1
123
113
  def check_any_private_id(der)
124
114
  return no_match(der) if der.nil? || der.empty?
125
115
 
126
- first_octet = der.unpack1('C').to_i
127
- asn1_class_bits = first_octet & CLASS_MASK
128
- if asn1_class_bits == CLASSES[:private]
129
- _, _, tag_id, = Types.decode_identifier_octets(der)
116
+ if asn1_class == :private
130
117
  @id_value = tag_id
131
118
  @matched_tag = tag_id
132
119
  true
@@ -164,15 +151,13 @@ module RASN1
164
151
 
165
152
  def value_to_der
166
153
  case @value
167
- when Array then @value.map(&:to_der).join
168
- else @value.to_s
154
+ when Array
155
+ @value.map(&:to_der).join
156
+ else
157
+ @value.to_s
169
158
  end
170
159
  end
171
160
 
172
- def trace_data
173
- ''
174
- end
175
-
176
161
  def explicit_type
177
162
  opts = { name: name, value: @value }
178
163
  if @accepted_tags.length == 1
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  module Types
5
5
  # ASN.1 UniversalString
6
6
  # @since 0.13.0
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'date'
4
4
 
5
- module RASN1
5
+ module RASN2
6
6
  module Types
7
7
  # ASN.1 UTCTime
8
8
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  module Types
5
5
  # ASN.1 UTF8 String
6
6
  # @author Sylvain Daubert
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  module Types
5
5
  # Create VisibleString as a Constrained subclass of IA5String
6
6
  Types.define_type(:VisibleString, from: IA5String) do |value|
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative 'types/constrained'
4
4
 
5
- module RASN1
5
+ module RASN2
6
6
  # This modules is a namesapce for all ASN.1 type classes.
7
7
  # @author Sylvain Daubert
8
8
  module Types
@@ -15,6 +15,7 @@ module RASN1
15
15
  return @primitives unless @primitives.empty?
16
16
 
17
17
  @primitives = self.constants.map { |c| Types.const_get(c) }
18
+ .grep(Class)
18
19
  .select { |klass| klass < Primitive }
19
20
  end
20
21
 
@@ -24,6 +25,7 @@ module RASN1
24
25
  return @constructed unless @constructed.empty?
25
26
 
26
27
  @constructed = self.constants.map { |c| Types.const_get(c) }
28
+ .grep(Class)
27
29
  .select { |klass| klass < Constructed }
28
30
  end
29
31
 
@@ -67,10 +69,10 @@ module RASN1
67
69
  asn1class, pc, id, = self.decode_identifier_octets(der)
68
70
  # cache_id: check versus class and 5 LSB bits
69
71
  cache_id = der.unpack1('C') & 0xdf
70
- klass = cache_id < Types::Base::MULTI_OCTETS_ID ? @id2types[id] : Types::Base
72
+ klass = cache_id < Types::Base::MULTI_OCTETS_ID ? @id2types[id] : Types::Tag
71
73
  is_constructed = (pc == :constructed)
72
74
  options = { class: asn1class, constructed: is_constructed }
73
- options[:tag_value] = id if klass == Types::Base
75
+ options[:tag_value] = id if klass == Types::Tag
74
76
  klass.new(options)
75
77
  end
76
78
 
@@ -89,7 +91,7 @@ module RASN1
89
91
  # This new type may have a constraint defines on it.
90
92
  # @param [Symbol,String] name new type name. Must start with a capital letter.
91
93
  # @param [Types::Base] from class from which inherits
92
- # @param [Module] in_module module in which creates new type (default to {RASN1::Types})
94
+ # @param [Module] in_module module in which creates new type (default to {RASN2::Types})
93
95
  # @return [Class] newly created class
94
96
  # @yieldparam [Object] value value to set to type, or infered at parsing
95
97
  # @yieldreturn [Boolean]
@@ -98,7 +100,7 @@ module RASN1
98
100
  # @example
99
101
  # # Define a new UInt32 type
100
102
  # # UInt32 ::= INTEGER (0 .. 4294967295)
101
- # RASN1::Types.define_type('UInt32', from: RASN1::Types::Integer) do |value|
103
+ # RASN2::Types.define_type('UInt32', from: RASN2::Types::Integer) do |value|
102
104
  # (value >= 0) && (value < 2**32)
103
105
  # end
104
106
  def self.define_type(name, from:, in_module: self, &block)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RASN1
3
+ module RASN2
4
4
  # Support for ASN.1 value notation (text representation of ASN.1 data instances).
5
5
  #
6
6
  # ASN.1 value notation allows defining values for ASN.1 types in a human-readable
@@ -16,8 +16,8 @@ module RASN1
16
16
  # to generate such text from {Model} instances.
17
17
  #
18
18
  # @example Parse a value notation string
19
- # models = RASN1::SchemaParser.parse_file('schema.asn')
20
- # record = RASN1::ValueNotation.parse(
19
+ # models = RASN2::SchemaParser.parse_file('schema.asn')
20
+ # record = RASN2::ValueNotation.parse(
21
21
  # File.read('instance.asn'),
22
22
  # models: models
23
23
  # )
@@ -25,13 +25,13 @@ module RASN1
25
25
  #
26
26
  # @example Generate value notation from a model
27
27
  # record = PersonnelRecord.new(name: 'John Doe', title: 'Engineer', age: 30, employed: true)
28
- # text = RASN1::ValueNotation.emit(record, name: 'myPerson', type_name: 'PersonnelRecord')
28
+ # text = RASN2::ValueNotation.emit(record, name: 'myPerson', type_name: 'PersonnelRecord')
29
29
  #
30
30
  # @author rickmark
31
31
  # @since 0.17.0
32
32
  module ValueNotation
33
33
  # Error raised when parsing or emitting value notation fails
34
- class Error < RASN1::Error; end
34
+ class Error < RASN2::Error; end
35
35
 
36
36
  class << self
37
37
  # Parse an ASN.1 value notation string and populate a model instance.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RASN2
4
+ # RASN2 version number
5
+ VERSION = '1.0.1'
6
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'delegate'
4
4
 
5
- module RASN1
5
+ module RASN2
6
6
  # This class is used to wrap a {Types::Base} or {Model} instance to force its options.
7
7
  #
8
8
  # == Usage
9
- # This class may be used to wrap another RASN1 object by 4 ways:
9
+ # This class may be used to wrap another RASN2 object by 4 ways:
10
10
  # * wrap an object to modify its options,
11
11
  # * implicitly wrap an object (i.e. change its tag),
12
12
  # * explicitly wrap an object (i.e wrap the object in another explicit ASN.1 tag),
@@ -14,15 +14,15 @@ module RASN1
14
14
  #
15
15
  # @example Wrapping object
16
16
  # # object to wrap
17
- # int = RASN1::Types::Integer.new(implicit: 1) # its tag is 0x81
17
+ # int = RASN2::Types::Integer.new(implicit: 1) # its tag is 0x81
18
18
  # # simple wrapper, change an option
19
- # wrapper = RASN1::Wrapper.new(int, default: 1)
19
+ # wrapper = RASN2::Wrapper.new(int, default: 1)
20
20
  # # implicit wrapper
21
- # wrapper = RASN1::Wrapper.new(int, implicit: 3) # wrapped int tag is now 0x83
21
+ # wrapper = RASN2::Wrapper.new(int, implicit: 3) # wrapped int tag is now 0x83
22
22
  # # explicit wrapper
23
- # wrapper = RASN1::Wrapper.new(int, explicit: 4) # int tag is always 0x81, but it is wrapped in a 0x84 tag
23
+ # wrapper = RASN2::Wrapper.new(int, explicit: 4) # int tag is always 0x81, but it is wrapped in a 0x84 tag
24
24
  # @example Wrapping a choice to make it recursive
25
- # class RecursiveChoice < RASN1::Model
25
+ # class RecursiveChoice < RASN2::Model
26
26
  # choice :choice,
27
27
  # content: [
28
28
  # integer(:value, implicit: 1),
@@ -78,7 +78,7 @@ module RASN1
78
78
  @element_options_to_merge = opts
79
79
  @options = {}
80
80
  end
81
- raise RASN1::Error, 'Cannot be implicit and explicit' if explicit? && implicit?
81
+ raise RASN2::Error, 'Cannot be implicit and explicit' if explicit? && implicit?
82
82
 
83
83
  super(element)
84
84
  end
@@ -201,13 +201,6 @@ module RASN1
201
201
  !constructed?
202
202
  end
203
203
 
204
- # @param [::Integer] level
205
- # @return [String]
206
- def inspect(level=0)
207
- return super() unless explicit?
208
-
209
- @explicit_wrapper.inspect(level) << ' ' << super()
210
- end
211
204
 
212
205
  private
213
206
 
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'rasn1/version'
4
- require_relative 'rasn1/errors'
5
- require_relative 'rasn1/helpers/colorize'
6
- require_relative 'rasn1/types'
7
- require_relative 'rasn1/model'
8
- require_relative 'rasn1/wrapper'
9
- require_relative 'rasn1/tracer'
10
- require_relative 'rasn1/schema_parser'
11
- require_relative 'rasn1/value_notation'
3
+ require_relative 'rasn2/version'
4
+ require_relative 'rasn2/errors'
5
+ require_relative 'rasn2/helpers/colorize'
6
+ require_relative 'rasn2/types'
7
+ require_relative 'rasn2/model'
8
+ require_relative 'rasn2/wrapper'
9
+ require_relative 'rasn2/tracer'
10
+ require_relative 'rasn2/schema_parser'
11
+ require_relative 'rasn2/value_notation'
12
12
 
13
13
  # Constrained types
14
- require_relative 'rasn1/types/visible_string'
14
+ require_relative 'rasn2/types/visible_string'
15
15
 
16
16
  # Rasn1 is a pure ruby library to parse, decode and encode ASN.1 data.
17
17
  # @author Sylvain Daubert
18
- module RASN1
18
+ module RASN2
19
19
  # @private
20
20
  CONTAINER_CLASSES = [Types::Sequence, Types::Set].freeze
21
21
 
@@ -35,11 +35,11 @@ module RASN1
35
35
  type = Types.id2type(der)
36
36
  size = type.parse!(der, ber: ber)
37
37
 
38
- if CONTAINER_CLASSES.include?(type.class)
39
- RASN1.tracer.tracing_level += 1 unless RASN1.tracer.nil?
38
+ if CONTAINER_CLASSES.include?(type.class) || type.constructed?
39
+ RASN2.tracer.tracing_level += 1 unless RASN2.tracer.nil?
40
40
  content = self.parse(type.value)
41
41
  type.value = content.is_a?(Array) ? content : [content]
42
- RASN1.tracer.tracing_level -= 1 unless RASN1.tracer.nil?
42
+ RASN2.tracer.tracing_level -= 1 unless RASN2.tracer.nil?
43
43
  end
44
44
 
45
45
  result << type
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasn2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LemonTree55
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.5
41
41
  description: |
42
- RASN1 is a pure ruby ASN.1 library. It may encode and decode DER and BER
42
+ Rasn2 is a pure ruby ASN.1 library. It may encode and decode DER and BER
43
43
  encodings.
44
44
  email:
45
45
  - lenontree@proton.me
@@ -52,43 +52,43 @@ extra_rdoc_files:
52
52
  files:
53
53
  - LICENSE
54
54
  - README.md
55
- - lib/rasn1.rb
56
- - lib/rasn1/errors.rb
57
- - lib/rasn1/helpers/colorize.rb
58
- - lib/rasn1/model.rb
59
- - lib/rasn1/schema_parser.rb
60
- - lib/rasn1/tracer.rb
61
- - lib/rasn1/types.rb
62
- - lib/rasn1/types/any.rb
63
- - lib/rasn1/types/base.rb
64
- - lib/rasn1/types/bit_string.rb
65
- - lib/rasn1/types/bmp_string.rb
66
- - lib/rasn1/types/boolean.rb
67
- - lib/rasn1/types/choice.rb
68
- - lib/rasn1/types/constrained.rb
69
- - lib/rasn1/types/constructed.rb
70
- - lib/rasn1/types/enumerated.rb
71
- - lib/rasn1/types/generalized_time.rb
72
- - lib/rasn1/types/ia5_string.rb
73
- - lib/rasn1/types/integer.rb
74
- - lib/rasn1/types/null.rb
75
- - lib/rasn1/types/numeric_string.rb
76
- - lib/rasn1/types/object_id.rb
77
- - lib/rasn1/types/octet_string.rb
78
- - lib/rasn1/types/primitive.rb
79
- - lib/rasn1/types/printable_string.rb
80
- - lib/rasn1/types/sequence.rb
81
- - lib/rasn1/types/sequence_of.rb
82
- - lib/rasn1/types/set.rb
83
- - lib/rasn1/types/set_of.rb
84
- - lib/rasn1/types/tag.rb
85
- - lib/rasn1/types/universal_string.rb
86
- - lib/rasn1/types/utc_time.rb
87
- - lib/rasn1/types/utf8_string.rb
88
- - lib/rasn1/types/visible_string.rb
89
- - lib/rasn1/value_notation.rb
90
- - lib/rasn1/version.rb
91
- - lib/rasn1/wrapper.rb
55
+ - lib/rasn2.rb
56
+ - lib/rasn2/errors.rb
57
+ - lib/rasn2/helpers/colorize.rb
58
+ - lib/rasn2/model.rb
59
+ - lib/rasn2/schema_parser.rb
60
+ - lib/rasn2/tracer.rb
61
+ - lib/rasn2/types.rb
62
+ - lib/rasn2/types/any.rb
63
+ - lib/rasn2/types/base.rb
64
+ - lib/rasn2/types/bit_string.rb
65
+ - lib/rasn2/types/bmp_string.rb
66
+ - lib/rasn2/types/boolean.rb
67
+ - lib/rasn2/types/choice.rb
68
+ - lib/rasn2/types/constrained.rb
69
+ - lib/rasn2/types/constructed.rb
70
+ - lib/rasn2/types/enumerated.rb
71
+ - lib/rasn2/types/generalized_time.rb
72
+ - lib/rasn2/types/ia5_string.rb
73
+ - lib/rasn2/types/integer.rb
74
+ - lib/rasn2/types/null.rb
75
+ - lib/rasn2/types/numeric_string.rb
76
+ - lib/rasn2/types/object_id.rb
77
+ - lib/rasn2/types/octet_string.rb
78
+ - lib/rasn2/types/primitive.rb
79
+ - lib/rasn2/types/printable_string.rb
80
+ - lib/rasn2/types/sequence.rb
81
+ - lib/rasn2/types/sequence_of.rb
82
+ - lib/rasn2/types/set.rb
83
+ - lib/rasn2/types/set_of.rb
84
+ - lib/rasn2/types/tag.rb
85
+ - lib/rasn2/types/universal_string.rb
86
+ - lib/rasn2/types/utc_time.rb
87
+ - lib/rasn2/types/utf8_string.rb
88
+ - lib/rasn2/types/visible_string.rb
89
+ - lib/rasn2/value_notation.rb
90
+ - lib/rasn2/version.rb
91
+ - lib/rasn2/wrapper.rb
92
92
  homepage: https://github.com/lemontree55/rasn1
93
93
  licenses:
94
94
  - MIT
@@ -99,7 +99,7 @@ metadata:
99
99
  documentation_uri: https://www.rubydoc.info/gems/rasn1
100
100
  rdoc_options:
101
101
  - "--title"
102
- - RASN1 - A pure ruby ASN.1 library
102
+ - Rasn2 - A pure ruby ASN.1 library
103
103
  - "--main"
104
104
  - README.md
105
105
  - "--inline-source"
@@ -1,76 +0,0 @@
1
- module RASN1
2
- module Helpers
3
- module Colorize
4
- def parens_hex(input, padding=2)
5
- input = input.is_a?(Integer) ? ("0x%0#{padding}x")% input : "0x#{input}"
6
- "#{colorize('(').webgray}#{colorize(input).blue}#{colorize(')').webgray}"
7
- end
8
-
9
- def int_with_hex(input, raw_value=nil)
10
- if raw_value
11
- "#{colorize(input).blue} #{parens_hex(raw_value)}"
12
- else
13
- "#{colorize(input).blue} #{parens_hex(input)}"
14
- end
15
-
16
- end
17
-
18
- def brace_surround(input)
19
- "#{colorize('[').webgray} #{input} #{colorize(']').webgray}"
20
- end
21
-
22
- def colorize_class(name, tag_id=nil)
23
- if tag_id
24
- "#{colorize(name).bold.yellow} #{parens_hex(tag_id)}"
25
- else
26
- colorize(name).bold.yellow
27
- end
28
- end
29
-
30
- def colorize_id(id, tag_class=nil)
31
- id = id.strip if id.is_a? String
32
- tag_class = tag_class.strip if tag_class.is_a? String
33
- if tag_class && tag_class != ''
34
- brace_surround("#{colorize_class(tag_class)} #{colorize(id).bold.green}")
35
- else
36
- brace_surround(colorize(id).bold.green)
37
- end
38
-
39
- end
40
-
41
- def length_specifier(data_length, encoded_length = nil)
42
- encoded_length = data_length if encoded_length.nil?
43
- "#{colorize('len:').gray} #{colorize(data_length).blue} #{parens_hex(encoded_length)}"
44
- end
45
-
46
- def colorize_name(name)
47
- colorize(name).bold.white
48
- end
49
-
50
- def colorize_attribute(attribute)
51
- colorize(attribute).bold.magenta
52
- end
53
-
54
- def colorize_default(value)
55
- colorize(value).green.bold
56
- end
57
-
58
- def colorize_nil(name = 'NONE')
59
- colorize(name).red.bold
60
- end
61
-
62
- def colorize_enum(name, raw_value)
63
- raw_value = raw_value.unpack1('H*') if raw_value.is_a?(String)
64
- "#{colorize_class(name)} #{parens_hex(raw_value)}"
65
- end
66
-
67
- def colorize_bool(value, raw_value)
68
- if value
69
- "#{colorize('TRUE').bold.green} #{parens_hex(raw_value)}"
70
- else
71
- "#{colorize('FALSE').bold.red} #{parens_hex(raw_value)}"
72
- end
73
- end
74
- end
75
- end
76
- end
data/lib/rasn1/version.rb DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RASN1
4
- # RASN1 version number
5
- VERSION = '0.16.0'
6
- end