Module: RASN1
- Defined in:
- lib/rasn1.rb,
lib/rasn1/model.rb,
lib/rasn1/types.rb,
lib/rasn1/errors.rb,
lib/rasn1/tracer.rb,
lib/rasn1/version.rb,
lib/rasn1/wrapper.rb,
lib/rasn1/types/any.rb,
lib/rasn1/types/set.rb,
lib/rasn1/types/base.rb,
lib/rasn1/types/null.rb,
lib/rasn1/types/choice.rb,
lib/rasn1/types/set_of.rb,
lib/rasn1/types/boolean.rb,
lib/rasn1/types/integer.rb,
lib/rasn1/types/sequence.rb,
lib/rasn1/types/utc_time.rb,
lib/rasn1/types/ia5string.rb,
lib/rasn1/types/object_id.rb,
lib/rasn1/types/primitive.rb,
lib/rasn1/types/bit_string.rb,
lib/rasn1/types/bmp_string.rb,
lib/rasn1/types/enumerated.rb,
lib/rasn1/types/constrained.rb,
lib/rasn1/types/constructed.rb,
lib/rasn1/types/sequence_of.rb,
lib/rasn1/types/utf8_string.rb,
lib/rasn1/types/octet_string.rb,
lib/rasn1/types/numeric_string.rb,
lib/rasn1/types/visible_string.rb,
lib/rasn1/types/generalized_time.rb,
lib/rasn1/types/printable_string.rb,
lib/rasn1/types/universal_string.rb
Overview
This file is part of RASN1 See codeberg.org/lemontree55/rasn1 for more informations Copyright © 2016-2024 Sylvain Daubert <[email protected]> Copyright © 2024 LemonTree55 <[email protected]> This program is published under MIT license.
Defined Under Namespace
Modules: Types Classes: ASN1Error, ChoiceError, ClassError, ConstraintError, EnumeratedError, Error, Model, ModelValidationError, Tracer, Wrapper
Constant Summary collapse
- CONTAINER_CLASSES =
[Types::Sequence, Types::Set].freeze
- VERSION =
RASN1 version number
'0.16.2'
Class Method Summary collapse
-
.parse(der, ber: false) ⇒ Types::Base, Array[Types::Base]
Parse a DER/BER string without checking a model.
-
.trace(io = $stdout) ⇒ void
Trace RASN1 parsing to
io. - .tracer ⇒ Object
Class Method Details
.parse(der, ber: false) ⇒ Types::Base, Array[Types::Base]
If you want to check ASN.1 grammary, you should define a Model and use RASN1::Model::Accel#parse.
This method will never decode SEQUENCE OF or SET OF objects, as these ones use the same encoding as SEQUENCE and SET, respectively.
Real type of tagged value cannot be guessed. So, such tag will generate RASN1::Types::Base objects.
Parse a DER/BER string without checking a model
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rasn1.rb', line 36 def self.parse(der, ber: false) # rubocop:disable Metrics/AbcSize result = [] until der.nil? || der.empty? type = Types.id2type(der) size = type.parse!(der, ber: ber) if CONTAINER_CLASSES.include?(type.class) RASN1.tracer.tracing_level += 1 unless RASN1.tracer.nil? content = self.parse(type.value) type.value = content.is_a?(Array) ? content : [content] RASN1.tracer.tracing_level -= 1 unless RASN1.tracer.nil? end result << type der = der[size..] end result.size == 1 ? result[0] : result end |
.trace(io = $stdout) ⇒ void
This method returns an undefined value.
Trace RASN1 parsing to io. All parsing methods called in block are traced to io. Each ASN.1 element is traced in a line showing element’s id, its length and its data.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rasn1/tracer.rb', line 51 def self.trace(io=$stdout) @tracer = Tracer.new(io) Tracer::TRACED_CLASSES.each(&:start_tracing) begin yield @tracer ensure Tracer::TRACED_CLASSES.reverse.each(&:stop_tracing) @tracer.io.flush @tracer = nil end end |
.tracer ⇒ Object
65 66 67 |
# File 'lib/rasn1/tracer.rb', line 65 def self.tracer @tracer end |