Class: RASN2::Types::BitString
- Defined in:
- lib/rasn2/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
RASN2::Types::Base::CLASSES, RASN2::Types::Base::CLASS_MASK, RASN2::Types::Base::INDEFINITE_LENGTH, RASN2::Types::Base::MULTI_OCTETS_ID
Instance Attribute Summary collapse
-
#bit_length ⇒ Object
Get bit length.
Attributes inherited from Base
#asn1_class, #default, #model, #name, #options
Instance Method Summary collapse
-
#can_build? ⇒ Boolean
Same as RASN2::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_value ⇒ Object
Methods inherited from Base
#==, #asn1_class_to_s, #attributes, #bin2hex, #build, #check_id, #colorize, #common_inspect, constrained?, #constructed?, #der2name, #do_parse, #do_parse_explicit, #do_parse_explicit_with_tracing, #do_parse_with_tracing, #encode_identifier_octets, #encode_size, encoded_type, #explicit?, #find_type, #get_data, #get_length, #id, #id2octets, #id_value, #implicit?, #indent, #initialize_copy, #inspect, #msg_type, #optional?, parse, #parse!, #pc_bit, #primitive?, #private?, #raise_id_error, #raise_on_indefinite_length, #self2name, #set_class, #set_default, #set_optional, #set_tag, #set_value, #specific_initializer, start_tracing, stop_tracing, #tag_id_to_integer, #tagged?, #to_der, #trace, #trace_data, #trace_real, #tracer, type, #type, #universal?, #unpack, #unsigned_to_chained_octets, #value, #value=, #value?, #value_size, #void_value
Methods included from Helpers::Colorize
#begin_colorizer, #brace_surround, #colorize, #colorize_attribute, #colorize_bool, #colorize_class, #colorize_default, #colorize_enum, #colorize_id, #colorize_name, #colorize_nil, #colorize_value, #colorizer, #colorizer=, #end_colorizer, #int_with_hex, #length_specifier, #parens_hex
Constructor Details
#initialize(options = {}) ⇒ BitString
Returns a new instance of BitString.
18 19 20 21 22 23 24 25 26 |
# File 'lib/rasn2/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/rasn2/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 RASN2::Types::Base#can_build? but also check bit_length
44 45 46 |
# File 'lib/rasn2/types/bit_string.rb', line 44 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.
53 54 55 56 57 58 |
# File 'lib/rasn2/types/bit_string.rb', line 53 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_value ⇒ Object
37 38 39 |
# File 'lib/rasn2/types/bit_string.rb', line 37 def inspect_value "(bit length: #{bit_length}): #{value.inspect}" end |