Module: RASN1
- Defined in:
- lib/rasn1.rb,
lib/rasn1/model.rb,
lib/rasn1/types.rb,
lib/rasn1/version.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/enumerated.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
Overview
Rasn1 is a pure ruby library to parse, decode and encode ASN.1 data.
Defined Under Namespace
Modules: Types Classes: ASN1Error, ChoiceError, ClassError, EnumeratedError, Error, Model
Constant Summary collapse
- VERSION =
'0.7.1'
Class Method Summary collapse
-
.parse(der, ber: false) ⇒ Types::Base
Parse a DER/BER string without checking a model.
Class Method Details
.parse(der, ber: false) ⇒ Types::Base
Note:
If you want to check ASN.1 grammary, you should define a Model and use RASN1::Model.parse.
Note:
This method will never decode SEQUENCE OF or SET OF objects, as these ones use the same encoding as SEQUENCE and SET, respectively.
Note:
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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rasn1.rb', line 44 def self.parse(der, ber: false) root = nil until der.empty? type = Types.tag2type(der[0].ord) type.parse!(der, ber: ber) root = type if root.nil? if [Types::Sequence, Types::Set].include? type.class subder = type.value ary = [] until subder.empty? ary << self.parse(subder) subder = subder[ary.last.to_der.size..-1] end type.value = ary end der = der[type.to_der.size..-1] end root end |