Class: RASN1::Types::Sequence
- Inherits:
-
Constructed
- Object
- Base
- Constructed
- RASN1::Types::Sequence
- 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
Direct Known Subclasses
Constant Summary collapse
- TAG =
Sequence tag value
0x10
Constants inherited from Constructed
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
-
#[](idx_or_name) ⇒ Object
Get element at index
idx
, or element of namename
. -
#initialize(value_or_options = {}, options = {}) ⇒ Sequence
constructor
A new instance of Sequence.
- #initialize_copy(other) ⇒ Object
Methods inherited from Constructed
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.
33 34 35 36 |
# File 'lib/rasn1/types/sequence.rb', line 33 def initialize(={}, ={}) super @value ||= [] end |
Instance Method Details
#[](idx_or_name) ⇒ Object
Get element at index idx
, or element of name name
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 |