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);
  }
  valueBytes = Uint8List(0);
  valueByteLength = 0;
  if (elements != null) {
    valueByteLength = _childLength();
    valueBytes = Uint8List(valueByteLength!);
    var i = 0;
    for (var obj in elements!) {
      var b = obj.encode();
      valueBytes!.setRange(i, i + b.length, b);
      i += b.length;
    }
  }
  return super.encode();
}