ASN1BMPString.fromBytes constructor

ASN1BMPString.fromBytes(
  1. 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 sb = StringBuffer();
    for (var b in valueBytes!) {
      if (b != 0) {
        sb.write(ascii.decode([b]));
      }
    }
    stringValue = sb.toString();
  }
}