Class: RASN1::Types::OctetString

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

Overview

ASN.1 Octet String

An OCTET STRINT may contain another primtive object:

os = OctetString.new
int = Integer.new
int.value = 12
os.value = int
os.to_der   # => DER string with INTEGER in OCTET STRING

Author:

  • Sylvain Daubert

Constant Summary collapse

ID =

OctetString id value

4

Constants inherited from Primitive

Primitive::ASN1_PC

Constants inherited from Base

Base::CLASSES, Base::CLASS_MASK, Base::INDEFINITE_LENGTH, Base::MULTI_OCTETS_ID

Instance Attribute Summary

Attributes inherited from Base

#asn1_class, #default, #name, #options

Instance Method Summary collapse

Methods inherited from Base

#==, #can_build?, constrained?, #constructed?, #do_parse, #do_parse_explicit, #do_parse_explicit_with_tracing, #do_parse_with_tracing, encoded_type, #explicit?, #id, #implicit?, #initialize, #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

This class inherits a constructor from RASN1::Types::Base

Instance Method Details

#der_to_value(der, ber: false) ⇒ void

This method returns an undefined value.

Make string value from der string. Force encoding to UTF-8

Parameters:

  • der (String)
  • ber (::Boolean) (defaults to: false)

Since:

  • 0.15.0 Handle ENCODING constant, if defined by subclass



30
31
32
33
34
35
36
37
# File 'lib/rasn1/types/octet_string.rb', line 30

def der_to_value(der, ber: false)
  klass = self.class
  if klass.const_defined?(:ENCODING)
    @value = der.to_s.dup.force_encoding(klass.const_get(:ENCODING))
  else
    super
  end
end

#inspect(level = 0) ⇒ String

Parameters:

  • level (::Integer) (defaults to: 0)

Returns:

  • (String)


20
21
22
23
# File 'lib/rasn1/types/octet_string.rb', line 20

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