Search in sources :

Example 1 with COSFilterInputStream

use of com.tom_roush.pdfbox.pdmodel.interactive.digitalsignature.COSFilterInputStream in project PdfBox-Android by TomRoush.

the class COSWriter method getDataToSign.

/**
 * Return the stream of PDF data to be signed. Clients should use this method only to create
 * signatures externally. {@link #write(PDDocument)} method should have been called prior.
 * The created signature should be set using {@link #writeExternalSignature(byte[])}.
 * <p>
 * When {@link SignatureInterface} instance is used, COSWriter obtains and writes the signature itself.
 * </p>
 *
 * @return data stream to be signed
 * @throws IllegalStateException if PDF is not prepared for external signing
 * @throws IOException if input data is closed
 */
public InputStream getDataToSign() throws IOException {
    if (incrementPart == null || incrementalInput == null) {
        throw new IllegalStateException("PDF not prepared for signing");
    }
    // range of incremental bytes to be signed (includes /ByteRange but not /Contents)
    int incPartSigOffset = (int) (signatureOffset - incrementalInput.length());
    int afterSigOffset = incPartSigOffset + (int) signatureLength;
    int[] range = { 0, incPartSigOffset, afterSigOffset, incrementPart.length - afterSigOffset };
    return new SequenceInputStream(new RandomAccessInputStream(incrementalInput), new COSFilterInputStream(incrementPart, range));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) COSFilterInputStream(com.tom_roush.pdfbox.pdmodel.interactive.digitalsignature.COSFilterInputStream) RandomAccessInputStream(com.tom_roush.pdfbox.io.RandomAccessInputStream)

Aggregations

RandomAccessInputStream (com.tom_roush.pdfbox.io.RandomAccessInputStream)1 COSFilterInputStream (com.tom_roush.pdfbox.pdmodel.interactive.digitalsignature.COSFilterInputStream)1 SequenceInputStream (java.io.SequenceInputStream)1