rasn1 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/rasn1/model.rb +12 -0
- data/lib/rasn1/types/choice.rb +7 -4
- data/lib/rasn1/types/generalized_time.rb +32 -28
- data/lib/rasn1/types/universal_string.rb +30 -0
- data/lib/rasn1/types.rb +1 -0
- data/lib/rasn1/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50b3f9ddc3a11279f36c21d14768a908b0fe4f22ff75d650791a7a58ac47eaa7
|
4
|
+
data.tar.gz: d229ea04a626e34d8411e3787101ace2c55e3cef7178b617073ed6b65fefb867
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37ea433265c6229a89d896e47918c242b2edc48c24ffa585873e3706dfc3eaf73628b76c91bad3e15e1d969a5caf52237c92336aefdba2668f63f9468e7e2004
|
7
|
+
data.tar.gz: 0035453de20ea4873999ec18eb3065afa9f1fdddc2927f446ecd2b1851a3a0d1bef32b5bbc2d9029f804a57cd71fefbf95dae4cd4babae5f8491f1e9ea8057ad
|
data/README.md
CHANGED
data/lib/rasn1/model.rb
CHANGED
@@ -299,6 +299,12 @@ module RASN1
|
|
299
299
|
# @param [Hash] options
|
300
300
|
# @return [Elem]
|
301
301
|
# @see Types::BitString#initialize
|
302
|
+
# @!method bmp_string(name, options)
|
303
|
+
# @!scope class
|
304
|
+
# @param [Symbol,String] name name of object in model
|
305
|
+
# @param [Hash] options
|
306
|
+
# @return [Elem]
|
307
|
+
# @see Types::BmpString#initialize
|
302
308
|
# @!method octet_string(name, options)
|
303
309
|
# @!scope class
|
304
310
|
# @param [Symbol,String] name name of object in model
|
@@ -317,6 +323,12 @@ module RASN1
|
|
317
323
|
# @param [Hash] options
|
318
324
|
# @return [Elem]
|
319
325
|
# @see Types::Enumerated#initialize
|
326
|
+
# @!method universal_string(name, options)
|
327
|
+
# @!scope class
|
328
|
+
# @param [Symbol,String] name name of object in model
|
329
|
+
# @param [Hash] options
|
330
|
+
# @return [Elem]
|
331
|
+
# @see Types::UniversalString#initialize
|
320
332
|
# @!method utf8_string(name, options)
|
321
333
|
# @!scope class
|
322
334
|
# @param [Symbol,String] name name of object in model
|
data/lib/rasn1/types/choice.rb
CHANGED
@@ -75,24 +75,27 @@ module RASN1
|
|
75
75
|
# @return [Integer] total number of parsed bytes
|
76
76
|
# @raise [ASN1Error] error on parsing
|
77
77
|
def parse!(der, ber: false)
|
78
|
-
parsed = false
|
79
78
|
@value.each_with_index do |element, i|
|
80
79
|
@chosen = i
|
81
80
|
nb_bytes = element.parse!(der, ber: ber)
|
82
|
-
parsed = true
|
83
81
|
return nb_bytes
|
84
82
|
rescue ASN1Error
|
85
83
|
@chosen = nil
|
86
84
|
next
|
87
85
|
end
|
88
|
-
|
86
|
+
|
87
|
+
@no_value = true
|
88
|
+
@value = void_value
|
89
|
+
raise ASN1Error, "CHOICE #{@name}: no type matching #{der.inspect}" unless optional?
|
90
|
+
|
91
|
+
0
|
89
92
|
end
|
90
93
|
|
91
94
|
# @param [::Integer] level
|
92
95
|
# @return [String]
|
93
96
|
def inspect(level=0)
|
94
97
|
str = common_inspect(level)
|
95
|
-
str << if defined?
|
98
|
+
str << if defined?(@chosen) && value?
|
96
99
|
"\n#{@value[@chosen].inspect(level + 1)}"
|
97
100
|
else
|
98
101
|
' not chosen!'
|
@@ -71,19 +71,33 @@ module RASN1
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def value_when_fraction_empty(date_hour)
|
74
|
-
if
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
tz = if date_hour[-1] == 'Z'
|
75
|
+
date_hour.slice!(-1, 1)
|
76
|
+
'+00:00' # Ruby 3.0: to remove after end-of support of ruby 3.0
|
77
|
+
elsif date_hour.match?(/[+-]\d+$/)
|
78
|
+
# Ruby 3.0
|
79
|
+
# date_hour.slice!(-5, 5)
|
80
|
+
zone = date_hour.slice!(-5, 5)
|
81
|
+
zone[0, 3] << ':' << zone[3, 2]
|
82
|
+
end
|
83
|
+
year = date_hour.slice!(0, 4).to_i
|
84
|
+
others = date_hour.scan(/../).map(&:to_i)
|
85
|
+
# Ruby 3.0
|
86
|
+
# From 3.1: "Z" and "-0100" are supported
|
87
|
+
# Below 3.1: should be "-01:00" or "+00:00"
|
88
|
+
unless tz.nil?
|
89
|
+
others += [0] * (5 - others.size)
|
90
|
+
others << tz
|
78
91
|
end
|
79
|
-
|
80
|
-
|
92
|
+
@value = Time.new(year, *others)
|
93
|
+
# From 3.1: replace all this code by: Time.new(year, *others, in: tz)
|
81
94
|
end
|
82
95
|
|
83
96
|
def value_when_fraction_ends_with_z(date_hour, fraction)
|
84
97
|
fraction = fraction[0...-1]
|
85
98
|
date_hour << 'Z'
|
86
|
-
frac_base =
|
99
|
+
frac_base = compute_frac_base(date_hour)
|
100
|
+
value_when_fraction_empty(date_hour)
|
87
101
|
fix_value(fraction, frac_base)
|
88
102
|
end
|
89
103
|
|
@@ -93,42 +107,32 @@ module RASN1
|
|
93
107
|
# fraction contains fraction and timezone info. Split them
|
94
108
|
fraction = match[1]
|
95
109
|
date_hour << match[2]
|
96
|
-
else
|
97
|
-
# fraction only contains fraction.
|
98
|
-
# Have to add offset with UTC to force Strptime to
|
99
|
-
# generate a local time.
|
100
|
-
date_hour << Time.now.strftime('%z')
|
101
110
|
end
|
102
111
|
|
103
|
-
frac_base =
|
112
|
+
frac_base = compute_frac_base(date_hour)
|
113
|
+
value_when_fraction_empty(date_hour)
|
104
114
|
fix_value(fraction, frac_base)
|
105
115
|
end
|
106
116
|
|
107
|
-
def value_from(date_hour)
|
108
|
-
format, frac_base = strformat(date_hour)
|
109
|
-
@value = Strptime.new(format).exec(date_hour)
|
110
|
-
frac_base
|
111
|
-
end
|
112
|
-
|
113
117
|
def fix_value(fraction, frac_base)
|
114
118
|
frac = ".#{fraction}".to_r * frac_base
|
115
119
|
@value = (@value + frac) unless fraction.nil?
|
116
120
|
end
|
117
121
|
|
118
|
-
def
|
122
|
+
def compute_frac_base(date_hour)
|
119
123
|
case date_hour.size
|
120
|
-
when 11
|
121
|
-
|
122
|
-
when 13, 17
|
123
|
-
|
124
|
+
when 10, 11
|
125
|
+
HOUR_TO_SEC
|
126
|
+
when 12, 13, 17
|
127
|
+
MINUTE_TO_SEC
|
124
128
|
when 15
|
125
129
|
if date_hour[-1] == 'Z'
|
126
|
-
|
130
|
+
SECOND_TO_SEC
|
127
131
|
else
|
128
|
-
|
132
|
+
HOUR_TO_SEC
|
129
133
|
end
|
130
|
-
when 19
|
131
|
-
|
134
|
+
when 14, 19
|
135
|
+
SECOND_TO_SEC
|
132
136
|
else
|
133
137
|
prefix = @name.nil? ? type : "tag #{@name}"
|
134
138
|
raise ASN1Error, "#{prefix}: unrecognized format: #{date_hour}"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RASN1
|
4
|
+
module Types
|
5
|
+
# ASN.1 UniversalString
|
6
|
+
# @since 0.13.0
|
7
|
+
# @author zeroSteiner
|
8
|
+
class UniversalString < OctetString
|
9
|
+
# UniversalString id value
|
10
|
+
ID = 28
|
11
|
+
|
12
|
+
# Get ASN.1 type
|
13
|
+
# @return [String]
|
14
|
+
def self.type
|
15
|
+
'UniversalString'
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def value_to_der
|
21
|
+
@value.to_s.dup.encode('UTF-32BE').b
|
22
|
+
end
|
23
|
+
|
24
|
+
def der_to_value(der, ber: false)
|
25
|
+
super
|
26
|
+
@value = der.to_s.dup.force_encoding('UTF-32BE')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rasn1/types.rb
CHANGED
@@ -128,6 +128,7 @@ require_relative 'types/null'
|
|
128
128
|
require_relative 'types/object_id'
|
129
129
|
require_relative 'types/enumerated'
|
130
130
|
require_relative 'types/bmp_string'
|
131
|
+
require_relative 'types/universal_string'
|
131
132
|
require_relative 'types/utf8_string'
|
132
133
|
require_relative 'types/numeric_string'
|
133
134
|
require_relative 'types/printable_string'
|
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.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Daubert
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: strptime
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/rasn1/types/sequence_of.rb
|
65
65
|
- lib/rasn1/types/set.rb
|
66
66
|
- lib/rasn1/types/set_of.rb
|
67
|
+
- lib/rasn1/types/universal_string.rb
|
67
68
|
- lib/rasn1/types/utc_time.rb
|
68
69
|
- lib/rasn1/types/utf8_string.rb
|
69
70
|
- lib/rasn1/types/visible_string.rb
|
@@ -77,7 +78,7 @@ metadata:
|
|
77
78
|
source_code_uri: https://github.com/sdaubert/rasn1
|
78
79
|
bug_tracker_uri: https://github.com/sdaubert/rasn1/issues
|
79
80
|
documentation_uri: https://www.rubydoc.info/gems/rasn1
|
80
|
-
post_install_message:
|
81
|
+
post_install_message:
|
81
82
|
rdoc_options:
|
82
83
|
- "--title"
|
83
84
|
- RASN1 - A pure ruby ASN.1 library
|
@@ -91,15 +92,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
92
|
requirements:
|
92
93
|
- - ">="
|
93
94
|
- !ruby/object:Gem::Version
|
94
|
-
version: 2.
|
95
|
+
version: 2.7.0
|
95
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
97
|
requirements:
|
97
98
|
- - ">="
|
98
99
|
- !ruby/object:Gem::Version
|
99
100
|
version: '0'
|
100
101
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
102
|
-
signing_key:
|
102
|
+
rubygems_version: 3.3.15
|
103
|
+
signing_key:
|
103
104
|
specification_version: 4
|
104
105
|
summary: Ruby ASN.1 library
|
105
106
|
test_files: []
|