Class: RASN1::Types::BitString
- Defined in:
- lib/rasn1/types/bit_string.rb
Overview
ASN.1 Bit String
Constant Summary collapse
- ID =
BitString id value
3
Constants inherited from Primitive
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
-
#bit_length ⇒ Object
Get bit length.
Attributes inherited from Base
#asn1_class, #default, #name, #options
Instance Method Summary collapse
-
#can_build? ⇒ Boolean
Same as RASN1::Types::Base#can_build? but also check bit_length.
-
#initialize(options = {}) ⇒ BitString
constructor
A new instance of BitString.
- #inspect(level = 0) ⇒ String
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.
18 19 20 21 22 23 24 25 26 |
# File 'lib/rasn1/types/bit_string.rb', line 18 def initialize(={}) 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_length ⇒ Object
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
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
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 |