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

ID =

BitString id value

3

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 collapse

Attributes inherited from Base

#asn1_class, #default, #name, #options

Instance Method Summary collapse

Methods inherited from Base

#==, constrained?, #constructed?, #do_parse_explicit_with_tracing, #do_parse_with_tracing, encoded_type, #explicit?, #id, #implicit?, #initialize_copy, #optional?, parse, #parse!, #primitive?, #specific_initializer, start_tracing, stop_tracing, #tagged?, #to_der, #trace, #type, type, #value, #value=, #value?, #value_size, #void_value

Constructor Details

#initialize(options = {}) ⇒ BitString

Returns a new instance of BitString.

Parameters:

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

Options Hash (options):

  • :bit_length (Object)

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

See Also:



18
19
20
21
22
23
24
25
26
# File 'lib/rasn1/types/bit_string.rb', line 18

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

    @default_bit_length = @options[:bit_length]
  end
  @bit_length = @options[:bit_length]
end

Instance Attribute Details

#bit_lengthObject

Get bit length



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

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

Instance Method Details

#can_build?Boolean

Same as RASN1::Types::Base#can_build? but also check bit_length

Returns:

See Also:



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

def can_build?
  super || (!@default.nil? && (@bit_length != @default_bit_length))
end

#inspect(level = 0) ⇒ String

Parameters:

Returns:

  • (String)


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

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