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
Rasn1 is a pure ruby library to parse, decode and encode ASN.1 data.
Defined Under Namespace
Modules: Types Classes: ASN1Error, ChoiceError, ClassError, ConstraintError, EnumeratedError, Error, Model, ModelValidationError, Tracer, Wrapper
Constant Summary collapse
Class Method Summary collapse
-
.parse(der, ber: false) ⇒ 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
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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rasn1.rb', line 26 def self.parse(der, ber: false) # rubocop:disable Metrics:AbcSize type = Types.id2type(der) type.parse!(der, ber: ber) if CONTAINER_CLASSES.include?(type.class) subder = type.value ary = [] RASN1.tracer.tracing_level += 1 unless RASN1.tracer.nil? until subder.empty? ary << self.parse(subder) subder = subder[ary.last.to_der.size..-1] end RASN1.tracer.tracing_level -= 1 unless RASN1.tracer.nil? type.value = ary end type 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.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rasn1/tracer.rb', line 45 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
59 60 61 |
# File 'lib/rasn1/tracer.rb', line 59 def self.tracer @tracer end |