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.
-
#der_to_value(der, ber: false) ⇒ void
Make value from DER/BER string.
-
#initialize(options = {}) ⇒ BitString
constructor
A new instance of BitString.
- #inspect(level = 0) ⇒ String
Methods inherited from Base
#==, constrained?, #constructed?, #do_parse, #do_parse_explicit, #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.
24 25 26 27 28 29 30 31 32 |
# File 'lib/rasn1/types/bit_string.rb', line 24 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
35 36 37 38 39 40 41 |
# File 'lib/rasn1/types/bit_string.rb', line 35 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
53 54 55 |
# File 'lib/rasn1/types/bit_string.rb', line 53 def can_build? super || (!@default.nil? && (@bit_length != @default_bit_length)) end |
#der_to_value(der, ber: false) ⇒ void
This method returns an undefined value.
Make value from DER/BER string. Also set #bit_length.
62 63 64 65 66 67 |
# File 'lib/rasn1/types/bit_string.rb', line 62 def der_to_value(der, ber: false) # rubocop:disable Lint/UnusedMethodArgument unused = der.unpack1('C').to_i value = der[1..].to_s @bit_length = value.length * 8 - unused @value = value end |
#inspect(level = 0) ⇒ String
45 46 47 48 |
# File 'lib/rasn1/types/bit_string.rb', line 45 def inspect(level=0) str = common_inspect(level) str << " #{value.inspect} (bit length: #{bit_length})" end |