parse static method
Implementation
static ASN1OctetString parse(final MutableIterable bytes) {
if (bytes.length < 2) {
throw Exception('Invalid data!');
}
int tag = bytes.first;
if (tag != ASN1Type.octetStringTag) {
throw Exception('Invalid tag!');
}
bytes.mutate = bytes.skip(1);
final lengthBigInt = ASN1Object.decodeLength(bytes);
int length = lengthBigInt.toInt();
if (length == 0) {
return ASN1OctetString(Uint8List(0));
}
if (bytes.length < length) {
throw Exception('Invalid data');
}
final contentBytes = bytes.take(length);
bytes.mutate = bytes.skip(length);
return ASN1OctetString(Uint8List.fromList(contentBytes.toList()));
}