rasn1 0.15.0 → 0.16.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rasn1/errors.rb +6 -0
- data/lib/rasn1/model.rb +63 -24
- data/lib/rasn1/tracer.rb +6 -0
- data/lib/rasn1/types/any.rb +6 -0
- data/lib/rasn1/types/base.rb +13 -2
- data/lib/rasn1/types/bit_string.rb +6 -0
- data/lib/rasn1/types/bmp_string.rb +6 -0
- data/lib/rasn1/types/boolean.rb +7 -1
- data/lib/rasn1/types/choice.rb +6 -0
- data/lib/rasn1/types/constrained.rb +6 -0
- data/lib/rasn1/types/constructed.rb +6 -0
- data/lib/rasn1/types/enumerated.rb +6 -0
- data/lib/rasn1/types/generalized_time.rb +6 -0
- data/lib/rasn1/types/ia5string.rb +6 -0
- data/lib/rasn1/types/integer.rb +6 -0
- data/lib/rasn1/types/null.rb +6 -0
- data/lib/rasn1/types/numeric_string.rb +6 -0
- data/lib/rasn1/types/object_id.rb +6 -0
- data/lib/rasn1/types/octet_string.rb +6 -0
- data/lib/rasn1/types/primitive.rb +6 -0
- data/lib/rasn1/types/printable_string.rb +6 -0
- data/lib/rasn1/types/sequence.rb +6 -0
- data/lib/rasn1/types/sequence_of.rb +6 -0
- data/lib/rasn1/types/set.rb +6 -0
- data/lib/rasn1/types/set_of.rb +6 -0
- data/lib/rasn1/types/universal_string.rb +6 -0
- data/lib/rasn1/types/utc_time.rb +6 -0
- data/lib/rasn1/types/utf8_string.rb +6 -0
- data/lib/rasn1/types/visible_string.rb +7 -1
- data/lib/rasn1/types.rb +6 -0
- data/lib/rasn1/version.rb +7 -1
- data/lib/rasn1/wrapper.rb +6 -0
- data/lib/rasn1.rb +24 -15
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd8cb204d6f0a5c24e321b88124844057a360272c4e738a0cf1dab3458d93c66
|
4
|
+
data.tar.gz: 4635d97697b8b91a836f7d7c28b27f0a0ee31a215b6f928f8932d55dfe268b12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07db598261b37e78e8329b7b20427c2f2ba7c24a53cccaed3aa61ba3413180cecdccaa665a6b502f77a2f00163b3af370e96b0ff5098f9ea519c62f1a86f0e47
|
7
|
+
data.tar.gz: 53a4a006d4a32964d412c92ff8821636d01beb0753d07259c7b08418f97a16d16ccbe47619ae9f999f5d22561e1b1fe1073b446202c242fac38316852fa29035
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[](https://badge.fury.io/rb/rasn1)
|
2
|
-
[](https://ci.codeberg.org/repos/15057)
|
3
3
|
|
4
4
|
# Rasn1
|
5
5
|
|
data/lib/rasn1/errors.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
# Base error class
|
5
11
|
class Error < StandardError; end
|
data/lib/rasn1/model.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
# @abstract
|
5
11
|
# {Model} class is a base class to define ASN.1 models.
|
@@ -381,15 +387,24 @@ module RASN1
|
|
381
387
|
lazy_initialize(args) unless args.empty?
|
382
388
|
end
|
383
389
|
|
384
|
-
#
|
385
|
-
#
|
386
|
-
#
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
390
|
+
# @overload [](name)
|
391
|
+
# Access an element of the model by its name
|
392
|
+
# @param [Symbol] name
|
393
|
+
# @return [Model, Types::Base, Wrapper]
|
394
|
+
# @overload [](idx)
|
395
|
+
# Access an element of root element by its index. Root element must be a {Types::Sequence} or {Types::SequenceOf}.
|
396
|
+
# @param [Integer] idx
|
397
|
+
# @return [Model, Types::Base, Wrapper]
|
398
|
+
def [](name_or_idx)
|
399
|
+
case name_or_idx
|
400
|
+
when Symbol
|
401
|
+
elt = @elements[name_or_idx]
|
402
|
+
return elt unless elt.is_a?(Proc)
|
403
|
+
|
404
|
+
@elements[name_or_idx] = elt.call
|
405
|
+
when Integer
|
406
|
+
root[name_or_idx]
|
407
|
+
end
|
393
408
|
end
|
394
409
|
|
395
410
|
# Set value of element +name+. Element should be a {Types::Base}.
|
@@ -552,7 +567,7 @@ module RASN1
|
|
552
567
|
end
|
553
568
|
|
554
569
|
# Initialize an sequence element from an array
|
555
|
-
# @param [Array]
|
570
|
+
# @param [Array] ary
|
556
571
|
# @return [void]
|
557
572
|
def lazy_initialize_array(ary)
|
558
573
|
raise Error, 'Only sequence types may be initialized with an array' unless SEQUENCE_TYPES.any? { |klass| root.is_a?(klass) }
|
@@ -582,13 +597,13 @@ module RASN1
|
|
582
597
|
private
|
583
598
|
|
584
599
|
def generate_root(args)
|
585
|
-
opts = args.slice(:explicit, :implicit, :optional, :class, :default, :constructed, :tag_value)
|
600
|
+
opts = args.slice(:name, :explicit, :implicit, :optional, :class, :default, :constructed, :tag_value)
|
586
601
|
root = self.class.class_eval { @root }
|
587
602
|
root_options = self.class.options || {}
|
588
603
|
root_options.merge!(opts)
|
604
|
+
@root_name = args[:name] || root.name
|
589
605
|
@root = generate_element(root, root_options)
|
590
|
-
@root_name = root
|
591
|
-
@elements[root.name] = @root
|
606
|
+
@elements[@root_name] = @root
|
592
607
|
end
|
593
608
|
|
594
609
|
def generate_element(elt, opts={})
|
@@ -596,15 +611,23 @@ module RASN1
|
|
596
611
|
when BaseElem
|
597
612
|
generate_base_element(elt, opts)
|
598
613
|
when ModelElem
|
614
|
+
opts[:name] ||= elt.name
|
599
615
|
elt.klass.new(opts)
|
600
616
|
when WrapElem
|
601
|
-
|
602
|
-
wrapper = Wrapper.new(wrapped, elt.options.merge(opts))
|
603
|
-
@elements[elt.element.name] = proc { wrapper.element }
|
604
|
-
wrapper
|
617
|
+
generate_wrapper_element(elt, opts)
|
605
618
|
end
|
606
619
|
end
|
607
620
|
|
621
|
+
def generate_wrapper_element(elt, opts)
|
622
|
+
wrapped = elt.element.is_a?(ModelElem) ? elt.element.klass : generate_element(elt.element)
|
623
|
+
options = elt.options.merge(opts)
|
624
|
+
options[:name] = elt.element.name if elt.element.is_a?(ModelElem)
|
625
|
+
wrapper = Wrapper.new(wrapped, options)
|
626
|
+
# Use a proc as wrapper may be lazy
|
627
|
+
@elements[elt.element.name] = proc { wrapper.element }
|
628
|
+
wrapper
|
629
|
+
end
|
630
|
+
|
608
631
|
def generate_base_element(elt, opts)
|
609
632
|
element = elt.proc.call(opts)
|
610
633
|
return element if elt.content.nil?
|
@@ -616,19 +639,20 @@ module RASN1
|
|
616
639
|
element
|
617
640
|
end
|
618
641
|
|
642
|
+
# @author sdaubert
|
643
|
+
# @author lemontree55
|
644
|
+
# @author adfoster-r7
|
619
645
|
def private_to_h(element=nil) # rubocop:disable Metrics/CyclomaticComplexity
|
620
646
|
my_element = element || root
|
621
|
-
my_element = my_element.root if my_element.is_a?(Model)
|
622
647
|
value = case my_element
|
648
|
+
when Model
|
649
|
+
model_to_h(my_element)
|
623
650
|
when Types::SequenceOf
|
624
651
|
sequence_of_to_h(my_element)
|
625
652
|
when Types::Sequence
|
626
653
|
sequence_to_h(my_element)
|
627
|
-
# @author adfoster-r7
|
628
654
|
when Types::Choice
|
629
|
-
|
630
|
-
|
631
|
-
private_to_h(my_element.value[my_element.chosen])
|
655
|
+
choice_to_h(my_element)
|
632
656
|
when Wrapper
|
633
657
|
wrapper_to_h(my_element)
|
634
658
|
else
|
@@ -641,6 +665,15 @@ module RASN1
|
|
641
665
|
end
|
642
666
|
end
|
643
667
|
|
668
|
+
def model_to_h(elt)
|
669
|
+
hsh = elt.to_h
|
670
|
+
if root.is_a?(Types::Choice)
|
671
|
+
hsh[hsh.keys.first]
|
672
|
+
else
|
673
|
+
{ @elements.key(elt) => hsh[hsh.keys.first] }
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
644
677
|
def sequence_of_to_h(elt)
|
645
678
|
if elt.of_type < Model
|
646
679
|
elt.value&.map { |el| el.to_h.values.first }
|
@@ -655,8 +688,7 @@ module RASN1
|
|
655
688
|
|
656
689
|
case el
|
657
690
|
when Model
|
658
|
-
|
659
|
-
[@elements.key(el), hsh[hsh.keys.first]]
|
691
|
+
model_to_h(el).to_a[0]
|
660
692
|
when Wrapper
|
661
693
|
[unwrap_keyname(@elements.key(el)), wrapper_to_h(el)]
|
662
694
|
else
|
@@ -666,6 +698,13 @@ module RASN1
|
|
666
698
|
ary.compact.to_h
|
667
699
|
end
|
668
700
|
|
701
|
+
def choice_to_h(elt)
|
702
|
+
raise ChoiceError.new(elt) if elt.chosen.nil?
|
703
|
+
|
704
|
+
chosen = elt.value[elt.chosen]
|
705
|
+
{ chosen.name => private_to_h(chosen) }
|
706
|
+
end
|
707
|
+
|
669
708
|
def unwrap_keyname(key)
|
670
709
|
key.to_s.delete_suffix('_wrapper').to_sym
|
671
710
|
end
|
data/lib/rasn1/tracer.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
# @private
|
5
11
|
class Tracer
|
data/lib/rasn1/types/any.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 ANY: accepts any types
|
data/lib/rasn1/types/base.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# @abstract This is base class for all ASN.1 types.
|
@@ -95,6 +101,7 @@ module RASN1
|
|
95
101
|
# Parse a DER or BER string
|
96
102
|
# @param [String] der_or_ber string to parse
|
97
103
|
# @param [Hash] options
|
104
|
+
# @return [Base]
|
98
105
|
# @option options [Boolean] :ber if +true+, parse a BER string, else a DER one
|
99
106
|
# @note More options are supported. See {Base#initialize}.
|
100
107
|
def self.parse(der_or_ber, options={})
|
@@ -359,7 +366,7 @@ module RASN1
|
|
359
366
|
lines << str
|
360
367
|
end
|
361
368
|
str[compute_trace_index(byte_count, 3), 2] = '%02x' % byte
|
362
|
-
str[compute_trace_index(byte_count, 1, 49)] = byte
|
369
|
+
str[compute_trace_index(byte_count, 1, 49)] = byte.between?(32, 126) ? byte.chr : '.'
|
363
370
|
byte_count += 1
|
364
371
|
end
|
365
372
|
lines.map(&:rstrip).join << "\n"
|
@@ -546,7 +553,11 @@ module RASN1
|
|
546
553
|
end
|
547
554
|
end
|
548
555
|
|
549
|
-
|
556
|
+
# Check ID from +der+ is the one expected
|
557
|
+
# @return [Boolean] +true+ is ID is expected, +false+ if it is not but +self+ is {#optional?}
|
558
|
+
# or has a {#default} value.
|
559
|
+
# @raise [ASN1Error] ID was not expected, is not optional and has no default value
|
560
|
+
def check_id(der) # rubocop:disable Naming/PredicateMethod
|
550
561
|
expected_id = encode_identifier_octets
|
551
562
|
real_id = der[0, expected_id.size]
|
552
563
|
return true if real_id == expected_id
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Bit String
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 BmpString
|
data/lib/rasn1/types/boolean.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Boolean
|
@@ -14,7 +20,7 @@ module RASN1
|
|
14
20
|
DER_FALSE = 0
|
15
21
|
|
16
22
|
# @return [false]
|
17
|
-
def void_value
|
23
|
+
def void_value # rubocop:disable Naming/PredicateMethod
|
18
24
|
false
|
19
25
|
end
|
20
26
|
|
data/lib/rasn1/types/choice.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# A ASN.1 CHOICE is a choice between different types.
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# Mixin to add constraints on a RASN1 type.
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# @abstract This class SHOULD be used as base class for all ASN.1 primitive
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Enumerated
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
require 'strptime'
|
4
10
|
|
5
11
|
module RASN1
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 IA5 String
|
data/lib/rasn1/types/integer.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Integer
|
data/lib/rasn1/types/null.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Null
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Numeric String
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Object ID
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Octet String
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# @abstract This class SHOULD be used as base class for all ASN.1 primitive
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 Printable String
|
data/lib/rasn1/types/sequence.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 sequence
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 SEQUENCE OF
|
data/lib/rasn1/types/set.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 set
|
data/lib/rasn1/types/set_of.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 SET OF
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 UniversalString
|
data/lib/rasn1/types/utc_time.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
require 'date'
|
4
10
|
|
5
11
|
module RASN1
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# ASN.1 UTF8 String
|
@@ -1,10 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
module Types
|
5
11
|
# Create VisibleString as a Constrained subclass of IA5String
|
6
12
|
Types.define_type(:VisibleString, from: IA5String) do |value|
|
7
|
-
value.nil? || value.chars.all? { |c| c.ord
|
13
|
+
value.nil? || value.chars.all? { |c| c.ord.between?(32, 126) }
|
8
14
|
end
|
9
15
|
|
10
16
|
# ASN.1 Visible String
|
data/lib/rasn1/types.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
require_relative 'types/constrained'
|
4
10
|
|
5
11
|
module RASN1
|
data/lib/rasn1/version.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
module RASN1
|
4
10
|
# RASN1 version number
|
5
|
-
VERSION = '0.
|
11
|
+
VERSION = '0.16.1'
|
6
12
|
end
|
data/lib/rasn1/wrapper.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
require 'delegate'
|
4
10
|
|
5
11
|
module RASN1
|
data/lib/rasn1.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This file is part of RASN1
|
4
|
+
# See https://codeberg.org/lemontree55/rasn1 for more informations
|
5
|
+
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
|
+
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
|
+
# This program is published under MIT license.
|
8
|
+
|
3
9
|
require_relative 'rasn1/version'
|
4
10
|
require_relative 'rasn1/errors'
|
5
11
|
require_relative 'rasn1/types'
|
@@ -12,6 +18,7 @@ require_relative 'rasn1/types/visible_string'
|
|
12
18
|
|
13
19
|
# Rasn1 is a pure ruby library to parse, decode and encode ASN.1 data.
|
14
20
|
# @author Sylvain Daubert
|
21
|
+
# @author LemonTree
|
15
22
|
module RASN1
|
16
23
|
# @private
|
17
24
|
CONTAINER_CLASSES = [Types::Sequence, Types::Set].freeze
|
@@ -25,22 +32,24 @@ module RASN1
|
|
25
32
|
# generate {Types::Base} objects.
|
26
33
|
# @param [String] der binary string to parse
|
27
34
|
# @param [Boolean] ber if +true+, decode a BER string, else a DER one
|
28
|
-
# @return [Types::Base]
|
29
|
-
def self.parse(der, ber: false) # rubocop:disable Metrics
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
# @return [Types::Base, Array[Types::Base]]
|
36
|
+
def self.parse(der, ber: false) # rubocop:disable Metrics/AbcSize
|
37
|
+
result = []
|
38
|
+
until der.nil? || der.empty?
|
39
|
+
type = Types.id2type(der)
|
40
|
+
size = type.parse!(der, ber: ber)
|
41
|
+
|
42
|
+
if CONTAINER_CLASSES.include?(type.class)
|
43
|
+
RASN1.tracer.tracing_level += 1 unless RASN1.tracer.nil?
|
44
|
+
content = self.parse(type.value)
|
45
|
+
type.value = content.is_a?(Array) ? content : [content]
|
46
|
+
RASN1.tracer.tracing_level -= 1 unless RASN1.tracer.nil?
|
40
47
|
end
|
41
|
-
|
42
|
-
|
48
|
+
|
49
|
+
result << type
|
50
|
+
der = der[size..]
|
43
51
|
end
|
44
|
-
|
52
|
+
|
53
|
+
result.size == 1 ? result[0] : result
|
45
54
|
end
|
46
55
|
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.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LemonTree55
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: strptime
|
@@ -70,14 +70,13 @@ files:
|
|
70
70
|
- lib/rasn1/types/visible_string.rb
|
71
71
|
- lib/rasn1/version.rb
|
72
72
|
- lib/rasn1/wrapper.rb
|
73
|
-
homepage: https://
|
73
|
+
homepage: https://codeberg.org/lemontree55/rasn1
|
74
74
|
licenses:
|
75
75
|
- MIT
|
76
76
|
metadata:
|
77
|
-
homepage_uri: https://
|
78
|
-
source_code_uri: https://
|
79
|
-
bug_tracker_uri: https://
|
80
|
-
documentation_uri: https://www.rubydoc.info/gems/rasn1
|
77
|
+
homepage_uri: https://codeberg.org/lemontree55/rasn1
|
78
|
+
source_code_uri: https://codeberg.org/lemontree55/rasn1
|
79
|
+
bug_tracker_uri: https://codeberg.org/lemontree55/rasn1/issues
|
81
80
|
post_install_message:
|
82
81
|
rdoc_options:
|
83
82
|
- "--title"
|