Class CMSTimeStampedData
java.lang.Object
org.bouncycastle.tsp.cms.CMSTimeStampedData
In-memory holder for an RFC 5544 TimeStampedData object - a document (or a URI
referencing one) bound to the temporal evidence (a chain of RFC 3161 time stamp
tokens) that proves it existed before a given point in time.
The wrapped ContentInfo must be of type id-ct-timestampedData; the
encapsulated TimeStampedData carries the optional dataUri, MetaData and content
along with the Evidence holding the time stamp chain. Use
CMSTimeStampedDataParser for a streaming alternative.
-
Constructor Summary
ConstructorsConstructorDescriptionCMSTimeStampedData(byte[] baseData) CMSTimeStampedData(org.bouncycastle.asn1.cms.ContentInfo contentInfo) -
Method Summary
Modifier and TypeMethodDescriptionaddTimeStamp(TimeStampToken token) Return a new timeStampedData object with the additional token attached to the end of the evidence chain.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).byte[]Return the encapsulated content, if present.Return the dataUri referencing the time-stamped document, if present.byte[]Return the DER encoding of the underlying timestampedData ContentInfo.getMessageImprintDigestCalculator(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.AttributeTableReturn the time stamp tokens making up the evidence chain, in order.voidInitialise 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.
-
Constructor Details
-
CMSTimeStampedData
public CMSTimeStampedData(org.bouncycastle.asn1.cms.ContentInfo contentInfo) -
CMSTimeStampedData
- Throws:
IOException
-
CMSTimeStampedData
- Throws:
IOException
-
-
Method Details
-
calculateNextHash
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.
-
addTimeStamp
Return a new timeStampedData object with the additional token attached to the end of the evidence chain. The new token is expected to time stamp the previous chain element (seecalculateNextHash(DigestCalculator)), extending the validity of the earlier tokens.- Parameters:
token- the time stamp token to append.- Returns:
- a new CMSTimeStampedData carrying the extended evidence chain.
- Throws:
CMSException- if the new structure cannot be built.
-
getContent
public byte[] getContent()Return the encapsulated content, if present.- Returns:
- the content octets, or null if no content is carried (e.g. a dataUri is used instead).
-
getDataUri
Return the dataUri referencing the time-stamped document, if present.- Returns:
- the dataUri, or null if none was set.
- Throws:
URISyntaxException- if the stored value is not a valid URI.
-
getFileName
-
getMediaType
-
getOtherMetaData
public org.bouncycastle.asn1.cms.AttributeTable getOtherMetaData() -
getTimeStampTokens
Return the time stamp tokens making up the evidence chain, in order.- Returns:
- an array of the time stamp tokens present in the message.
- Throws:
CMSException- if a token cannot be parsed.
-
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.
-
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.
-
getEncoded
Return the DER encoding of the underlying timestampedData ContentInfo.- Returns:
- the encoded ContentInfo.
- Throws:
IOException- if encoding fails.
-