addSignatureLtv method
- String outputPath,
- CPDFSignatureLtvOptions options
Adds LTV material to the signed document and writes it to outputPath.
The native SDK reads the document's saved file, collects the signer certificate chain and OCSP / CRL evidence over the network, and appends them as an incremental update. The current document is not modified or reloaded. When CPDFSignatureLtvOptions.appendDocumentTimestamp is true, a document timestamp is appended to a second copy at CPDFSignatureLtvOptions.timestampOutputPath.
A native run that cannot complete, for example because the certificate chain is untrusted or a responder is unreachable, returns a result whose CPDFSignatureLtvResult.success is false and whose CPDFSignatureLtvResult.errors explain why. Invalid arguments throw ArgumentError; an unusable document throws PlatformException.
example:
final result = await document.addSignatureLtv(
'/path/to/signed_ltv.pdf',
const CPDFSignatureLtvOptions(
trustedCertificatePath: '/path/to/root.pem',
),
);
if (result.success) {
await document.open(result.finalPath);
}
Since 3.2.0.
Implementation
Future<CPDFSignatureLtvResult> addSignatureLtv(
String outputPath,
CPDFSignatureLtvOptions options,
) async {
if (outputPath.isEmpty) {
throw ArgumentError.value(
outputPath,
'outputPath',
'An output path is required.',
);
}
if (options.trustedCertificatePath.isEmpty) {
throw ArgumentError.value(
options.trustedCertificatePath,
'options.trustedCertificatePath',
'A trusted certificate path is required.',
);
}
if (options.appendDocumentTimestamp) {
final timestampServerUrl = options.timestampServerUrl;
if (timestampServerUrl == null ||
!_isTimestampServerUrl(timestampServerUrl)) {
throw ArgumentError.value(
timestampServerUrl,
'options.timestampServerUrl',
'An http or https timestamp server URL is required.',
);
}
final timestampOutputPath = options.timestampOutputPath;
if (timestampOutputPath == null ||
timestampOutputPath.isEmpty ||
timestampOutputPath == outputPath) {
throw ArgumentError.value(
timestampOutputPath,
'options.timestampOutputPath',
'A timestamp output path different from outputPath is required.',
);
}
}
final rawResult = await _channel.invokeMethod<Map<Object?, Object?>>(
'add_signature_ltv',
<String, dynamic>{
'output_path': outputPath,
'options': options.toJson(),
},
);
if (rawResult == null) {
throw StateError('Adding LTV material returned no result.');
}
return CPDFSignatureLtvResult.fromJson(
Map<String, dynamic>.from(rawResult),
);
}