Package org.bouncycastle.tsp.cms
Class CMSTimeStampedDataParser
- java.lang.Object
-
- org.bouncycastle.cms.CMSContentInfoParser
-
- org.bouncycastle.tsp.cms.CMSTimeStampedDataParser
-
public class CMSTimeStampedDataParser extends CMSContentInfoParser
Streaming parser for an RFC 5544 TimeStampedData object. It exposes the dataUri, MetaData and (streamed) content of the time-stamped document together with the Evidence chain of RFC 3161 time stamp tokens, reading from the supplied stream lazily rather than buffering the whole structure asCMSTimeStampedDatadoes.The encapsulated content is drained from
getContent()before the trailing evidence block can be parsed; the methods that need the time stamps (getTimeStampTokens(),getMessageImprintDigestCalculator(org.bouncycastle.operator.DigestCalculatorProvider), thevalidatemethods) drain it automatically. The supplied InputStream is closed only whenCMSContentInfoParser.close()(inherited fromCMSContentInfoParser) is invoked.
-
-
Field Summary
-
Fields inherited from class org.bouncycastle.cms.CMSContentInfoParser
_contentInfo, _data
-
-
Constructor Summary
Constructors Constructor Description CMSTimeStampedDataParser(byte[] baseData)CMSTimeStampedDataParser(java.io.InputStream in)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]calculateNextHash(DigestCalculator calculator)Calculate the hash over the last time stamp element in the evidence chain, as required to obtain the next time stamp token that extends the chain (per RFC 5544 each token is computed over its preceding element).java.io.InputStreamgetContent()Return a stream over the encapsulated content, if present.java.net.URIgetDataUri()Return the dataUri referencing the time-stamped document, if present.java.lang.StringgetFileName()java.lang.StringgetMediaType()DigestCalculatorgetMessageImprintDigestCalculator(DigestCalculatorProvider calculatorProvider)Returns an appropriately initialised digest calculator based on the message imprint algorithm described in the first time stamp in the TemporalData for this message.org.bouncycastle.asn1.cms.AttributeTablegetOtherMetaData()TimeStampToken[]getTimeStampTokens()Return the time stamp tokens making up the evidence chain, in order.voidinitialiseMessageImprintDigestCalculator(DigestCalculator calculator)Initialise the passed in calculator with the MetaData for this message, if it is required as part of the initial message imprint calculation.voidvalidate(DigestCalculatorProvider calculatorProvider, byte[] dataDigest)Validate the digests present in the TimeStampTokens contained in the CMSTimeStampedData.voidvalidate(DigestCalculatorProvider calculatorProvider, byte[] dataDigest, TimeStampToken timeStampToken)Validate the passed in timestamp token against the tokens and data present in the message.-
Methods inherited from class org.bouncycastle.cms.CMSContentInfoParser
close, isBEREncoded
-
-
-
-
Constructor Detail
-
CMSTimeStampedDataParser
public CMSTimeStampedDataParser(java.io.InputStream in) throws CMSException- Throws:
CMSException
-
CMSTimeStampedDataParser
public CMSTimeStampedDataParser(byte[] baseData) throws CMSException- Throws:
CMSException
-
-
Method Detail
-
calculateNextHash
public byte[] calculateNextHash(DigestCalculator calculator) throws CMSException
Calculate the hash over the last time stamp element in the evidence chain, as required to obtain the next time stamp token that extends the chain (per RFC 5544 each token is computed over its preceding element).- Parameters:
calculator- the digest calculator to use.- Returns:
- the digest of the DER encoding of the most recent TimeStampAndCRL.
- Throws:
CMSException- if the hash cannot be calculated.
-
getContent
public java.io.InputStream getContent()
Return a stream over the encapsulated content, if present. The stream must be drained before the trailing evidence block can be parsed.- Returns:
- an InputStream over the content octets, or null if no content is carried.
-
getDataUri
public java.net.URI getDataUri() throws java.net.URISyntaxExceptionReturn the dataUri referencing the time-stamped document, if present.- Returns:
- the dataUri, or null if none was set.
- Throws:
java.net.URISyntaxException- if the stored value is not a valid URI.
-
getFileName
public java.lang.String getFileName()
-
getMediaType
public java.lang.String getMediaType()
-
getOtherMetaData
public org.bouncycastle.asn1.cms.AttributeTable getOtherMetaData()
-
initialiseMessageImprintDigestCalculator
public void initialiseMessageImprintDigestCalculator(DigestCalculator calculator) throws CMSException
Initialise the passed in calculator with the MetaData for this message, if it is required as part of the initial message imprint calculation.- Parameters:
calculator- the digest calculator to be initialised.- Throws:
CMSException- if the MetaData is required and cannot be processed
-
getMessageImprintDigestCalculator
public DigestCalculator getMessageImprintDigestCalculator(DigestCalculatorProvider calculatorProvider) throws OperatorCreationException
Returns an appropriately initialised digest calculator based on the message imprint algorithm described in the first time stamp in the TemporalData for this message. If the metadata is required to be included in the digest calculation, the returned calculator will be pre-initialised.- Parameters:
calculatorProvider- a provider of DigestCalculator objects.- Returns:
- an initialised digest calculator.
- Throws:
OperatorCreationException- if the provider is unable to create the calculator.
-
getTimeStampTokens
public TimeStampToken[] getTimeStampTokens() throws CMSException
Return the time stamp tokens making up the evidence chain, in order. The encapsulated content is drained first if it has not already been read.- Returns:
- an array of the time stamp tokens present in the message.
- Throws:
CMSException- if the evidence block cannot be parsed.
-
validate
public void validate(DigestCalculatorProvider calculatorProvider, byte[] dataDigest) throws ImprintDigestInvalidException, CMSException
Validate the digests present in the TimeStampTokens contained in the CMSTimeStampedData.- Parameters:
calculatorProvider- provider for digest calculatorsdataDigest- the calculated data digest for the message- Throws:
ImprintDigestInvalidException- if an imprint digest fails to compareCMSException- if an exception occurs processing the message.
-
validate
public void validate(DigestCalculatorProvider calculatorProvider, byte[] dataDigest, TimeStampToken timeStampToken) throws ImprintDigestInvalidException, CMSException
Validate the passed in timestamp token against the tokens and data present in the message.- Parameters:
calculatorProvider- provider for digest calculatorsdataDigest- the calculated data digest for the message.timeStampToken- the timestamp token of interest.- Throws:
ImprintDigestInvalidException- if the token is not present in the message, or an imprint digest fails to compare.CMSException- if an exception occurs processing the message.
-
-