class RASN1::Types::UtcTime
ASN.1 UTCTime
+{#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
Constants
- ID
UtcTime
id value
Public Class Methods
type()
click to toggle source
Get ASN.1 type @return [String]
# File lib/rasn1/types/utc_time.rb, line 26 def self.type 'UTCTime' end
Private Instance Methods
der_to_value(der, ber: false)
click to toggle source
# File lib/rasn1/types/utc_time.rb, line 36 def der_to_value(der, ber: false) format = case der.size when 11 '%Y%m%d%H%MZ' when 13 '%Y%m%d%H%M%SZ' when 15 '%Y%m%d%H%M%z' when 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 @value = DateTime.strptime(century + der, format).to_time end
value_to_der()
click to toggle source
# File lib/rasn1/types/utc_time.rb, line 32 def value_to_der @value.getutc.strftime('%y%m%d%H%M%SZ') end