Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Aug 9, 2024
2 parents bc4d3f9 + 4124813 commit 3606f48
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ You should have received a copy of the GNU Affero General Public License
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
Expand All @@ -36,20 +35,47 @@ public class RegexBasedLocationExtractionStrategyTest : ExtendedITextTest {
.CurrentContext.TestDirectory) + "/resources/itext/kernel/parser/RegexBasedLocationExtractionStrategyTest/";

[NUnit.Framework.Test]
public virtual void Test01() {
System.Console.Out.WriteLine(new FileInfo(sourceFolder).FullName);
PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "in01.pdf"));
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy(iText.Commons.Utils.StringUtil.RegexCompile
("\\{\\{Signature\\}\\}"));
public virtual void Test00() {
PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + "in00.pdf"));
// get locations
IList<IPdfTextLocation> locationList = new List<IPdfTextLocation>();
for (int x = 1; x <= pdfDocument.GetNumberOfPages(); x++) {
new PdfCanvasProcessor(extractionStrategy).ProcessPageContent(pdfDocument.GetPage(x));
for (int i = 1; i <= document.GetNumberOfPages(); ++i) {
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("cillum"
);
PdfCanvasProcessor processor = new PdfCanvasProcessor(extractionStrategy);
processor.ProcessPageContent(document.GetPage(i));
foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) {
if (location != null) {
locationList.Add(location);
}
locationList.Add(location);
}
}
// compare
NUnit.Framework.Assert.AreEqual(2, locationList.Count);
IPdfTextLocation loc = locationList[0];
NUnit.Framework.Assert.AreEqual("cillum", loc.GetText());
NUnit.Framework.Assert.AreEqual(64, (int)loc.GetRectangle().GetX());
NUnit.Framework.Assert.AreEqual(732, (int)loc.GetRectangle().GetY());
NUnit.Framework.Assert.AreEqual(30, (int)loc.GetRectangle().GetWidth());
NUnit.Framework.Assert.AreEqual(11, (int)loc.GetRectangle().GetHeight());
IPdfTextLocation loc2 = locationList[1];
NUnit.Framework.Assert.AreEqual(64, (int)loc2.GetRectangle().GetX());
NUnit.Framework.Assert.AreEqual(732, (int)loc2.GetRectangle().GetY());
NUnit.Framework.Assert.AreEqual(30, (int)loc2.GetRectangle().GetWidth());
NUnit.Framework.Assert.AreEqual(11, (int)loc2.GetRectangle().GetHeight());
document.Close();
}

[NUnit.Framework.Test]
public virtual void Test02() {
PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + "in01.pdf"));
// get locations
IList<IPdfTextLocation> locationList = new List<IPdfTextLocation>();
for (int i = 1; i <= document.GetNumberOfPages(); ++i) {
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("\\{\\{Signature\\}\\}"
);
PdfCanvasProcessor processor = new PdfCanvasProcessor(extractionStrategy);
processor.ProcessPageContent(document.GetPage(i));
foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) {
locationList.Add(location);
}
}
// compare
Expand All @@ -60,8 +86,7 @@ public virtual void Test01() {
NUnit.Framework.Assert.AreEqual(375, (int)loc.GetRectangle().GetY());
NUnit.Framework.Assert.AreEqual(55, (int)loc.GetRectangle().GetWidth());
NUnit.Framework.Assert.AreEqual(11, (int)loc.GetRectangle().GetHeight());
// close
pdfDocument.Close();
document.Close();
}

// https://jira.itextsupport.com/browse/DEVSIX-1940
Expand All @@ -70,11 +95,11 @@ public virtual void Test01() {
public virtual void TestLigatureBeforeLigature() {
System.Console.Out.WriteLine(new FileInfo(sourceFolder).FullName);
PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "ligature.pdf"));
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("ca");
// get locations
IList<IPdfTextLocation> locationList = new List<IPdfTextLocation>();
for (int x = 1; x <= pdfDocument.GetNumberOfPages(); x++) {
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("ca");
new PdfCanvasProcessor(extractionStrategy).ProcessPageContent(pdfDocument.GetPage(x));
foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) {
if (location != null) {
Expand All @@ -98,11 +123,11 @@ public virtual void TestLigatureBeforeLigature() {
public virtual void TestLigatureCrossLigature() {
System.Console.Out.WriteLine(new FileInfo(sourceFolder).FullName);
PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "ligature.pdf"));
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("al");
// get locations
IList<IPdfTextLocation> locationList = new List<IPdfTextLocation>();
for (int x = 1; x <= pdfDocument.GetNumberOfPages(); x++) {
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("al");
new PdfCanvasProcessor(extractionStrategy).ProcessPageContent(pdfDocument.GetPage(x));
foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) {
if (location != null) {
Expand All @@ -126,11 +151,11 @@ public virtual void TestLigatureCrossLigature() {
public virtual void TestLigatureInLigature() {
System.Console.Out.WriteLine(new FileInfo(sourceFolder).FullName);
PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "ligature.pdf"));
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("l");
// get locations
IList<IPdfTextLocation> locationList = new List<IPdfTextLocation>();
for (int x = 1; x <= pdfDocument.GetNumberOfPages(); x++) {
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("l");
new PdfCanvasProcessor(extractionStrategy).ProcessPageContent(pdfDocument.GetPage(x));
foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) {
if (location != null) {
Expand All @@ -153,11 +178,11 @@ public virtual void TestLigatureInLigature() {
[NUnit.Framework.Test]
public virtual void TestRotatedText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "rotatedText.pdf"));
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("abc");
// get locations
IList<IPdfTextLocation> locationList = new List<IPdfTextLocation>();
for (int x = 1; x <= pdfDocument.GetNumberOfPages(); x++) {
// build strategy
RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("abc");
new PdfCanvasProcessor(extractionStrategy).ProcessPageContent(pdfDocument.GetPage(x));
foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) {
if (location != null) {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ public virtual void VerifyRsaSha3SignatureTest() {
}

[NUnit.Framework.Test]
public virtual void VerifyRsaPssSha3SignatureTest()
{
if ("BC".Equals(BOUNCY_CASTLE_FACTORY.GetProviderName())) {
VerifyIsoExtensionExample("RSASSA-PSS", "sample-pss-sha3_256.pdf");
} else {
// Signer "RSASSA-PSS not recognised in BCFIPS mode
NUnit.Framework.Assert.Catch(typeof(PdfException), () => VerifyIsoExtensionExample("RSASSA-PSS", "sample-pss-sha3_256.pdf"));
}
public virtual void VerifyRsaPssSha3SignatureTest() {
VerifyIsoExtensionExample("RSASSA-PSS", "sample-pss-sha3_256.pdf");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,8 @@ public virtual void TestRsaWithSha3_512() {
}

[NUnit.Framework.Test]
public virtual void TestRsaSsaPssWithSha3_256()
{
if ("BC".Equals(BOUNCY_CASTLE_FACTORY.GetProviderName())) {
DoRoundTrip("rsa", DigestAlgorithms.SHA3_256, "RSASSA-PSS", new DerObjectIdentifier(SecurityIDs.ID_RSASSA_PSS));
} else {
// Signer RSASSA-PSS not recognised in BCFIPS mode
NUnit.Framework.Assert.Catch(typeof(PdfException), () => DoRoundTrip("rsa", DigestAlgorithms.SHA3_256, "RSASSA-PSS", new DerObjectIdentifier(SecurityIDs.ID_RSASSA_PSS)));
}
public virtual void TestRsaSsaPssWithSha3_256() {
DoRoundTrip("rsa", DigestAlgorithms.SHA3_256, "RSASSA-PSS", new DerObjectIdentifier(SecurityIDs.ID_RSASSA_PSS));
}

[NUnit.Framework.Test]
Expand Down
Loading

0 comments on commit 3606f48

Please sign in to comment.