Class: RASN1::Types::BitString

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

Overview

ASN.1 Bit String

Author:

  • Sylvain Daubert

Constant Summary collapse

TAG =

BitString tag value

0x03

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::MAX_TAG, RASN1::Types::Base::UNDUPPABLE_TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#asn1_class, #default, #name, #value

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(options = {}) ⇒ BitString #initialize(value, options = {}) ⇒ BitString

Returns a new instance of BitString.

Overloads:

  • #initialize(options = {}) ⇒ BitString

    Parameters:

    • options (Hash) (defaults to: {})

    Options Hash (options):

    • :bit_length (Object)

      default bit_length value. Should be present if :default is set

  • #initialize(value, options = {}) ⇒ BitString

    Parameters:

    • value (Object)

      value to set for this ASN.1 object

    • options (Hash) (defaults to: {})

    Options Hash (options):

    • :bit_length (Object)

      default bit_length value. Should be present if :default is set

See Also:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rasn1/types/bit_string.rb', line 25

def initialize(value_or_options={}, options={})
  super
  opts = value_or_options.is_a?(Hash) ? value_or_options : options
  if @default
    if opts[:bit_length].nil?
      raise ASN1Error, "TAG #{@name}: default bit length is not defined"
    end
    @default_bit_length = opts[:bit_length]
  end
  @bit_length = opts[:bit_length]
end

Instance Attribute Details

#bit_lengthObject

Get bit length



38
39
40
41
42
43
44
# File 'lib/rasn1/types/bit_string.rb', line 38

def bit_length
  if @value.nil?
    @default_bit_length
  else
    @bit_length
  end
end

Instance Method Details

#inspect(level = 0) ⇒ String

Parameters:

Returns:

  • (String)


48
49
50
51
# File 'lib/rasn1/types/bit_string.rb', line 48

def inspect(level=0)
  str = common_inspect(level)
  str << " #{value.inspect} (bit length: #{bit_length})"
end