Class: RASN1::Types::Sequence

Inherits:
Constructed show all
Defined in:
lib/rasn1/types/sequence.rb

Overview

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

Direct Known Subclasses

Set

Constant Summary collapse

TAG =

Sequence tag value

0x10

Constants inherited from Constructed

Constructed::ASN1_PC

Constants inherited from Base

Base::CLASSES, Base::CLASS_MASK, Base::INDEFINITE_LENGTH, Base::MAX_TAG, Base::UNDUPPABLE_TYPES

Instance Attribute Summary

Attributes inherited from Base

#asn1_class, #default, #name, #value

Instance Method Summary collapse

Methods inherited from Constructed

#inspect

Methods inherited from Base

#==, #constructed?, encode_type, #explicit?, #implicit?, #inspect, #optional?, parse, #parse!, #primitive?, #tag, #tagged?, #to_der, #type, type, #value_size

Constructor Details

#initialize(value_or_options = {}, options = {}) ⇒ Sequence

Returns a new instance of Sequence.

See Also:



33
34
35
36
# File 'lib/rasn1/types/sequence.rb', line 33

def initialize(value_or_options={}, options={})
  super
  @value ||= []
end

Instance Method Details

#[](idx_or_name) ⇒ Object

Get element at index idx, or element of name name

Parameters:

  • idx_or_name (Integer, String, Symbol)

Returns:

  • (Object)


46
47
48
49
50
51
52
53
# 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) ⇒ Object



38
39
40
41
# File 'lib/rasn1/types/sequence.rb', line 38

def initialize_copy(other)
  super
  @value = @value.map(&:dup)
end