Skip to content

Commit edbf657

Browse files
committed
Add tests for DigestAlgorithms and EncryptionAlgorithms in sign module
DEVSIX-5840 Autoported commit. Original commit hash: [9da3a434] Manual files: sign/src/test/java/com/itextpdf/signatures/DigestAlgorithmsManualTest.java sign/src/test/java/com/itextpdf/signatures/EncryptionAlgorithmsManualTest.java
1 parent 4847941 commit edbf657

File tree

4 files changed

+170
-1
lines changed

4 files changed

+170
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2021 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
44+
using System;
45+
using System.IO;
46+
using iText.Test;
47+
48+
namespace iText.Signatures
49+
{
50+
public class DigestAlgorithmsManualTest : ExtendedITextTest
51+
{
52+
[NUnit.Framework.Test]
53+
public virtual void DigestSHA1SunPKCS11Test()
54+
{
55+
Stream data = new MemoryStream(new byte[] {13, 16, 20, 0, 10});
56+
byte[] hash = DigestAlgorithms.Digest(data, DigestAlgorithms.SHA1);
57+
byte[] expected = {15, 20, 1, 9, 150, 49, 219, 191, 211, 193, 53, 186, 76, 185, 102, 188, 78, 205, 156, 50};
58+
NUnit.Framework.Assert.AreEqual(expected, hash);
59+
}
60+
61+
[NUnit.Framework.Test]
62+
public virtual void DigestSHA256SUNTest()
63+
{
64+
Stream data = new MemoryStream(new byte[] {13, 16, 20, 0, 10});
65+
byte[] hash = DigestAlgorithms.Digest(data, DigestAlgorithms.SHA256);
66+
foreach (byte b in hash)
67+
{
68+
Console.Out.Write(b + ", ");
69+
}
70+
71+
byte[] expected =
72+
{
73+
19, 172, 172, 211, 220, 121, 241, 238, 167, 97, 239, 51, 81, 119, 214, 197, 225, 121, 169, 174, 211,
74+
119, 61, 92, 110, 157, 105, 4, 97, 12, 127, 194
75+
};
76+
NUnit.Framework.Assert.AreEqual(expected, hash);
77+
}
78+
}
79+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2021 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+
24+
using System;
25+
using iText.Test;
26+
27+
namespace iText.Signatures
28+
{
29+
public class EncryptionAlgorithmsManualTest : ExtendedITextTest
30+
{
31+
[NUnit.Framework.Test]
32+
public virtual void GetAlgorithmNullTest()
33+
{
34+
NUnit.Framework.Assert.Catch(typeof(ArgumentNullException),
35+
() => EncryptionAlgorithms.GetAlgorithm(null));
36+
}
37+
}
38+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2021 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+
using iText.Test;
24+
25+
namespace iText.Signatures {
26+
public class EncryptionAlgorithmsTest : ExtendedITextTest {
27+
[NUnit.Framework.Test]
28+
public virtual void GetAlgorithmRSATest() {
29+
NUnit.Framework.Assert.AreEqual("RSA", EncryptionAlgorithms.GetAlgorithm("1.2.840.113549.1.1.1"));
30+
}
31+
32+
[NUnit.Framework.Test]
33+
public virtual void GetAlgorithmECDSATest() {
34+
NUnit.Framework.Assert.AreEqual("ECDSA", EncryptionAlgorithms.GetAlgorithm("1.2.840.10045.2.1"));
35+
}
36+
37+
[NUnit.Framework.Test]
38+
public virtual void GetAlgorithmEmptyTest() {
39+
NUnit.Framework.Assert.AreEqual("", EncryptionAlgorithms.GetAlgorithm(""));
40+
}
41+
42+
[NUnit.Framework.Test]
43+
public virtual void GetAlgorithmEmptySpaceTest() {
44+
NUnit.Framework.Assert.AreEqual(" ", EncryptionAlgorithms.GetAlgorithm(" "));
45+
}
46+
47+
[NUnit.Framework.Test]
48+
public virtual void GetAlgorithmUndefinedTest() {
49+
NUnit.Framework.Assert.AreEqual("undefined", EncryptionAlgorithms.GetAlgorithm("undefined"));
50+
}
51+
}
52+
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24d931ff6031ae8e34b71bfd9ca2e6fd8ec2201b
1+
9da3a4342a9ec9a6c9addfa2c344785b1cdb316a

0 commit comments

Comments
 (0)