applyLtv method

Future<({bool applied, Uint8List bytes})> applyLtv({
  1. required Uint8List pdfBytes,
  2. List<Uint8List> crl = const <Uint8List>[],
  3. List<Uint8List> ocsp = const <Uint8List>[],
  4. List<Uint8List> certs = const <Uint8List>[],
})

Implementation

Future<({Uint8List bytes, bool applied})> applyLtv({
  required Uint8List pdfBytes,
  List<Uint8List> crl = const <Uint8List>[],
  List<Uint8List> ocsp = const <Uint8List>[],
  List<Uint8List> certs = const <Uint8List>[],
}) async {
  if (crl.isEmpty && ocsp.isEmpty && certs.isEmpty) {
    return (bytes: pdfBytes, applied: false);
  }

  final parser = PdfDocumentParser(pdfBytes);
  final document = PdfDocument.load(parser);
  document.ensureDss();

  for (final c in crl) {
    document.dss!.addCrlBytes(c);
  }
  for (final o in ocsp) {
    document.dss!.addOcspBytes(o);
  }
  for (final cert in certs) {
    document.dss!.addCertBytes(cert);
  }

  if (document.dss!.isEmpty) {
    return (bytes: pdfBytes, applied: false);
  }

  final out = await document.save();
  return (bytes: Uint8List.fromList(out), applied: true);
}