rasn1 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rasn1/model.rb +18 -1
- data/lib/rasn1/types/base.rb +26 -6
- data/lib/rasn1/types/choice.rb +4 -4
- data/lib/rasn1/types/constructed.rb +0 -1
- data/lib/rasn1/types/enumerated.rb +2 -2
- data/lib/rasn1/types/ia5string.rb +1 -1
- data/lib/rasn1/types/octet_string.rb +2 -2
- data/lib/rasn1/types/sequence.rb +5 -5
- data/lib/rasn1/types/sequence_of.rb +7 -15
- data/lib/rasn1/types/set.rb +4 -4
- data/lib/rasn1/types/visible_string.rb +7 -0
- data/lib/rasn1/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8afb668f624fee248cce8fe52bd51b57dc42a88f
|
4
|
+
data.tar.gz: 041fe9c1bf42b220b616d4c751b7acef8e98afc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32f94898893e828e3bc37569bde1cea6e72c577e64748aa87e6c30ffca7065eeb0365c2f10c2d26db89ff71ca2d03f2d9c8281175544d3af0b87b6f263fec24a
|
7
|
+
data.tar.gz: 5261798fa1336eb18234316d4224bfb12a55fe6a6583c36fe01cc2f40eeeb68cbcb839af83d5ccd3ec031c7eb72c2d50143568ce267ce03587dc28020e564f6f
|
data/lib/rasn1/model.rb
CHANGED
@@ -167,9 +167,26 @@ module RASN1
|
|
167
167
|
# @param [Symbol,String] name name of object in model
|
168
168
|
# @param [Hash] options
|
169
169
|
# @see Types::Utf8String#initialize
|
170
|
+
# @method numeric_string(name, options)
|
171
|
+
# @param [Symbol,String] name name of object in model
|
172
|
+
# @param [Hash] options
|
173
|
+
# @see Types::NumericString#initialize
|
174
|
+
# @method printable_string(name, options)
|
175
|
+
# @param [Symbol,String] name name of object in model
|
176
|
+
# @param [Hash] options
|
177
|
+
# @see Types::PrintableString#initialize
|
178
|
+
# @method visible_string(name, options)
|
179
|
+
# @param [Symbol,String] name name of object in model
|
180
|
+
# @param [Hash] options
|
181
|
+
# @see Types::VisibleString#initialize
|
182
|
+
# @method ia5_string(name, options)
|
183
|
+
# @param [Symbol,String] name name of object in model
|
184
|
+
# @param [Hash] options
|
185
|
+
# @see Types::IA5String#initialize
|
170
186
|
Types.primitives.each do |prim|
|
171
187
|
next if prim == Types::ObjectId
|
172
|
-
|
188
|
+
method_name = prim.type.gsub(/([a-z0-9])([A-Z])/, '\1_\2').downcase.gsub(/\s+/, '_')
|
189
|
+
class_eval "def #{method_name}(name, options={})\n" \
|
173
190
|
" options.merge!(name: name)\n" \
|
174
191
|
" proc = Proc.new do |opts|\n" \
|
175
192
|
" #{prim.to_s}.new(options.merge(opts))\n" \
|
data/lib/rasn1/types/base.rb
CHANGED
@@ -74,6 +74,17 @@ module RASN1
|
|
74
74
|
@type = self.to_s.gsub(/.*::/, '').gsub(/([a-z0-9])([A-Z])/, '\1 \2').upcase
|
75
75
|
end
|
76
76
|
|
77
|
+
# Parse a DER or BER string
|
78
|
+
# @param [String] der_or_ber string to parse
|
79
|
+
# @param [Hash] options
|
80
|
+
# @option options [Boolean] :ber if +true+, parse a BER string, else a DER one
|
81
|
+
# @note More options are supported. See {Base#initialize}.
|
82
|
+
def self.parse(der_or_ber, options={})
|
83
|
+
obj = self.new(options)
|
84
|
+
obj.parse!(der_or_ber, ber: options[:ber])
|
85
|
+
obj
|
86
|
+
end
|
87
|
+
|
77
88
|
|
78
89
|
# @overload initialize(options={})
|
79
90
|
# @param [Hash] options
|
@@ -113,12 +124,18 @@ module RASN1
|
|
113
124
|
|
114
125
|
# Used by +#dup+ and +#clone+. Deep copy @value.
|
115
126
|
def initialize_copy(other)
|
116
|
-
@value =
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
127
|
+
@value = case
|
128
|
+
when NilClass, TrueClass, FalseClass, Integer
|
129
|
+
@value
|
130
|
+
else
|
131
|
+
@value.dup
|
132
|
+
end
|
133
|
+
@default = case
|
134
|
+
when NilClass, TrueClass, FalseClass, Integer
|
135
|
+
@default
|
136
|
+
else
|
137
|
+
@default.dup
|
138
|
+
end
|
122
139
|
end
|
123
140
|
|
124
141
|
# Get value or default value
|
@@ -233,6 +250,9 @@ module RASN1
|
|
233
250
|
end
|
234
251
|
else
|
235
252
|
str << "#{type}: #{value.inspect}"
|
253
|
+
str << " OPTIONAL" if optional?
|
254
|
+
str << " DEFAULT #{@default}" unless @default.nil?
|
255
|
+
str
|
236
256
|
end
|
237
257
|
end
|
238
258
|
|
data/lib/rasn1/types/choice.rb
CHANGED
@@ -5,10 +5,10 @@ module RASN1
|
|
5
5
|
#
|
6
6
|
# == Create a CHOICE
|
7
7
|
# A CHOICE is defined this way:
|
8
|
-
# choice = Choice.new
|
9
|
-
# choice.value = [Integer.new(
|
10
|
-
# Integer.new(
|
11
|
-
# OctetString.new(
|
8
|
+
# choice = Choice.new
|
9
|
+
# choice.value = [Integer.new(implicit: 0, class: :context),
|
10
|
+
# Integer.new(implicit: 1, class: :context),
|
11
|
+
# OctetString.new(implicit: 2, class: :context)]
|
12
12
|
# The chosen type may be set this way:
|
13
13
|
# choice.chosen = 0 # choose :int1
|
14
14
|
# The chosen value may be set these ways:
|
@@ -5,8 +5,8 @@ module RASN1
|
|
5
5
|
#
|
6
6
|
# An enumerated type permits to assign names to integer values. It may be defined
|
7
7
|
# different ways:
|
8
|
-
# enum = RASN1::Types::Enumerated.new(
|
9
|
-
# enum = RASN1::Types::Enumerated.new(
|
8
|
+
# enum = RASN1::Types::Enumerated.new(enum: { 'a' => 0, 'b' => 1, 'c' => 2 })
|
9
|
+
# enum = RASN1::Types::Enumerated.new(enum: { a: 0, b: 1, c: 2 })
|
10
10
|
# Its value should be setting as an Integer or a String/symbol:
|
11
11
|
# enum.value = :b
|
12
12
|
# enum.value = 1 # equivalent to :b
|
@@ -4,8 +4,8 @@ module RASN1
|
|
4
4
|
# ASN.1 Octet String
|
5
5
|
#
|
6
6
|
# An OCTET STRINT may contain another primtive object:
|
7
|
-
# os = OctetString.new
|
8
|
-
# int = Integer.new
|
7
|
+
# os = OctetString.new
|
8
|
+
# int = Integer.new
|
9
9
|
# int.value = 12
|
10
10
|
# os.value = int
|
11
11
|
# os.to_der # => DER string with INTEGER in OCTET STRING
|
data/lib/rasn1/types/sequence.rb
CHANGED
@@ -12,11 +12,11 @@ module RASN1
|
|
12
12
|
# house [1] IMPLICIT INTEGER DEFAULT 0
|
13
13
|
# }
|
14
14
|
# do:
|
15
|
-
# seq = RASN1::Types::Sequence.new
|
15
|
+
# seq = RASN1::Types::Sequence.new
|
16
16
|
# seq.value = [
|
17
|
-
# RASN1::Types::Integer.new
|
18
|
-
# RASN1::Types::Integer.new(
|
19
|
-
# RASN1::Types::Integer.new(
|
17
|
+
# RASN1::Types::Integer.new
|
18
|
+
# RASN1::Types::Integer.new(explicit: 0, optional: true),
|
19
|
+
# RASN1::Types::Integer.new(implicit: 1, default: 0)
|
20
20
|
# ]
|
21
21
|
#
|
22
22
|
# A sequence may also be used without value to not parse sequence content:
|
@@ -35,7 +35,7 @@ module RASN1
|
|
35
35
|
|
36
36
|
def initialize_copy(other)
|
37
37
|
super
|
38
|
-
@value.map
|
38
|
+
@value = @value.map { |v| v.dup }
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -10,16 +10,16 @@ module RASN1
|
|
10
10
|
# Integers ::= SEQUENCE OF INTEGER
|
11
11
|
# do:
|
12
12
|
# # Create a SEQUENCE OF INTEGER
|
13
|
-
# seqof = RASN1::Types::SequenceOf.new(
|
13
|
+
# seqof = RASN1::Types::SequenceOf.new(RASN1::Types::Integer)
|
14
14
|
# # Set integer values
|
15
|
-
# seqof.value
|
15
|
+
# seqof.value = [1, 2, 3, 4]
|
16
16
|
#
|
17
17
|
# == Use with {Constructed} types
|
18
18
|
# SEQUENCE OF may be used to create sequence of composed types. For example:
|
19
|
-
# composed_type = RASN1::Sequence.new
|
20
|
-
# commposed_type.value = [RASN1::Types::Integer
|
21
|
-
# RASN1::Types::OctetString
|
22
|
-
# seqof = RASN1::SequenceOf.new(
|
19
|
+
# composed_type = RASN1::Types::Sequence.new
|
20
|
+
# commposed_type.value = [RASN1::Types::Integer,
|
21
|
+
# RASN1::Types::OctetString]
|
22
|
+
# seqof = RASN1::Types::SequenceOf.new(composed_type)
|
23
23
|
# seqof << [0, 'data0']
|
24
24
|
# seqof << [1, 'data1']
|
25
25
|
#
|
@@ -62,7 +62,7 @@ module RASN1
|
|
62
62
|
def initialize_copy(other)
|
63
63
|
super
|
64
64
|
@of_type = @of_type.dup
|
65
|
-
@value.map
|
65
|
+
@value = @value.map { |v| v.dup }
|
66
66
|
end
|
67
67
|
|
68
68
|
# Add an item to SEQUENCE OF
|
@@ -148,16 +148,8 @@ module RASN1
|
|
148
148
|
of_type_class.new(:t)
|
149
149
|
end
|
150
150
|
nb_bytes += type.parse!(der[nb_bytes, der.length])
|
151
|
-
#value = if composed_of_type?
|
152
|
-
# type.value.map { |obj| obj.value }
|
153
|
-
# elsif of_type_class < Model
|
154
|
-
# type.to_h[type.to_h.keys.first]
|
155
|
-
# else
|
156
|
-
# type.value
|
157
|
-
# end
|
158
151
|
@value << type
|
159
152
|
end
|
160
|
-
#puts "#{name}: #{@value.inspect}"
|
161
153
|
end
|
162
154
|
|
163
155
|
def explicit_type
|
data/lib/rasn1/types/set.rb
CHANGED
@@ -12,11 +12,11 @@ module RASN1
|
|
12
12
|
# house [1] IMPLICIT INTEGER DEFAULT 0
|
13
13
|
# }
|
14
14
|
# do:
|
15
|
-
# set = RASN1::Types::Set.new
|
15
|
+
# set = RASN1::Types::Set.new
|
16
16
|
# set.value = [
|
17
|
-
# RASN1::Types::Integer
|
18
|
-
# RASN1::Types::Integer(
|
19
|
-
# RASN1::Types::Integer(
|
17
|
+
# RASN1::Types::Integer
|
18
|
+
# RASN1::Types::Integer(explicit: 0, optional: true),
|
19
|
+
# RASN1::Types::Integer(implicit: 1, default: 0)
|
20
20
|
# ]
|
21
21
|
# @author Sylvain Daubert
|
22
22
|
class Set < Sequence
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Daubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|