Class: RASN1::Types::Boolean

Inherits:
Primitive show all
Defined in:
lib/rasn1/types/boolean.rb

Overview

ASN.1 Boolean

BOOLEAN is a primitive type to handle true or false values.

Examples:

Booelan

bool = RASN1::Types::Boolean.new(value: true)
bool2 = RASN1.parse(bool.to_der)
bool2.class       #=> RASN1::Types::Boolean
bool3.value       #=> true

Author:

  • Sylvain Daubert

  • LemonTree55

Constant Summary collapse

ID =

Boolean id value

0x01
DER_TRUE =

DER true value

0xff
DER_FALSE =

DER false value

0

Constants inherited from Primitive

Primitive::ASN1_PC

Constants inherited from Base

RASN1::Types::Base::CLASSES, RASN1::Types::Base::CLASS_MASK, RASN1::Types::Base::INDEFINITE_LENGTH, RASN1::Types::Base::MULTI_OCTETS_ID

Instance Attribute Summary

Attributes inherited from Base

#asn1_class, #default, #name, #options

Instance Method Summary collapse

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, #initialize_copy, #inspect, #optional?, parse, #parse!, #primitive?, #specific_initializer, start_tracing, stop_tracing, #tagged?, #to_der, #trace, #type, type, #value, #value=, #value?, #value_size

Constructor Details

This class inherits a constructor from RASN1::Types::Base

Instance Method Details

#der_to_value(der, ber: false) ⇒ void

This method returns an undefined value.

Make boolean value from DER/BER string.

Parameters:

  • der (String)
  • ber (::Boolean) (defaults to: false)

Raises:

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rasn1/types/boolean.rb', line 43

def der_to_value(der, ber: false)
  raise ASN1Error, "tag #{@name}: BOOLEAN should have a length of 1" unless der.size == 1

  bool = der.unpack1('C')
  case bool
  when DER_FALSE
    @value = false
  when DER_TRUE
    @value = true
  else
    raise ASN1Error, "tag #{@name}: bad value 0x%02x for BOOLEAN" % bool unless ber

    @value = true
  end
end

#void_valuefalse

Returns:

  • (false)


32
33
34
# File 'lib/rasn1/types/boolean.rb', line 32

def void_value # rubocop:disable Naming/PredicateMethod
  false
end