ASN1BMPString.fromBytes constructor
ASN1BMPString.fromBytes(
- Uint8List encodedBytes
Creates an ASN1BMPString entity from the given encodedBytes
.
Implementation
ASN1BMPString.fromBytes(Uint8List encodedBytes)
: super.fromBytes(encodedBytes) {
if (ASN1Utils.isConstructed(encodedBytes.elementAt(0))) {
elements = [];
var parser = ASN1Parser(valueBytes);
var sb = StringBuffer();
while (parser.hasNext()) {
var bmpString = parser.nextObject() as ASN1BMPString;
sb.write(bmpString.stringValue);
elements!.add(bmpString);
}
stringValue = sb.toString();
} else {
var utf16CodeUnits = <int>[];
for (var i = 0; i < valueBytes!.length; i += 2) {
// Combine High-Byte and Low-Byte to create a UTF-16 code unit
var highByte = valueBytes![i];
var lowByte = valueBytes![i + 1];
utf16CodeUnits.add((highByte << 8) | lowByte);
}
// Decode UTF-16 code units into a Dart String
stringValue = String.fromCharCodes(utf16CodeUnits);
}
}