Skip to content

Commit afdb928

Browse files
committed
Improve documentation of PdfPKCS7#getTimeStampDate. Make UNDEFINED_TIMESTAMP_DATE public and move to a separate class
DEVSIX-3509
1 parent c4f8cfa commit afdb928

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

sign/src/main/java/com/itextpdf/signatures/CRLVerifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ public List<VerificationOK> verify(X509Certificate signCert, X509Certificate iss
127127
* @throws GeneralSecurityException
128128
*/
129129
public boolean verify(X509CRL crl, X509Certificate signCert, X509Certificate issuerCert, Date signDate) throws GeneralSecurityException {
130-
if (crl == null || signDate == SignUtils.UNDEFINED_TIMESTAMP_DATE)
130+
if (crl == null || signDate == TimestampConstants.UNDEFINED_TIMESTAMP_DATE) {
131131
return false;
132+
}
132133
// We only check CRLs valid on the signing date for which the issuer matches
133134
if (crl.getIssuerX500Principal().equals(signCert.getIssuerX500Principal()) && signDate.before(crl.getNextUpdate())) {
134135
// the signing certificate may not be revoked

sign/src/main/java/com/itextpdf/signatures/LtvVerifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ public void switchToPreviousRevision() throws IOException, GeneralSecurityExcept
279279
latestRevision = false;
280280
dss = document.getCatalog().getPdfObject().getAsDictionary(PdfName.DSS);
281281
Calendar cal = pkcs7.getTimeStampDate();
282-
if (cal == SignUtils.UNDEFINED_TIMESTAMP_DATE)
282+
if (cal == TimestampConstants.UNDEFINED_TIMESTAMP_DATE) {
283283
cal = pkcs7.getSignDate();
284+
}
284285
// TODO: get date from signature
285286
signDate = cal.getTime();
286287
List<String> names = sgnUtil.getSignatureNames();

sign/src/main/java/com/itextpdf/signatures/PdfPKCS7.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,11 @@ public void setLocation(String location) {
538538
*/
539539
public Calendar getSignDate() {
540540
Calendar dt = getTimeStampDate();
541-
if (dt == SignUtils.UNDEFINED_TIMESTAMP_DATE)
541+
if (dt == TimestampConstants.UNDEFINED_TIMESTAMP_DATE) {
542542
return this.signDate;
543-
else
543+
} else {
544544
return dt;
545+
}
545546
}
546547

547548
/**
@@ -1470,13 +1471,17 @@ public TimeStampToken getTimeStampToken() {
14701471
}
14711472

14721473
/**
1473-
* Gets the timestamp date
1474+
* Gets the timestamp date.
14741475
*
1475-
* @return a date
1476+
* In case the signed document doesn't contain timestamp,
1477+
* {@link TimestampConstants#UNDEFINED_TIMESTAMP_DATE} will be returned.
1478+
*
1479+
* @return the timestamp date
14761480
*/
14771481
public Calendar getTimeStampDate() {
1478-
if (timeStampToken == null)
1479-
return (Calendar) SignUtils.UNDEFINED_TIMESTAMP_DATE;
1482+
if (timeStampToken == null) {
1483+
return (Calendar) TimestampConstants.UNDEFINED_TIMESTAMP_DATE;
1484+
}
14801485
return SignUtils.getTimeStampDate(timeStampToken);
14811486
}
14821487

sign/src/main/java/com/itextpdf/signatures/SignUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ This file is part of the iText (R) project.
115115
import org.bouncycastle.x509.util.StreamParsingException;
116116

117117
final class SignUtils {
118-
static final Object UNDEFINED_TIMESTAMP_DATE = null;
119-
120118
static String getPrivateKeyAlgorithm(PrivateKey pk) {
121119
String algorithm = pk.getAlgorithm();
122120

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.signatures;
24+
25+
public class TimestampConstants {
26+
27+
/**
28+
* The timestamp which is returned in case the signed document doesn't contain timestamp.
29+
* The constant's value is different in Java and .NET.
30+
*/
31+
public static final Object UNDEFINED_TIMESTAMP_DATE = null;
32+
}

0 commit comments

Comments
 (0)