Module: RASN2
- Defined in:
- lib/rasn2.rb,
lib/rasn2/model.rb,
lib/rasn2/types.rb,
lib/rasn2/errors.rb,
lib/rasn2/tracer.rb,
lib/rasn2/version.rb,
lib/rasn2/wrapper.rb,
lib/rasn2/types/any.rb,
lib/rasn2/types/set.rb,
lib/rasn2/types/tag.rb,
lib/rasn2/types/base.rb,
lib/rasn2/types/null.rb,
lib/rasn2/types/choice.rb,
lib/rasn2/types/set_of.rb,
lib/rasn2/schema_parser.rb,
lib/rasn2/types/boolean.rb,
lib/rasn2/types/integer.rb,
lib/rasn2/types/sequence.rb,
lib/rasn2/types/utc_time.rb,
lib/rasn2/value_notation.rb,
lib/rasn2/types/object_id.rb,
lib/rasn2/types/primitive.rb,
lib/rasn2/helpers/colorize.rb,
lib/rasn2/types/bit_string.rb,
lib/rasn2/types/bmp_string.rb,
lib/rasn2/types/enumerated.rb,
lib/rasn2/types/ia5_string.rb,
lib/rasn2/types/constrained.rb,
lib/rasn2/types/constructed.rb,
lib/rasn2/types/sequence_of.rb,
lib/rasn2/types/utf8_string.rb,
lib/rasn2/types/octet_string.rb,
lib/rasn2/types/numeric_string.rb,
lib/rasn2/types/visible_string.rb,
lib/rasn2/types/generalized_time.rb,
lib/rasn2/types/printable_string.rb,
lib/rasn2/types/universal_string.rb
Overview
Rasn1 is a pure ruby library to parse, decode and encode ASN.1 data.
Defined Under Namespace
Modules: Helpers, SchemaParser, Types, ValueNotation Classes: ASN1Error, ChoiceError, ClassError, ConstraintError, EnumeratedError, Error, Model, ModelValidationError, Tracer, Wrapper
Constant Summary collapse
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, color: false) ⇒ void
Trace RASN2 parsing to
io. - .tracer ⇒ Object
- .tracer=(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 RASN2::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 RASN2::Types::Base objects.
Parse a DER/BER string without checking a model
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rasn2.rb', line 32 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) || type.constructed? RASN2.tracer.tracing_level += 1 unless RASN2.tracer.nil? content = self.parse(type.value) type.value = content.is_a?(Array) ? content : [content] RASN2.tracer.tracing_level -= 1 unless RASN2.tracer.nil? end result << type der = der[size..] end result.size == 1 ? result[0] : result end |
.trace(io = $stdout, color: false) ⇒ void
This method returns an undefined value.
Trace RASN2 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.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rasn2/tracer.rb', line 68 def self.trace(io=$stdout, color: false) self.tracer = Tracer.new(io, color: color) Tracer::TRACED_CLASSES.each(&:start_tracing) begin yield self.tracer ensure Tracer::TRACED_CLASSES.reverse.each(&:stop_tracing) self.tracer.io.flush self.tracer = nil end end |
.tracer ⇒ Object
82 83 84 |
# File 'lib/rasn2/tracer.rb', line 82 def self.tracer @tracer end |
.tracer=(tracer) ⇒ Object
86 87 88 |
# File 'lib/rasn2/tracer.rb', line 86 def self.tracer=(tracer) @tracer = tracer end |