Class: RASN1::Types::Integer
- Defined in:
- lib/rasn1/types/integer.rb
Overview
ASN.1 Integer
Direct Known Subclasses
Constant Summary collapse
- ID =
Integer id value
2
Constants inherited from Primitive
Constants inherited from Base
Base::CLASSES, Base::CLASS_MASK, Base::INDEFINITE_LENGTH, Base::MULTI_OCTETS_ID
Instance Attribute Summary collapse
- #enum ⇒ Hash? readonly
Attributes inherited from Base
#asn1_class, #default, #name, #options
Instance Method Summary collapse
-
#der_to_value(der, ber: false) ⇒ void
Make integer value from
derstring. -
#initialize(options = {}) ⇒ Integer
constructor
A new instance of Integer.
-
#to_i ⇒ Integer
Integer value.
- #value=(val) ⇒ void
- #void_value ⇒ Integer
Methods inherited from Base
#==, #can_build?, constrained?, #constructed?, #do_parse, #do_parse_explicit, #do_parse_explicit_with_tracing, #do_parse_with_tracing, encoded_type, #explicit?, #id, #implicit?, #initialize_copy, #inspect, #optional?, parse, #parse!, #primitive?, #specific_initializer, start_tracing, stop_tracing, #tagged?, #to_der, #trace, #type, type, #value, #value?, #value_size
Constructor Details
#initialize(options = {}) ⇒ Integer
Returns a new instance of Integer.
24 25 26 27 |
# File 'lib/rasn1/types/integer.rb', line 24 def initialize(={}) super initialize_enum(@options[:enum]) end |
Instance Attribute Details
#enum ⇒ Hash? (readonly)
15 16 17 |
# File 'lib/rasn1/types/integer.rb', line 15 def enum @enum end |
Instance Method Details
#der_to_value(der, ber: false) ⇒ void
This method returns an undefined value.
Make integer value from der string.
67 68 69 70 71 72 73 74 |
# File 'lib/rasn1/types/integer.rb', line 67 def der_to_value(der, ber: false) int_value = der_to_int_value(der, ber: ber) @value = if @enum.empty? int_value else int_to_enum(int_value) end end |
#to_i ⇒ Integer
Integer value
53 54 55 56 57 58 59 60 61 |
# File 'lib/rasn1/types/integer.rb', line 53 def to_i val = value? ? @value : @default case val when String, Symbol @enum[val] else val || 0 end end |
#value=(val) ⇒ void
This method returns an undefined value.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rasn1/types/integer.rb', line 31 def value=(val) @no_value = false case val when String, Symbol value_from_string_or_symbol(val) when ::Integer value_from_integer(val) when nil @no_value = true @value = void_value else raise EnumeratedError, "#{@name}: not in enumeration" end end |