encode method
Encodes this ASN1Object depending on the given encodingRule
If no ASN1EncodingRule is given, ENCODING_DER will be used.
Supported encoding rules are :
- ASN1EncodingRule.ENCODING_DER
- ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM
- ASN1EncodingRule.ENCODING_BER_CONSTRUCTED
- ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH
- ASN1EncodingRule.ENCODING_BER_PADDED
Throws an UnsupportedAsn1EncodingRuleException if the given encodingRule
is not supported.
Implementation
@override
Uint8List encode(
{ASN1EncodingRule encodingRule = ASN1EncodingRule.ENCODING_DER}) {
switch (encodingRule) {
case ASN1EncodingRule.ENCODING_BER_PADDED:
case ASN1EncodingRule.ENCODING_DER:
case ASN1EncodingRule.ENCODING_BER_LONG_LENGTH_FORM:
var b = <int>[];
if (unusedbits != null) {
b.add(unusedbits!);
} else {
b.add(0);
}
b.addAll(stringValues!);
valueBytes = Uint8List.fromList(b);
break;
case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH:
case ASN1EncodingRule.ENCODING_BER_CONSTRUCTED:
valueByteLength = 0;
if (elements == null) {
elements = <ASN1Object>[];
elements!.add(ASN1BitString(stringValues: stringValues));
}
valueByteLength = _childLength(
isIndefinite: encodingRule ==
ASN1EncodingRule.ENCODING_BER_CONSTRUCTED_INDEFINITE_LENGTH);
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;
}
break;
}
return super.encode(encodingRule: encodingRule);
}