Interface MultiPassStrategy
-
- All Known Implementing Classes:
InMemoryMultiPassStrategy
,WriteToFileMultiPassStrategy
public interface MultiPassStrategy
Since for verification of cleartext signed messages, we need to read the whole data twice in order to verify signatures, a strategy for how to cache the read data is required. Otherwise, large data kept in memory could causeOutOfMemoryErrors
or other issues. This is an Interface that describes a strategy to deal with the fact that detached signatures require multiple passes to do verification. This interface can be used to write the signed data stream out viagetMessageOutputStream()
and later get access to the data again viagetMessageInputStream()
. Thereby the detail where the data is being stored (memory, file, etc.) can be abstracted away.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description java.io.InputStream
getMessageInputStream()
Provide anInputStream
which contains the data that was previously written away ingetMessageOutputStream()
.java.io.OutputStream
getMessageOutputStream()
Provide anOutputStream
into which the signed data can be read into.static InMemoryMultiPassStrategy
keepMessageInMemory()
Read the message content into memory.static MultiPassStrategy
writeMessageToFile(java.io.File file)
Write the message content out to a file and re-read it to verify signatures.
-
-
-
Method Detail
-
getMessageOutputStream
java.io.OutputStream getMessageOutputStream() throws java.io.IOException
Provide anOutputStream
into which the signed data can be read into.- Returns:
- output stream
- Throws:
java.io.IOException
- io error
-
getMessageInputStream
java.io.InputStream getMessageInputStream() throws java.io.IOException
Provide anInputStream
which contains the data that was previously written away ingetMessageOutputStream()
. As there may be multiple signatures that need to be processed, each call of this method MUST return a newInputStream
.- Returns:
- input stream
- Throws:
java.io.IOException
- io error
-
writeMessageToFile
static MultiPassStrategy writeMessageToFile(java.io.File file)
Write the message content out to a file and re-read it to verify signatures. This strategy is best suited for larger messages (e.g. plaintext signed files) which might not fit into memory. After the message has been processed completely, the messages content are available at the provided file.- Parameters:
file
- target file- Returns:
- strategy
-
keepMessageInMemory
static InMemoryMultiPassStrategy keepMessageInMemory()
Read the message content into memory. This strategy is best suited for small messages which fit into memory. After the message has been processed completely, the message content can be accessed by callingByteArrayOutputStream.toByteArray()
ongetMessageOutputStream()
.- Returns:
- strategy
-
-