time.bend checks
raw source on the hub · import 0xeb25eff332574f4f1d48668b83cdda30/time.bend as Time
bend-osdev-asn1, UTCTime and GeneralizedTime (ITU-T X.680 (02/2021) clauses 47 and 46; their DER forms, X.690 (02/2021) 11.8 and 11.7).
UTCTime: YYMMDDhhmm, optionally ss, then Z or +hhmm / -hhmm (X.680 47.3). GeneralizedTime: YYYYMMDDhh, optionally mm and then ss, a fraction of a second after a full stop or comma, then Z, +hh[mm] / -hh[mm], or nothing (local time) (X.680 46.3; this reader takes fractions only after the seconds, not of an hour or minute). Under the values rule (DER) both must end in Z and keep their seconds (11.7.1, 11.7.2, 11.8.1, 11.8.2), and a GeneralizedTime fraction uses a full stop and ends in a non-zero digit (11.7.3, 11.7.4). Dates must exist in the Gregorian calendar; hours are 0 to 23, minutes and seconds 0 to 59.
A UTCTime holds two digits of its year; the century is a parameter (pivot: years below it are 20YY, the others 19YY). Asn1.utc_pivot() is 50, RFC 5280 4.1.2.5.1's rule.
7 imports
import Base import bend-osdev-bytes@0.1.0.0/bytes.bend as B import ./error.bend as E import ./tag.bend as T import ./node.bend as N import ./rules.bend as R import ./prim.bend as P
Types
type Asn1Zone source · line 25 · raw
Data
Asn1ZuluAsn1Zone
Asn1LocalTimeAsn1Zone
Asn1Offset@negative:Bool -> @hours:Nat -> @minutes:Nat -> Asn1Zone
type Asn1Time source · line 32 · raw
Data
year (four digits), month, day, hour, minute, second, the fraction's digits, and the zone
Asn1Time@year:Nat -> @month:Nat -> @day:Nat -> @hour:Nat -> @minute:Nat -> @second:Nat -> @frac:List<&2, Nat> -> @zone:Asn1Zone -> Asn1Time
type A1TNums source · line 35 · raw
Data
A1TNums@vals:List<&2, Nat> -> @rest:List<&2, U32> -> A1TNums
type A1Gen source · line 41 · raw
Data
A GeneralizedTime read so far: the date and hour, the minute and second (if present), the fraction's digits, the rest, and whether the form is right so far
A1Gen@f:List<&2, Nat> -> @mi:Nat -> @s:Nat -> @has_mi:Bool -> @has_s:Bool -> @frac:List<&2, Nat> -> @rest:List<&2, U32> -> @ok:Bool -> A1Gen
Definitions
def Asn1.utc_pivot source · line 44 · raw
Nat
def a1.t.dig source · line 49 · raw
@+x:U32 -> Bool
def a1.t.val source · line 52 · raw
@x:U32 -> Nat
def a1.t.done source · line 55 · raw
@ok:Bool -> @acc:List<&2, Nat> -> @xs:List<&2, U32> -> Maybe<&2, A1TNums>
def a1.t.nums source · line 63 · raw
@k:Nat -> @xs:List<&2, U32> -> @ok:Bool -> @acc:List<&2, Nat> -> Maybe<&2, A1TNums>
k two-digit numbers
def a1.t.two source · line 73 · raw
@xs:List<&2, U32> -> Bool
whether xs starts with two digits
def a1.t.leap source · line 82 · raw
@+y:Nat -> Bool
def a1.t.mdays source · line 85 · raw
@+y:Nat -> @m:Nat -> Nat
def a1.t.in source · line 100 · raw
@+v:Nat -> @lo:Nat -> @hi:Nat -> Bool
def a1.t.zone_ok source · line 103 · raw
@z:Asn1Zone -> Bool
def Asn1Time.valid source · line 111 · raw
@t:Asn1Time -> Bool
a date and time of day that exist
def a1.t.days.go source · line 116 · raw
@+early:Bool -> @+y:Nat -> @+m:Nat -> @d:Nat -> Nat
def a1.t.days source · line 123 · raw
@+y:Nat -> @+m:Nat -> @d:Nat -> Nat
days from 0000-03-01 (with the year shifted 400 on, so the count stays a natural number): 365 a year, the leap days, and the months from March
def a1.t.shift source · line 126 · raw
@z:Asn1Zone -> @+secs:Nat -> Nat
def Asn1Time.seconds source · line 137 · raw
@t:Asn1Time -> Nat
the time as seconds in UTC (offsets applied; a local time taken as UTC), from an epoch before year 0
def a1.t.fcmp2 source · line 142 · raw
@c:Cmp -> @rest:Cmp -> Cmp
def a1.t.fcmp source · line 153 · raw
@f1:List<&2, Nat> -> @f2:List<&2, Nat> -> Cmp
def a1.t.cmp2 source · line 164 · raw
@c:Cmp -> @f1:List<&2, Nat> -> @f2:List<&2, Nat> -> Cmp
def Asn1Time.cmp source · line 174 · raw
@a:Asn1Time -> @b:Asn1Time -> Cmp
order of two times (fractions of a second compared digit by digit)
def a1.t.sign.pick source · line 179 · raw
@plus:Bool -> @minus:Bool -> Maybe<&2, Bool>
def a1.t.sign source · line 188 · raw
@+x:U32 -> Maybe<&2, Bool>
def a1.t.off source · line 191 · raw
@s:Maybe<&2, Bool> -> @m:Maybe<&2, A1TNums> -> Maybe<&2, Asn1Zone>
def a1.t.zone source · line 202 · raw
@xs:List<&2, U32> -> @+local:Bool -> @+hh_only:Bool -> Maybe<&2, Asn1Zone>
the zone at the end: Z, +hhmm / -hhmm (or +hh / -hh when hh_only), or (when local is allowed) nothing
def a1.t.zulu source · line 213 · raw
@z:Asn1Zone -> Bool
def a1.t.check2 source · line 220 · raw
@ok:Bool -> @t:Asn1Time -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
def Asn1Time.zone source · line 227 · raw
@t:Asn1Time -> Asn1Zone
def a1.t.check source · line 234 · raw
@+der:Bool -> @mt:Maybe<&2, Asn1Time> -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
def a1.utc.year source · line 241 · raw
@+yy:Nat -> @+pivot:Nat -> Nat
def a1.utc.zone source · line 244 · raw
@+pivot:Nat -> @f:List<&2, Nat> -> @+s:Nat -> @m:Maybe<&2, Asn1Zone> -> Maybe<&2, Asn1Time>
def a1.utc.sec source · line 251 · raw
@two:Bool -> @+der:Bool -> @+pivot:Nat -> @f:List<&2, Nat> -> @rest:List<&2, U32> -> Maybe<&2, Asn1Time>
def a1.utc.parse source · line 258 · raw
@m:Maybe<&2, A1TNums> -> @+der:Bool -> @+pivot:Nat -> Maybe<&2, Asn1Time>
def Asn1.utc_of_content source · line 266 · raw
@+r:0xeb25eff332574f4f1d48668b83cdda30/rules.Asn1Rules -> @+pivot:Nat -> @o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
a UTCTime's characters as a time (the century from pivot)
def a1.t.head_dig source · line 272 · raw
@xs:List<&2, U32> -> Bool
def a1.gen.run source · line 280 · raw
@xs:List<&2, U32> -> @d:Bool -> @acc:List<&2, Nat> -> A1TNums
a run of digits (d: whether the first is one), and the rest
def a1.gen.start source · line 289 · raw
@m:Maybe<&2, A1TNums> -> A1Gen
def a1.gen.two.go source · line 296 · raw
@two:Bool -> @g:A1Gen -> A1Gen
def a1.gen.two source · line 306 · raw
@g:A1Gen -> A1Gen
the next two digits, as the minute or then the second, if present
def a1.gen.dec_sign source · line 311 · raw
@+x:U32 -> @+der:Bool -> Bool
def a1.gen.frac.put source · line 314 · raw
@r:A1TNums -> @g:A1Gen -> A1Gen
def a1.gen.frac.go source · line 319 · raw
@sign:Bool -> @g:A1Gen -> A1Gen
def a1.gen.frac source · line 327 · raw
@+der:Bool -> @g:A1Gen -> A1Gen
a fraction of a second, after the seconds
def a1.gen.last0 source · line 334 · raw
@ds:List<&2, Nat> -> @last:Nat -> Bool
def a1.gen.der_ok source · line 342 · raw
@g:A1Gen -> Bool
DER: minutes and seconds present, no trailing zero in the fraction
def a1.gen.mk source · line 347 · raw
@ok:Bool -> @y:Nat -> @mo:Nat -> @d:Nat -> @h:Nat -> @mi:Nat -> @s:Nat -> @fr:List<&2, Nat> -> @z:Maybe<&2, Asn1Zone> -> Maybe<&2, Asn1Time>
def a1.gen.finish source · line 354 · raw
@+der:Bool -> @+g:A1Gen -> Maybe<&2, Asn1Time>
def Asn1.gen_of_content source · line 362 · raw
@+r:0xeb25eff332574f4f1d48668b83cdda30/rules.Asn1Rules -> @o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
a GeneralizedTime's characters as a time
def a1.t.from source · line 368 · raw
@r:Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, 0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets> -> @+rr:0xeb25eff332574f4f1d48668b83cdda30/rules.Asn1Rules -> @+pivot:Nat -> @utc:Bool -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
def Asn1.get_utc_time source · line 378 · raw
@+r:0xeb25eff332574f4f1d48668b83cdda30/rules.Asn1Rules -> @+pivot:Nat -> @n:0xeb25eff332574f4f1d48668b83cdda30/node.Asn1Node -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
a UTCTime element's time
def Asn1.get_gen_time source · line 382 · raw
@+r:0xeb25eff332574f4f1d48668b83cdda30/rules.Asn1Rules -> @n:0xeb25eff332574f4f1d48668b83cdda30/node.Asn1Node -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
a GeneralizedTime element's time
def a1.t.either source · line 385 · raw
@utc:Bool -> @+r:0xeb25eff332574f4f1d48668b83cdda30/rules.Asn1Rules -> @+pivot:Nat -> @n:0xeb25eff332574f4f1d48668b83cdda30/node.Asn1Node -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
def Asn1.get_time source · line 393 · raw
@+r:0xeb25eff332574f4f1d48668b83cdda30/rules.Asn1Rules -> @+pivot:Nat -> @+n:0xeb25eff332574f4f1d48668b83cdda30/node.Asn1Node -> Result<&2, &2, 0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error, Asn1Time>
a UTCTime or GeneralizedTime element's time (X.509's Time)
def a1.t.d2 source · line 398 · raw
@+v:Nat -> List<&2, U32>
def a1.t.ds source · line 401 · raw
@ds:List<&2, Nat> -> List<&2, U32>
def a1.t.drop0 source · line 408 · raw
@ds:List<&2, Nat> -> List<&2, Nat>
def a1.t.trim source · line 415 · raw
@ds:List<&2, Nat> -> List<&2, Nat>
def a1.t.fracs.go source · line 418 · raw
@fr:List<&2, Nat> -> List<&2, U32>
def a1.t.fracs source · line 425 · raw
@fr:List<&2, Nat> -> List<&2, U32>
def a1.t.app source · line 428 · raw
@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>
def Asn1.utc_time source · line 432 · raw
@t:Asn1Time -> 0xeb25eff332574f4f1d48668b83cdda30/node.Asn1Node
a time as a UTCTime element: YYMMDDHHMMSSZ (the year's last two digits)
def Asn1.gen_time source · line 438 · raw
@t:Asn1Time -> 0xeb25eff332574f4f1d48668b83cdda30/node.Asn1Node
a time as a GeneralizedTime element: YYYYMMDDHHMMSS[.f]Z
def a1.t.show2 source · line 443 · raw
@+v:Nat -> String
def a1.t.show_zone source · line 446 · raw
@z:Asn1Zone -> String
def Asn1Time.show source · line 456 · raw
@t:Asn1Time -> String
a time as text: YYYY-MM-DDTHH:MM:SS[.f] and Z, +HH:MM / -HH:MM, or nothing