use of com.github.zhenwei.pkix.util.asn1.tsp.ArchiveTimeStamp in project LinLong-Java by zhenwei1108.
the class ERSArchiveTimeStampGenerator method generateArchiveTimeStamp.
public ERSArchiveTimeStamp generateArchiveTimeStamp(TimeStampResponse tspResponse) throws TSPException, ERSException {
PartialHashtree[] reducedHashTree = getPartialHashtrees();
byte[] rootHash = rootNodeCalculator.computeRootHash(digCalc, reducedHashTree);
TSTInfo tstInfo = tspResponse.getTimeStampToken().getTimeStampInfo().toASN1Structure();
if (!tstInfo.getMessageImprint().getHashAlgorithm().equals(digCalc.getAlgorithmIdentifier())) {
throw new ERSException("time stamp imprint for wrong algorithm");
}
if (!Arrays.areEqual(tstInfo.getMessageImprint().getHashedMessage(), rootHash)) {
throw new ERSException("time stamp imprint for wrong root hash");
}
ArchiveTimeStamp ats;
if (reducedHashTree.length == 1) {
// just include the TimeStamp
ats = new ArchiveTimeStamp(null, null, tspResponse.getTimeStampToken().toCMSSignedData().toASN1Structure());
} else {
ats = new ArchiveTimeStamp(digCalc.getAlgorithmIdentifier(), reducedHashTree, tspResponse.getTimeStampToken().toCMSSignedData().toASN1Structure());
}
return new ERSArchiveTimeStamp(ats, digCalc, rootNodeCalculator);
}
Aggregations