createLongTermValidity method
Future<bool>
createLongTermValidity({
- List<
List< ? publicCertificatesData,int> > - RevocationType type = RevocationType.ocspAndCrl,
- bool includePublicCertificates = false,
Creates long-term validation of the signature.
// Load the existing PDF document.
PdfDocument document =
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
// Create a new PDF document.
PdfSignatureField field = document.form.fields[0] as PdfSignatureField;
// Check if field is signed.
if (field.isSigned) {
// Create a long-term validation for the signature.
bool isLTV = await field.signature!
.createLongTermValidity(includePublicCertificates: true);
}
// Save the document.
List<int> bytes = await document.save();
// Dispose the document.
document.dispose();
Implementation
Future<bool> createLongTermValidity(
{List<List<int>>? publicCertificatesData,
RevocationType type = RevocationType.ocspAndCrl,
bool includePublicCertificates = false}) async {
final List<X509Certificate> x509CertificateList = <X509Certificate>[];
if (publicCertificatesData != null) {
final X509CertificateParser parser = X509CertificateParser();
for (final List<int> certRawData in publicCertificatesData) {
final X509Certificate certificate =
parser.readCertificate(PdfStreamReader(certRawData))!;
x509CertificateList.add(certificate);
}
} else {
final List<X509Certificate?>? certChain = timestampServer != null
? await _helper.getTimestampCertificateChain()
: _helper.getCertificateChain();
if (certChain != null) {
for (final X509Certificate? certificate in certChain) {
if (certificate != null) {
x509CertificateList.add(certificate);
}
}
certChain.clear();
}
}
if (x509CertificateList.isNotEmpty) {
return _helper.getDSSDetails(
x509CertificateList, type, includePublicCertificates);
} else {
return false;
}
}