Class: RASN2::Types::GeneralizedTime

Inherits:
Primitive show all
Defined in:
lib/rasn2/types/generalized_time.rb

Overview

ASN.1 GeneralizedTime

+Base#value of a GeneralizedTime should be a ruby Time.

===Notes When encoding, resulting string is always a UTC time, appended with Z. Minutes and seconds are always generated. Fractions of second are generated if value Time object have them.

On parsing, are supported:

  • UTC times (ending with Z),
  • local times (no suffix),
  • local times with difference between UTC and this local time (ending with sHHMM, where s is +++ or -, and HHMM is the time differential betwen UTC and local time). These times may include minutes and seconds. Fractions of hour, minute and second are supported.

Author:

  • Sylvain Daubert

Constant Summary collapse

ID =

GeneralizedTime id value

24
HOUR_TO_SEC =
3600
MINUTE_TO_SEC =
60
SECOND_TO_SEC =
1

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, #model, #name, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #asn1_class_to_s, #attributes, #bin2hex, #build, #can_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?, #explicit_type, #find_type, #get_data, #get_length, #id, #id2octets, #id_value, #implicit?, #indent, #initialize, #initialize_copy, #inspect, #inspect_value, #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_real, #tracer, #type, #universal?, #unpack, #unsigned_to_chained_octets, #value, #value=, #value?, #value_size

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

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

Class Method Details

.typeString

Get ASN.1 type

Returns:

  • (String)


38
39
40
# File 'lib/rasn2/types/generalized_time.rb', line 38

def self.type
  'GeneralizedTime'
end

Instance Method Details

#der_to_value(der, ber: false) ⇒ void

This method returns an undefined value.

Make time value from der string

Parameters:

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


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rasn2/types/generalized_time.rb', line 51

def der_to_value(der, ber: false) # rubocop:disable Lint/UnusedMethodArgument
  date_hour, fraction = der.split('.')
  date_hour = date_hour.to_s
  fraction = fraction.to_s

  if fraction.empty?
    value_when_fraction_empty(date_hour)
  elsif fraction[-1] == 'Z'
    value_when_fraction_ends_with_z(date_hour, fraction)
  else
    value_on_others_cases(date_hour, fraction)
  end
end

#void_valueTime

Returns:

  • (Time)


43
44
45
# File 'lib/rasn2/types/generalized_time.rb', line 43

def void_value
  Time.now
end