Class: RASN1::Types::UtcTime

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

Overview

ASN.1 UTCTime

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

Notes

When encoding, resulting string is always a UTC time, appended with Z. Seconds are always generated.

On parsing, UTC times (ending with Z) and local times (ending with sHHMM, where s is +++ or -, and HHMM is the time differential betwen UTC and local time) are both supported. Seconds may be present or not.

Author:

  • Sylvain Daubert

Constant Summary collapse

ID =

UtcTime id value

23

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

Class Method Summary collapse

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, #inspect, #optional?, parse, #parse!, #primitive?, #specific_initializer, start_tracing, stop_tracing, #tagged?, #to_der, #trace, #type, #value, #value=, #value?, #value_size, #void_value

Constructor Details

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

Class Method Details

.typeString

Get ASN.1 type

Returns:

  • (String)


26
27
28
# File 'lib/rasn1/types/utc_time.rb', line 26

def self.type
  'UTCTime'
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)

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rasn1/types/utc_time.rb', line 35

def der_to_value(der, ber: false) # rubocop:disable Lint/UnusedMethodArgument
  format = case der.size
           when 11, 15
             '%Y%m%d%H%M%z'
           when 13, 17
             '%Y%m%d%H%M%S%z'
           else
             prefix = @name.nil? ? type : "tag #{@name}"
             raise ASN1Error, "#{prefix}: unrecognized format: #{der}"
           end
  century = (Time.now.year / 100).to_s
  begin
    @value = Strptime.new(format).exec(century + der)
  rescue ArgumentError
    prefix = @name.nil? ? type : "tag #{@name}"
    raise ASN1Error, "#{prefix}: unrecognized format: #{der}"
  end
end