dump method

  1. @override
String dump({
  1. int spaces = 0,
})
override

Creates a readable dump from the current ASN1Object.

Important note: Subclasses need to override this method. If the ASN1Object is constructed and has child elements, dump() has to be called for each child element.

Implementation

@override
String dump({int spaces = 0}) {
  var sb = StringBuffer();
  for (var i = 0; i < spaces; i++) {
    sb.write(' ');
  }
  if (isConstructed!) {
    sb.write('BIT STRING (${elements!.length} elem)');
    for (var e in elements!) {
      var dump = e.dump(spaces: spaces + dumpIndent);
      sb.write('\n$dump');
    }
  } else {
    if (ASN1Utils.isASN1Tag(stringValues!.elementAt(0))) {
      var sb2 = StringBuffer();
      for (var v in stringValues!) {
        var s = v.toRadixString(2);
        sb2.write(s);
      }
      var bits = sb2.toString();
      if (unusedbits != null) {
        bits = bits.substring(0, bits.length - unusedbits!);
      }
      var parser = ASN1Parser(stringValues as Uint8List?);
      var next = parser.nextObject();
      var dump = next.dump(spaces: spaces + dumpIndent);
      sb.write('BIT STRING (${bits.length} bit)\n$dump');
    } else {
      var sb2 = StringBuffer();
      for (var v in stringValues!) {
        var s = v.toRadixString(2);
        sb2.write(s);
      }
      var bits = sb2.toString();
      if (unusedbits != null) {
        bits = bits.substring(0, bits.length - unusedbits!);
      }
      sb.write('BIT STRING (${bits.length} bit) ');
      sb.write(bits);
    }
  }
  return sb.toString();
}