encode method

  1. @override
Uint8List encode({
  1. ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER,
})
override

Encodes this ASN1Object depending on the given encodingRule

If no ASN1EncodingRule is given, ENCODING_DER will be used.

Supported encoding rules are :

Throws an UnsupportedAsn1EncodingRuleException if the given encodingRule is not supported.

Implementation

@override
Uint8List encode(
    {ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) {
  if (encodingRule != ASN1EncodingRule.ENCODING_DER) {
    throw UnsupportedAsn1EncodingRuleException(encodingRule);
  }
  var utc = dateTimeValue!.toUtc();
  var year = utc.year.toString();
  var month = utc.month.toString();
  var day = utc.day.toString();
  var hour = utc.hour.toString();
  var minute = utc.minute.toString();
  var second = utc.second.toString();
  // Encode string to YYMMDDhhmm[ss]Z
  var utcString = '$year$month$day$hour$minute${second}Z';
  valueBytes = ascii.encode(utcString);
  valueByteLength = valueBytes!.length;
  return super.encode();
}