Class: RASN2::Types::Enumerated
- Defined in:
- lib/rasn2/types/enumerated.rb
Overview
ASN.1 Enumerated
An enumerated type permits to assign names to integer values. It may be defined different ways: enum = RASN2::Types::Enumerated.new(enum: { 'a' => 0, 'b' => 1, 'c' => 2 }) enum = RASN2::Types::Enumerated.new(enum: { a: 0, b: 1, c: 2 }) Its value should be setting as an Integer or a String/symbol: enum.value = :b enum.value = 1 # equivalent to :b But its value is always stored as named integer: enum.value = :b enum.value # => :b enum.value = 0 enum.value # => :a A EnumeratedError is raised when set value is not in enumeration.
Constant Summary collapse
- ID =
Enumerated id value
0x0a
Constants inherited from Primitive
Constants inherited from Base
Base::CLASSES, Base::CLASS_MASK, Base::INDEFINITE_LENGTH, Base::MULTI_OCTETS_ID
Instance Attribute Summary collapse
Attributes inherited from Base
#asn1_class, #default, #model, #name, #options
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Enumerated
constructor
A new instance of Enumerated.
- #to_h ⇒ Hash
Methods inherited from Integer
#der_to_value, #to_i, #value=, #void_value
Methods inherited from Base
#==, #asn1_class_to_s, #attributes, #bin2hex, #build, #can_build?, #check_id, #colorize, #common_inspect, constrained?, #constructed?, #der2name, #der_to_value, #do_parse, #do_parse_explicit, #do_parse_explicit_with_tracing, #do_parse_with_tracing, #encode_identifier_octets, #encode_size, encoded_type, #explicit?, #explicit_type, #find_type, #get_data, #get_length, #id, #id2octets, #id_value, #implicit?, #indent, #initialize_copy, #inspect, #inspect_value, #msg_type, #optional?, parse, #parse!, #pc_bit, #primitive?, #private?, #raise_id_error, #raise_on_indefinite_length, #self2name, #set_class, #set_default, #set_optional, #set_tag, #set_value, #specific_initializer, start_tracing, stop_tracing, #tag_id_to_integer, #tagged?, #to_der, #trace, #trace_data, #trace_real, #tracer, type, #type, #universal?, #unpack, #unsigned_to_chained_octets, #value, #value=, #value?, #value_size, #value_to_der, #void_value
Methods included from Helpers::Colorize
#begin_colorizer, #brace_surround, #colorize, #colorize_attribute, #colorize_bool, #colorize_class, #colorize_default, #colorize_enum, #colorize_id, #colorize_name, #colorize_nil, #colorize_value, #colorizer, #colorizer=, #end_colorizer, #int_with_hex, #length_specifier, #parens_hex
Constructor Details
#initialize(options = {}) ⇒ Enumerated
Returns a new instance of Enumerated.
33 34 35 36 |
# File 'lib/rasn2/types/enumerated.rb', line 33 def initialize(={}) super raise EnumeratedError, 'no enumeration given' if @enum.empty? end |
Instance Attribute Details
#enum ⇒ Hash
|
|
# File 'lib/rasn2/types/enumerated.rb', line 22
|
Instance Method Details
#to_h ⇒ Hash
39 40 41 |
# File 'lib/rasn2/types/enumerated.rb', line 39 def to_h @enum end |