class RASN1::Types::Sequence
ASN.1 sequence
A sequence is a collection of another ASN.1 types.
To encode this ASN.1 example:
Record ::= SEQUENCE { id INTEGER, room [0] INTEGER OPTIONAL, house [1] IMPLICIT INTEGER DEFAULT 0 }
do:
seq = RASN1::Types::Sequence.new seq.value = [ RASN1::Types::Integer.new RASN1::Types::Integer.new(explicit: 0, optional: true), RASN1::Types::Integer.new(implicit: 1, default: 0) ]
A sequence may also be used without value to not parse sequence content:
seq = RASN1::Types::Sequence.new(:seq) seq.parse!(der_string) seq.value # => String
@author Sylvain Daubert
Constants
- ID
Sequence
id value
Public Class Methods
new(value_or_options={}, options={})
click to toggle source
@see Base#initialize
Calls superclass method
RASN1::Types::Base::new
# File lib/rasn1/types/sequence.rb, line 33 def initialize(value_or_options={}, options={}) super @value ||= [] end
Public Instance Methods
[](idx_or_name)
click to toggle source
Get element at index idx
, or element of name name
@param [Integer, String, Symbol] idx_or_name @return [Object]
# File lib/rasn1/types/sequence.rb, line 46 def [](idx_or_name) case idx_or_name when Integer @value[idx] when String, Symbol @value.find { |elt| elt.name == idx_or_name } end end
initialize_copy(other)
click to toggle source
Calls superclass method
RASN1::Types::Base#initialize_copy
# File lib/rasn1/types/sequence.rb, line 38 def initialize_copy(other) super @value = @value.map(&:dup) end
Private Instance Methods
der_to_value(der, ber: false)
click to toggle source
# File lib/rasn1/types/sequence.rb, line 66 def der_to_value(der, ber: false) if @value.is_a?(Array) && !@value.empty? nb_bytes = 0 @value.each do |element| nb_bytes += element.parse!(der[nb_bytes..-1]) end else @value = der der.length end end
value_to_der()
click to toggle source
# File lib/rasn1/types/sequence.rb, line 57 def value_to_der case @value when Array @value.map(&:to_der).join else @value.to_s end end