toDer static method
Converts a list of BigInt values to DER-encoded bytes.
The toDer method takes a list of BigInt values bigIntList
and encodes them in DER format.
It returns a list of bytes representing the DER-encoded sequence of integers.
Example Usage:
List<BigInt> values = [BigInt.from(123), BigInt.from(456)];
List<int> derBytes = DEREncoding.toDer(values);
Parameters:
bigIntList
: The list of BigInt values to be DER-encoded. Returns: A list of bytes representing the DER-encoded sequence of integers.
Implementation
static List<int> toDer(List<BigInt> bigIntList) {
List<List<int>> encodedIntegers = bigIntList.map((bi) {
List<int> bytes = _encodeInteger(bi);
return bytes;
}).toList();
List<int> lengthBytes =
_encodeLength(encodedIntegers.fold<int>(0, (sum, e) => sum + e.length));
List<int> contentBytes =
encodedIntegers.fold<List<int>>([], (prev, e) => [...prev, ...e]);
_encodeLength(200);
var derBytes = [
0x30,
...lengthBytes,
...contentBytes,
];
return derBytes;
}