derGeneralizedTime function

Uint8List derGeneralizedTime(
  1. DateTime time
)

GeneralizedTime in the DER canonical form (always UTC, seconds present, no fractional part) - what RFC 5280 ยง4.1.2.5.2 and RFC 3161 require.

Implementation

Uint8List derGeneralizedTime(DateTime time) {
  final t = time.toUtc();
  String two(int v) => v.toString().padLeft(2, '0');
  final text = '${t.year.toString().padLeft(4, '0')}${two(t.month)}'
      '${two(t.day)}${two(t.hour)}${two(t.minute)}${two(t.second)}Z';
  return derEncode(DerTag.generalizedTime, text.codeUnits);
}