Skip to content

Commit fe065da

Browse files
committed
Fix javadoc issues
DEVSIX-8395
1 parent ed5c15d commit fe065da

File tree

2 files changed

+99
-81
lines changed

2 files changed

+99
-81
lines changed

src/main/java/com/itextpdf/samples/SignatureTestHelper.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.itextpdf.signatures.validation.report.ReportItem;
1414
import com.itextpdf.signatures.validation.report.ValidationReport;
1515
import com.itextpdf.test.ITextTest;
16+
1617
import org.bouncycastle.asn1.tsp.TSTInfo;
1718
import org.bouncycastle.jce.provider.BouncyCastleProvider;
1819

@@ -34,7 +35,7 @@
3435
* length, and as a result the strength, of encryption keys. Be aware that in
3536
* this sample by using {@link ITextTest#removeCryptographyRestrictions()} we
3637
* remove cryptography restrictions via reflection for testing purposes.
37-
* <br/>
38+
* <br>
3839
* For more conventional way of solving this problem you need to replace the
3940
* default security JARs in your Java installation with the Java Cryptography
4041
* Extension (JCE) Unlimited Strength Jurisdiction Policy Files. These JARs
@@ -48,7 +49,8 @@ public class SignatureTestHelper {
4849

4950
private String errorMessage;
5051

51-
public String checkForErrors(String outFile, String cmpFile, String destPath, Map<Integer, List<Rectangle>> ignoredAreas)
52+
public String checkForErrors(String outFile, String cmpFile, String destPath,
53+
Map<Integer, List<Rectangle>> ignoredAreas)
5254
throws InterruptedException, IOException, GeneralSecurityException {
5355
errorMessage = null;
5456

@@ -72,14 +74,28 @@ public String checkForErrors(String outFile, String cmpFile, String destPath, Ma
7274

7375
/**
7476
* In this method we add trusted certificates to the IssuingCertificateRetriever.
75-
* If document signatures certificates doesn't contain certificates that are added in this method, verification will fail.
77+
* If document signatures certificates doesn't contain certificates that are added in this method, verification will
78+
* fail.
7679
* NOTE: Override this method to add additional certificates.
80+
*
81+
* @param certificateRetriever certificate retriever
82+
* @param certs certificates
83+
*
84+
* @throws CertificateException cert retriever problem occurred
85+
* @throws IOException input/output file exception
7786
*/
7887
protected void addTrustedCertificates(IssuingCertificateRetriever certificateRetriever, List<Certificate> certs)
7988
throws CertificateException, IOException {
8089
certificateRetriever.addTrustedCertificates(certs);
8190
}
8291

92+
protected void compareSignatures(String outFile, String cmpFile) throws IOException {
93+
SignedDocumentInfo outInfo = collectInfo(outFile);
94+
SignedDocumentInfo cmpInfo = collectInfo(cmpFile);
95+
96+
compareSignedDocumentsInfo(outInfo, cmpInfo);
97+
}
98+
8399
private void verifySignaturesForDocument(String documentPath) throws IOException, CertificateException {
84100
BouncyCastleProvider provider = new BouncyCastleProvider();
85101
Security.addProvider(provider);
@@ -114,13 +130,6 @@ private void verifySignaturesForDocument(String documentPath) throws IOException
114130

115131
}
116132

117-
protected void compareSignatures(String outFile, String cmpFile) throws IOException {
118-
SignedDocumentInfo outInfo = collectInfo(outFile);
119-
SignedDocumentInfo cmpInfo = collectInfo(cmpFile);
120-
121-
compareSignedDocumentsInfo(outInfo, cmpInfo);
122-
}
123-
124133
private SignedDocumentInfo collectInfo(String documentPath) throws IOException {
125134
SignedDocumentInfo docInfo = new SignedDocumentInfo();
126135

@@ -356,19 +365,23 @@ private void compareSignedDocumentsInfo(SignedDocumentInfo outInfo, SignedDocume
356365
CertificateInfo cmpCert = cmpSig.getCertificateInfos().get(j);
357366

358367
if (!outCert.getIssuer().equals(cmpCert.getIssuer())) {
359-
addComparisonError("Certificate issuer", outCert.getIssuer().toString(), cmpCert.getIssuer().toString());
368+
addComparisonError("Certificate issuer", outCert.getIssuer().toString(),
369+
cmpCert.getIssuer().toString());
360370
}
361371

362372
if (!outCert.getSubject().equals(cmpCert.getSubject())) {
363-
addComparisonError("Certificate subject", outCert.getSubject().toString(), cmpCert.getSubject().toString());
373+
addComparisonError("Certificate subject", outCert.getSubject().toString(),
374+
cmpCert.getSubject().toString());
364375
}
365376

366377
if (!outCert.getValidFrom().equals(cmpCert.getValidFrom())) {
367-
addComparisonError("Date \"valid from\"", outCert.getValidFrom().toString(), cmpCert.getValidFrom().toString());
378+
addComparisonError("Date \"valid from\"", outCert.getValidFrom().toString(),
379+
cmpCert.getValidFrom().toString());
368380
}
369381

370382
if (!outCert.getValidTo().equals(cmpCert.getValidTo())) {
371-
addComparisonError("Date \"valid to\"", outCert.getValidTo().toString(), cmpCert.getValidTo().toString());
383+
addComparisonError("Date \"valid to\"", outCert.getValidTo().toString(),
384+
cmpCert.getValidTo().toString());
372385
}
373386
}
374387

@@ -391,10 +404,11 @@ private void addComparisonError(String comparisonCategory, String newVal, String
391404

392405
private void addError(String error) {
393406
if (error != null && error.length() > 0) {
394-
if (errorMessage == null)
407+
if (errorMessage == null) {
395408
errorMessage = "";
396-
else
409+
} else {
397410
errorMessage += "\n";
411+
}
398412

399413
errorMessage += error;
400414
}

src/main/java/com/itextpdf/signatures/chapter01/PasswordMD.java

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,40 @@
1212
* Class to demonstrate the use of message digests for passwords.
1313
*/
1414
public class PasswordMD {
15-
16-
/** The digest of a password. */
15+
16+
/**
17+
* The digest of a password.
18+
*/
1719
protected byte[] digest;
18-
19-
/** The algorithm that will create the digest. */
20+
21+
/**
22+
* The algorithm that will create the digest.
23+
*/
2024
protected MessageDigest md;
21-
25+
2226
/**
2327
* Instantiates a new password ,essage digest.
2428
*
25-
* @param password the password
29+
* @param password the password
2630
* @param algorithm the algorithm
27-
* @param provider the provider
31+
* @param provider the provider
32+
*
2833
* @throws GeneralSecurityException the general security exception
2934
*/
3035
protected PasswordMD(String password, String algorithm, String provider)
31-
throws GeneralSecurityException {
32-
if (provider == null)
36+
throws GeneralSecurityException {
37+
if (provider == null) {
3338
md = MessageDigest.getInstance(algorithm);
34-
else
39+
} else {
3540
md = MessageDigest.getInstance(algorithm, provider);
41+
}
3642
digest = md.digest(password.getBytes());
3743
}
38-
39-
/**
40-
* Gets the size of the digest in bytes.
41-
*
42-
* @return the digest size in bytes
43-
*/
44-
public int getDigestSize() {
45-
return digest.length;
46-
}
47-
48-
/**
49-
* Gets the digest as a hexadecimal string.
50-
*
51-
* @return the digest as a hexadecimal string
52-
*/
53-
public String getDigestAsHexString() {
54-
return new BigInteger(1, digest).toString(16);
55-
}
56-
57-
/**
58-
* Check a password.
59-
*
60-
* @param password the password
61-
* @return true, if successful
62-
*/
63-
public boolean checkPassword(String password) {
64-
return MessageDigest.isEqual(digest, md.digest(password.getBytes()));
65-
}
66-
44+
6745
/**
6846
* Show test.
6947
*
7048
* @param algorithm the algorithm
71-
* @throws GeneralSecurityException the general security exception
7249
*/
7350
public static void showTestDefault(String algorithm) {
7451
try {
@@ -79,20 +56,18 @@ public static void showTestDefault(String algorithm) {
7956
System.out.println("Is the password 'password'? "
8057
+ app.checkPassword("password"));
8158
System.out.println("Is the password 'secret'? "
82-
+ app.checkPassword("secret"));
59+
+ app.checkPassword("secret"));
8360
} catch (NoSuchAlgorithmException e) {
8461
System.out.println(e.getMessage());
8562
} catch (GeneralSecurityException e) {
8663
System.out.println(e.getMessage());
8764
}
8865
}
8966

90-
9167
/**
9268
* Show test.
9369
*
9470
* @param algorithm the algorithm
95-
* @throws GeneralSecurityException the general security exception
9671
*/
9772
public static void showTestBC(String algorithm) {
9873
try {
@@ -103,39 +78,68 @@ public static void showTestBC(String algorithm) {
10378
System.out.println("Is the password 'password'? "
10479
+ app.checkPassword("password"));
10580
System.out.println("Is the password 'secret'? "
106-
+ app.checkPassword("secret"));
81+
+ app.checkPassword("secret"));
10782
} catch (NoSuchAlgorithmException e) {
10883
System.out.println(e.getMessage());
10984
} catch (GeneralSecurityException e) {
11085
System.out.println(e.getMessage());
11186
}
11287
}
113-
88+
11489
/**
11590
* The main method.
11691
*
11792
* @param args the arguments
11893
*/
11994
public static void main(String[] args) {
120-
showTestDefault("MD2");
121-
showTestDefault("MD5");
122-
showTestDefault("SHA-1");
123-
showTestDefault("SHA-224");
124-
showTestDefault("SHA-256");
125-
showTestDefault("SHA-384");
126-
showTestDefault("SHA-512");
127-
showTestDefault("RIPEMD128");
128-
showTestDefault("RIPEMD160");
129-
showTestDefault("RIPEMD256");
130-
Security.addProvider(new BouncyCastleProvider());
131-
showTestBC("MD5");
132-
showTestBC("SHA-1");
133-
showTestBC("SHA-224");
134-
showTestBC("SHA-256");
135-
showTestBC("SHA-384");
136-
showTestBC("SHA-512");
137-
showTestBC("RIPEMD128");
138-
showTestBC("RIPEMD160");
139-
showTestBC("RIPEMD256");
95+
showTestDefault("MD2");
96+
showTestDefault("MD5");
97+
showTestDefault("SHA-1");
98+
showTestDefault("SHA-224");
99+
showTestDefault("SHA-256");
100+
showTestDefault("SHA-384");
101+
showTestDefault("SHA-512");
102+
showTestDefault("RIPEMD128");
103+
showTestDefault("RIPEMD160");
104+
showTestDefault("RIPEMD256");
105+
Security.addProvider(new BouncyCastleProvider());
106+
showTestBC("MD5");
107+
showTestBC("SHA-1");
108+
showTestBC("SHA-224");
109+
showTestBC("SHA-256");
110+
showTestBC("SHA-384");
111+
showTestBC("SHA-512");
112+
showTestBC("RIPEMD128");
113+
showTestBC("RIPEMD160");
114+
showTestBC("RIPEMD256");
115+
}
116+
117+
/**
118+
* Gets the size of the digest in bytes.
119+
*
120+
* @return the digest size in bytes
121+
*/
122+
public int getDigestSize() {
123+
return digest.length;
124+
}
125+
126+
/**
127+
* Gets the digest as a hexadecimal string.
128+
*
129+
* @return the digest as a hexadecimal string
130+
*/
131+
public String getDigestAsHexString() {
132+
return new BigInteger(1, digest).toString(16);
133+
}
134+
135+
/**
136+
* Check a password.
137+
*
138+
* @param password the password
139+
*
140+
* @return true, if successful
141+
*/
142+
public boolean checkPassword(String password) {
143+
return MessageDigest.isEqual(digest, md.digest(password.getBytes()));
140144
}
141145
}

0 commit comments

Comments
 (0)