From 3e7b63ab25a53b47942f8c1369ee82c0ef6f201b Mon Sep 17 00:00:00 2001 From: Angelina Pavlovets Date: Mon, 7 Oct 2024 14:23:21 +0000 Subject: [PATCH 1/2] Refactor com.itextpdf.kernel.events mechanism DEVSIX-5041 Autoported commit. Original commit hash: [5b9f0e980] --- .../itext/kernel/pdf/PdfStampingTest.cs | 6 +- .../pdf/event/PdfDocumentEventHandlingTest.cs | 101 +++++++++++++++ .../itext/layout/DefaultLayoutTest.cs | 14 +-- .../itext/pdfa/PdfAPageTest.cs | 6 +- .../cmp_emptySignatureAppearance.pdf | Bin 18900 -> 18900 bytes .../cmp_signatureFieldAppearanceTest.pdf | Bin 28100 -> 28148 bytes .../sign/SignatureAppearanceTest/test.pem | 117 +++++++++++------- .../itext/commons/actions/EventManager.cs | 2 +- .../itext.kernel/itext/kernel/events/Event.cs | 43 ------- .../itext/kernel/events/EventDispatcher.cs | 78 ------------ .../itext/kernel/events/IEventDispatcher.cs | 81 ------------ .../itext/kernel/events/IEventHandler.cs | 38 ------ .../mac/StandaloneMacIntegrityProtector.cs | 10 +- .../itext/kernel/pdf/OcgPropertiesCopier.cs | 4 +- .../itext/kernel/pdf/PageFlushingHelper.cs | 2 +- .../itext/kernel/pdf/PdfDocument.cs | 71 +++++++---- .../itext.kernel/itext/kernel/pdf/PdfPage.cs | 2 +- .../itext/kernel/pdf/PdfWriter.cs | 4 +- .../pdf/event/AbstractPdfDocumentEvent.cs | 85 +++++++++++++ .../event/AbstractPdfDocumentEventHandler.cs | 102 +++++++++++++++ .../{events => pdf/event}/PdfDocumentEvent.cs | 18 +-- .../mac/SignatureContainerGenerationEvent.cs | 4 +- .../mac/SignatureDocumentClosingEvent.cs | 4 +- .../mac/SignatureMacIntegrityProtector.cs | 10 +- port-hash | 2 +- 25 files changed, 444 insertions(+), 360 deletions(-) create mode 100644 itext.tests/itext.kernel.tests/itext/kernel/pdf/event/PdfDocumentEventHandlingTest.cs delete mode 100644 itext/itext.kernel/itext/kernel/events/Event.cs delete mode 100644 itext/itext.kernel/itext/kernel/events/EventDispatcher.cs delete mode 100644 itext/itext.kernel/itext/kernel/events/IEventDispatcher.cs delete mode 100644 itext/itext.kernel/itext/kernel/events/IEventHandler.cs create mode 100644 itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEvent.cs create mode 100644 itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEventHandler.cs rename itext/itext.kernel/itext/kernel/{events => pdf/event}/PdfDocumentEvent.cs (82%) diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs index 4f5a911683..390c9ab661 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs @@ -24,12 +24,12 @@ You should have received a copy of the GNU Affero General Public License using System.IO; using iText.Commons.Utils; using iText.IO.Source; -using iText.Kernel.Events; using iText.Kernel.Font; using iText.Kernel.Logs; using iText.Kernel.Pdf.Canvas; using iText.Kernel.Pdf.Canvas.Parser; using iText.Kernel.Pdf.Canvas.Parser.Listener; +using iText.Kernel.Pdf.Event; using iText.Kernel.Utils; using iText.Test; using iText.Test.Attributes; @@ -1239,8 +1239,8 @@ internal static void VerifyPdfPagesCount(PdfObject root) { //\endcond //\cond DO_NOT_DOCUMENT - internal class WatermarkEventHandler : iText.Kernel.Events.IEventHandler { - public virtual void HandleEvent(Event @event) { + internal class WatermarkEventHandler : AbstractPdfDocumentEventHandler { + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { PdfDocumentEvent pdfEvent = (PdfDocumentEvent)@event; PdfPage page = pdfEvent.GetPage(); PdfCanvas pdfCanvas = new PdfCanvas(page); diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/event/PdfDocumentEventHandlingTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/event/PdfDocumentEventHandlingTest.cs new file mode 100644 index 0000000000..07e8de34fd --- /dev/null +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/event/PdfDocumentEventHandlingTest.cs @@ -0,0 +1,101 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System.IO; +using iText.Commons.Actions; +using iText.Kernel.Pdf; +using iText.Test; + +namespace iText.Kernel.Pdf.Event { + [NUnit.Framework.Category("UnitTest")] + public class PdfDocumentEventHandlingTest : ExtendedITextTest { + [NUnit.Framework.Test] + public virtual void SimplePdfDocumentEventTest() { + using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + document.AddEventHandler(PdfDocumentEvent.INSERT_PAGE, insertPageHandler); + document.AddNewPage(); + document.AddNewPage(); + NUnit.Framework.Assert.AreEqual(2, insertPageHandler.GetInsertedPagesCounter()); + } + } + + [NUnit.Framework.Test] + public virtual void GloballyRegisteredAbstractPdfDocumentEventHandlerTest() { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + insertPageHandler.AddType(PdfDocumentEvent.INSERT_PAGE); + EventManager.GetInstance().Register(insertPageHandler); + using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { + document.AddNewPage(); + } + // Events with specified PDF document are ignored. + NUnit.Framework.Assert.AreEqual(0, insertPageHandler.GetInsertedPagesCounter()); + EventManager.GetInstance().Unregister(insertPageHandler); + } + + [NUnit.Framework.Test] + public virtual void EventHandlerPerSeveralDocumentsTest() { + using (PdfDocument document1 = new PdfDocument(new PdfWriter(new MemoryStream()))) { + using (PdfDocument document2 = new PdfDocument(new PdfWriter(new MemoryStream()))) { + using (PdfDocument document3 = new PdfDocument(new PdfWriter(new MemoryStream()))) { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + document1.AddEventHandler(PdfDocumentEvent.INSERT_PAGE, insertPageHandler); + document2.AddEventHandler(PdfDocumentEvent.INSERT_PAGE, insertPageHandler); + document1.AddNewPage(); + document2.AddNewPage(); + document3.AddNewPage(); + NUnit.Framework.Assert.AreEqual(2, insertPageHandler.GetInsertedPagesCounter()); + document2.RemoveEventHandler(insertPageHandler); + document2.AddNewPage(); + NUnit.Framework.Assert.AreEqual(2, insertPageHandler.GetInsertedPagesCounter()); + } + } + } + } + + [NUnit.Framework.Test] + public virtual void NoDocumentSpecifiedForEventButHandlerIsGloballyRegisteredTest() { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + insertPageHandler.AddType(PdfDocumentEvent.INSERT_PAGE); + EventManager.GetInstance().Register(insertPageHandler); + EventManager.GetInstance().OnEvent(new PdfDocumentEvent(PdfDocumentEvent.INSERT_PAGE)); + EventManager.GetInstance().Unregister(insertPageHandler); + NUnit.Framework.Assert.AreEqual(1, insertPageHandler.GetInsertedPagesCounter()); + } + + private class InsertPageHandler : AbstractPdfDocumentEventHandler { + private int insertedPagesCounter = 0; + + public virtual int GetInsertedPagesCounter() { + return insertedPagesCounter; + } + + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { + insertedPagesCounter++; + } + } + } +} diff --git a/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs b/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs index a2d440518a..23d3c442ac 100644 --- a/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs +++ b/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs @@ -24,11 +24,11 @@ You should have received a copy of the GNU Affero General Public License using System.Collections.Generic; using System.IO; using iText.Kernel.Colors; -using iText.Kernel.Events; using iText.Kernel.Font; using iText.Kernel.Geom; using iText.Kernel.Pdf; using iText.Kernel.Pdf.Canvas; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Layer; using iText.Kernel.Utils; using iText.Layout.Borders; @@ -241,8 +241,8 @@ public virtual void CloseEmptyDocumentWithRemovingPageEventOnAddingPageTest() { , "diff")); } - private class ParagraphAdderHandler : iText.Kernel.Events.IEventHandler { - public virtual void HandleEvent(Event @event) { + private class ParagraphAdderHandler : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { PdfDocumentEvent docEvent = (PdfDocumentEvent)@event; PdfPage page = docEvent.GetPage(); PdfDocument pdfDoc = ((PdfDocumentEvent)@event).GetDocument(); @@ -257,12 +257,12 @@ public virtual void HandleEvent(Event @event) { } } - private class PageRemoverHandler : iText.Kernel.Events.IEventHandler { - public virtual void HandleEvent(Event @event) { + private class PageRemoverHandler : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { PdfDocumentEvent docEvent = (PdfDocumentEvent)@event; PdfPage page = docEvent.GetPage(); - PdfDocument pdfDoc = ((PdfDocumentEvent)@event).GetDocument(); - pdfDoc.RemovePage(1); + PdfDocument pdfDoc = @event.GetDocument(); + pdfDoc.RemovePage(page); } } } diff --git a/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs b/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs index 484c3d62ce..8e2c77171d 100644 --- a/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs +++ b/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs @@ -22,9 +22,9 @@ You should have received a copy of the GNU Affero General Public License */ using System; using iText.Commons.Utils; -using iText.Kernel.Events; using iText.Kernel.Geom; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; using iText.Layout; using iText.Layout.Element; using iText.Pdfa.Logs; @@ -174,7 +174,7 @@ public virtual void CheckFlushingOfCheckedPage() { //\cond DO_NOT_DOCUMENT // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) - internal class EndPageEventHandler : iText.Kernel.Events.IEventHandler { + internal class EndPageEventHandler : AbstractPdfDocumentEventHandler { private int counter = 0; //\cond DO_NOT_DOCUMENT @@ -186,7 +186,7 @@ public virtual int GetCounter() { return counter; } - public virtual void HandleEvent(Event @event) { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { counter++; } } diff --git a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_emptySignatureAppearance.pdf b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_emptySignatureAppearance.pdf index e5a2cb45f3d14b40ad17143de4365fbce5a2534e..34d21d1fd0eaefd1c81a4a6c0a2efe3a3f8ba7b0 100644 GIT binary patch literal 18900 zcmeI4&5xbeUB^w7MH!+BiDv(7tlC8JJ?}4ISsgoeV>K@$&*VjNEOcJoiJZA+<~mJa z!x9Ox0I@-;1VUoLCaMsNvSmY|NI^v`k!Y!4U-$#~oM&b{j_p)U8mV18GrGQap65L0 z<@@{nzTe;P%IBQldFjTB@{-v)|D*r<_}{j|B&KzKckA-y)zuF-?N&Ot+os!Ml7^SF z%1ugpGu@efo}bmV^}!~U&CP?pzHo8=s~v2PrpsCcC8BS_iKtR=CIr{Ls6q-aRGRO) ze%#7sp|~!!6kMSV&p0uj5lmEQVdnc*@KNNa_9*8by~%TrI?DN7`IyE-qjxoarC^kk z5gwbBr001A-I)jdh{#CVT1Iy~q>M6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AppearanceTest/cmp_signatureFieldAppearanceTest.pdf b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf index 3b4b50654a735616ae8891015b8ea1725360419a..0963394d15a8f6835bf773e42f8b57a2b06b3d5a 100644 GIT binary patch delta 4788 zcmc(jTd3t#9mhS*h|OWJG*bwfQW(K-bp6(ET}9%|)MzNp2%5bZwXXG0P&z?R?M8y4 zpqjQ2MBqy=LQr^ui7td#5EWTLV2IH}FA;`dFI|W}|9xi08H&M&u-WXh_x|73<@de) z=Eu)({q^~+FS{#)mAAcrefple&V1s~tvL=8OtvKjmr|I~bR#AjTTHShhpBs?^~?|M zIUHTx{M0O)PaAVFMvdhbyS&60S?_Eg+NVa>@7cOx<*f56W~ecZanyU`OyRo^*}LFl zicZDy3|Z!}cV11C_{#asbsC+M$i#vV5^az$f(Gwxm`vJj=D^(5GO|&oxA$ItY+k-d zGLzF>x_OHJ*R_wKuQRhegZt~SXUIvYB>gxW^( zwbYig_EaS`m2OA3EmT)x?r}8rCf4C&C?jX*d`aq(2G_H1F?P19u%~kd6Kan&lv+xV zT2k|2l;Ec2udJ$NmsV$%uFbk=v*|3?k72FUW*NVaI=YCrMME+@*JMJJo=pn2 zYB5T^xN&HYHpOmQV%eiKowjA;TCXn3P#2qH&7y^BN9sQk&$Pp9nc^~!GrlI)IYMEN zfQ34qxH7)6<;A(Cxp?i(WFr)%#o2SN&GeZ)+t6khZ26d_H9x1!S!5R1T=hxEtP*;3 zobRqhW@Ma&2)Q(|VykI(Iv+fR3q=Rh%LO*YoL5z1h81Ajz>A`ZH@p!RZlv!4htFZ0 z1l|l$`3Ase9n;9Hnp$u*q!GoH8G5sfJb;~?gB{3G?o1qEgT?jfnR|(?l~GomU9m3L zp*2(YK5OMEv-eg&?m50O0mkBq6J|PQW{n?wxC`eQ%z+>SlZ~TlZdt%gL3@C`ybOhz zKxW}HJhfxtb&!YIHWOO#98hT5?c6(Y;dtk`a8w~m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R~oZu=Yi?Zy3Allows an access to the instance of EventManager. + /// Allows access to the instance of EventManager. /// the instance of the class public static iText.Commons.Actions.EventManager GetInstance() { return INSTANCE; diff --git a/itext/itext.kernel/itext/kernel/events/Event.cs b/itext/itext.kernel/itext/kernel/events/Event.cs deleted file mode 100644 index 033040c93d..0000000000 --- a/itext/itext.kernel/itext/kernel/events/Event.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -using System; - -namespace iText.Kernel.Events { - /// Describes abstract event. - public class Event { - /// A type of event. - protected internal String type; - - /// Creates an event of the specified type. - /// type of event - public Event(String type) { - this.type = type; - } - - /// Returns the type of this event. - /// type of this event - public virtual String GetEventType() { - return type; - } - } -} diff --git a/itext/itext.kernel/itext/kernel/events/EventDispatcher.cs b/itext/itext.kernel/itext/kernel/events/EventDispatcher.cs deleted file mode 100644 index ebea2532ee..0000000000 --- a/itext/itext.kernel/itext/kernel/events/EventDispatcher.cs +++ /dev/null @@ -1,78 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -using System; -using System.Collections.Generic; - -namespace iText.Kernel.Events { - /// - /// IEventDispatcher implementation that forwards Events to registered - /// - /// implementations. - /// - public class EventDispatcher : IEventDispatcher { - protected internal IDictionary> eventHandlers = new Dictionary - >(); - - public virtual void AddEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - RemoveEventHandler(type, handler); - IList handlers = eventHandlers.Get(type); - if (handlers == null) { - handlers = new List(); - eventHandlers.Put(type, handlers); - } - handlers.Add(handler); - } - - public virtual void DispatchEvent(Event @event) { - DispatchEvent(@event, false); - } - - public virtual void DispatchEvent(Event @event, bool delayed) { - IList handlers = eventHandlers.Get(@event.GetEventType()); - if (handlers != null) { - foreach (iText.Kernel.Events.IEventHandler handler in handlers) { - handler.HandleEvent(@event); - } - } - } - - public virtual bool HasEventHandler(String type) { - return eventHandlers.ContainsKey(type); - } - - public virtual void RemoveEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - IList handlers = eventHandlers.Get(type); - if (handlers == null) { - return; - } - handlers.Remove(handler); - if (handlers.Count == 0) { - eventHandlers.JRemove(type); - } - } - - public virtual void RemoveAllHandlers() { - eventHandlers.Clear(); - } - } -} diff --git a/itext/itext.kernel/itext/kernel/events/IEventDispatcher.cs b/itext/itext.kernel/itext/kernel/events/IEventDispatcher.cs deleted file mode 100644 index bc8bc3911f..0000000000 --- a/itext/itext.kernel/itext/kernel/events/IEventDispatcher.cs +++ /dev/null @@ -1,81 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -using System; - -namespace iText.Kernel.Events { - /// Event dispatcher interface. - public interface IEventDispatcher { - /// Adds new event handler. - /// a type of event to be handled - /// event handler - void AddEventHandler(String type, iText.Kernel.Events.IEventHandler handler); - - /// Dispatches an event. - /// - /// the - /// - /// to be dispatched - /// - void DispatchEvent(Event @event); - - /// Dispatches a delayed event. - /// - /// Dispatches a delayed event. - /// Sometimes event cannot be handled immediately because event handler has not been set yet. - /// In this case event is placed into event ques of dispatcher and is waiting until handler is assigned. - /// - /// - /// the - /// - /// to be dispatched - /// - /// - /// flag whether - /// - /// delayed or not - /// - void DispatchEvent(Event @event, bool delayed); - - /// Checks if event dispatcher as an event handler assigned for a certain event type. - /// - /// a type of the - /// - /// - /// true if event dispatcher as an event handler assigned for a certain event type - bool HasEventHandler(String type); - - /// Removes event handler. - /// - /// a type of the - /// - /// - /// - /// event handler - /// - /// - void RemoveEventHandler(String type, iText.Kernel.Events.IEventHandler handler); - - /// Remove all event handlers. - void RemoveAllHandlers(); - } -} diff --git a/itext/itext.kernel/itext/kernel/events/IEventHandler.cs b/itext/itext.kernel/itext/kernel/events/IEventHandler.cs deleted file mode 100644 index e7b21b85fc..0000000000 --- a/itext/itext.kernel/itext/kernel/events/IEventHandler.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -namespace iText.Kernel.Events { - /// Interface for handling events. - /// - /// Interface for handling events. EventHandlers are added to the - /// . - /// - public interface IEventHandler { - /// Hook for handling events. - /// - /// Hook for handling events. Implementations can access the PdfDocument instance - /// associated to the specified Event or, if available, the PdfPage instance. - /// - /// the Event that needs to be processed - void HandleEvent(Event @event); - } -} diff --git a/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs b/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs index f2ded9ad2e..8b46685873 100644 --- a/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs +++ b/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs @@ -24,9 +24,9 @@ You should have received a copy of the GNU Affero General Public License using System.IO; using iText.Commons.Bouncycastle.Security; using iText.IO.Source; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; namespace iText.Kernel.Mac { //\cond DO_NOT_DOCUMENT @@ -108,8 +108,8 @@ private MemoryStream GetDocumentByteArrayOutputStream() { return ((MemoryStream)document.GetWriter().GetOutputStream()); } - private sealed class StandaloneMacPdfObjectAdder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class StandaloneMacPdfObjectAdder : AbstractPdfDocumentEventHandler { + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { this._enclosing.macPdfObject = new MacPdfObject(this._enclosing.GetContainerSizeEstimate()); this._enclosing.document.GetTrailer().Put(PdfName.AuthCode, this._enclosing.macPdfObject.GetPdfObject()); } @@ -121,8 +121,8 @@ internal StandaloneMacPdfObjectAdder(StandaloneMacIntegrityProtector _enclosing) private readonly StandaloneMacIntegrityProtector _enclosing; } - private sealed class StandaloneMacContainerEmbedder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class StandaloneMacContainerEmbedder : AbstractPdfDocumentEventHandler { + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { try { this._enclosing.EmbedMacContainerInTrailer(); } diff --git a/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs b/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs index 2138e88d47..7276b16dda 100644 --- a/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs +++ b/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs @@ -71,11 +71,12 @@ public static void CopyOCGProperties(PdfDocument sourceDocument, PdfDocument des } } +//\cond DO_NOT_DOCUMENT /// Get all OCGs from a given page annotations/xobjects/resources, including ones already stored in catalog /// /// where to search for OCGs. /// set of indirect references pointing to found OCGs. - public static ICollection GetOCGsFromPage(PdfPage page) { + internal static ICollection GetOCGsFromPage(PdfPage page) { //Using linked hash set for elements order consistency (e.g. in tests) ICollection ocgs = new LinkedHashSet(); IList annotations = page.GetAnnotations(); @@ -88,6 +89,7 @@ public static ICollection GetOCGsFromPage(PdfPage page) { new HashSet()); return ocgs; } +//\endcond private static ICollection GetAllUsedNonFlushedOCGs(IDictionary page2page , PdfDictionary toOcProperties) { diff --git a/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs b/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs index 5b84b48aea..2fe775a544 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs @@ -23,8 +23,8 @@ You should have received a copy of the GNU Affero General Public License using System; using System.Collections.Generic; using iText.Commons.Utils; -using iText.Kernel.Events; using iText.Kernel.Exceptions; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Layer; namespace iText.Kernel.Pdf { diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs b/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs index 8e135859e1..af293ebf9d 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs @@ -33,7 +33,6 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Actions.Data; using iText.Kernel.Actions.Events; using iText.Kernel.Colors; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Font; using iText.Kernel.Geom; @@ -41,6 +40,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Numbering; using iText.Kernel.Pdf.Annot; using iText.Kernel.Pdf.Collection; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Filespec; using iText.Kernel.Pdf.Navigation; using iText.Kernel.Pdf.Statistics; @@ -53,7 +53,7 @@ You should have received a copy of the GNU Affero General Public License namespace iText.Kernel.Pdf { /// Main enter point to work with PDF document. - public class PdfDocument : IEventDispatcher, IDisposable { + public class PdfDocument : IDisposable { private static readonly PdfName[] PDF_NAMES_TO_REMOVE_FROM_ORIGINAL_TRAILER = new PdfName[] { PdfName.Encrypt , PdfName.Size, PdfName.Prev, PdfName.Root, PdfName.Info, PdfName.ID, PdfName.XRefStm, PdfName.AuthCode }; @@ -70,6 +70,8 @@ public class PdfDocument : IEventDispatcher, IDisposable { private readonly IDictionary documentFonts = new Dictionary(); + private readonly ICollection documentHandlers = new LinkedHashSet(); + private readonly SequenceId documentId; /// To be adjusted destinations. @@ -81,8 +83,6 @@ public class PdfDocument : IEventDispatcher, IDisposable { private readonly IList pendingDestinationMutations = new List(); - protected internal EventDispatcher eventDispatcher = new EventDispatcher(); - /// PdfWriter associated with the document. /// /// PdfWriter associated with the document. @@ -732,34 +732,57 @@ public virtual void SetDefaultPageSize(PageSize pageSize) { defaultPageSize = pageSize; } - /// - public virtual void AddEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - eventDispatcher.AddEventHandler(type, handler); + /// Adds new event handler. + /// a type of event to be handled + /// event handler + public virtual void AddEventHandler(String type, AbstractPdfDocumentEventHandler handler) { + handler.AddType(type); + documentHandlers.Add(handler); } - /// - public virtual void DispatchEvent(Event @event) { - eventDispatcher.DispatchEvent(@event); - } - - /// - public virtual void DispatchEvent(Event @event, bool delayed) { - eventDispatcher.DispatchEvent(@event, delayed); + /// Dispatches an event. + /// + /// the + /// + /// to be dispatched + /// + public virtual void DispatchEvent(AbstractPdfDocumentEvent @event) { + @event.SetDocument(this); + foreach (IEventHandler handler in documentHandlers) { + handler.OnEvent(@event); + } } - /// - public virtual bool HasEventHandler(String type) { - return eventDispatcher.HasEventHandler(type); + /// Checks if provided event handler assigned for this document. + /// + /// the + /// + /// to check + /// + /// + /// + /// + /// if event handler is assigned for this document, + /// + /// otherwise + /// + public virtual bool HasEventHandler(AbstractPdfDocumentEventHandler handler) { + return documentHandlers.Contains(handler); } - /// - public virtual void RemoveEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - eventDispatcher.RemoveEventHandler(type, handler); + /// Removes event handler. + /// + /// + /// + /// event handler to remove for this document + /// + public virtual void RemoveEventHandler(AbstractPdfDocumentEventHandler handler) { + documentHandlers.Remove(handler); } - /// + /// Removes all event handlers for this document. public virtual void RemoveAllHandlers() { - eventDispatcher.RemoveAllHandlers(); + documentHandlers.Clear(); } /// @@ -840,7 +863,7 @@ public virtual void Close() { .GetInstance())); // The event will prepare document for flushing, i.e. will set an appropriate producer line manager.OnEvent(new FlushPdfDocumentEvent(this)); - DispatchEvent(new PdfDocumentEvent(PdfDocumentEvent.START_DOCUMENT_CLOSING, this)); + DispatchEvent(new PdfDocumentEvent(PdfDocumentEvent.START_DOCUMENT_CLOSING)); UpdateXmpMetadata(); // In PDF 2.0, all the values except CreationDate and ModDate are deprecated. Remove them now if (pdfVersion.CompareTo(PdfVersion.PDF_2_0) >= 0) { diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs b/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs index 4293bd1ed9..49a637e39c 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs @@ -25,11 +25,11 @@ You should have received a copy of the GNU Affero General Public License using Microsoft.Extensions.Logging; using iText.Commons; using iText.Commons.Utils; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Geom; using iText.Kernel.Pdf.Action; using iText.Kernel.Pdf.Annot; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Filespec; using iText.Kernel.Pdf.Layer; using iText.Kernel.Pdf.Tagging; diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs b/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs index 65c0ae5799..fe8a8261c6 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs @@ -27,9 +27,9 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons; using iText.Commons.Utils; using iText.IO.Source; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Mac; +using iText.Kernel.Pdf.Event; using iText.Kernel.Utils; namespace iText.Kernel.Pdf { @@ -421,7 +421,7 @@ protected internal virtual void FlushModifiedWaitingObjects(ICollection. +*/ +using System; +using iText.Commons.Actions; +using iText.Kernel.Pdf; + +namespace iText.Kernel.Pdf.Event { + /// Describes abstract PDF document event of the specified type. + /// + /// Describes abstract PDF document event of the specified type. + /// + /// Use + /// + /// to fire an event + /// and + /// + /// to register + /// + /// handler for that type of event. + /// + public abstract class AbstractPdfDocumentEvent : IEvent { + /// A type of event. + protected internal String type; + + private PdfDocument document; + + /// Creates an event of the specified type. + /// the type of event + protected internal AbstractPdfDocumentEvent(String type) { + this.type = type; + } + + /// Returns the type of this event. + /// type of this event + public virtual String GetType() { + return type; + } + + /// Retrieves the document associated with this event. + /// + /// + /// + /// that triggered this event + /// + public virtual PdfDocument GetDocument() { + return document; + } + + /// Sets the document associated with this event. + /// + /// + /// + /// that triggered this event + /// + /// + /// this + /// + /// instance + /// + public virtual iText.Kernel.Pdf.Event.AbstractPdfDocumentEvent SetDocument(PdfDocument document) { + this.document = document; + return this; + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEventHandler.cs b/itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEventHandler.cs new file mode 100644 index 0000000000..25f283aa23 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEventHandler.cs @@ -0,0 +1,102 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using iText.Commons.Actions; + +namespace iText.Kernel.Pdf.Event { + /// Base class for PDF document events handling based on the event type. + /// + /// Base class for PDF document events handling based on the event type. + /// + /// Handles + /// + /// event fired by + /// . + /// Use + /// + /// to register this handler for + /// specific type of event. + /// + public abstract class AbstractPdfDocumentEventHandler : IEventHandler { + private readonly ICollection types = new HashSet(); + + /// + /// Creates new + /// + /// instance. + /// + /// + /// Creates new + /// + /// instance. + /// + /// By default, this instance handles all types of the + /// + /// events. For specific types + /// handling, use + /// + /// method. + /// + protected internal AbstractPdfDocumentEventHandler() { + } + + /// + /// Adds new event type to handle by this + /// + /// instance. + /// + /// + /// the + /// + /// type to handle + /// + /// + /// this + /// + /// instance + /// + public virtual iText.Kernel.Pdf.Event.AbstractPdfDocumentEventHandler AddType(String type) { + this.types.Add(type); + return this; + } + + public virtual void OnEvent(IEvent @event) { + if (!(@event is AbstractPdfDocumentEvent)) { + return; + } + AbstractPdfDocumentEvent iTextEvent = (AbstractPdfDocumentEvent)@event; + if (types.IsEmpty() || types.Contains(iTextEvent.GetType())) { + OnAcceptedEvent(iTextEvent); + } + } + + /// Handles the accepted event. + /// + /// + /// + /// to handle + /// + protected internal abstract void OnAcceptedEvent(AbstractPdfDocumentEvent @event); + } +} diff --git a/itext/itext.kernel/itext/kernel/events/PdfDocumentEvent.cs b/itext/itext.kernel/itext/kernel/pdf/event/PdfDocumentEvent.cs similarity index 82% rename from itext/itext.kernel/itext/kernel/events/PdfDocumentEvent.cs rename to itext/itext.kernel/itext/kernel/pdf/event/PdfDocumentEvent.cs index 2b7319ec63..87e844f5a5 100644 --- a/itext/itext.kernel/itext/kernel/events/PdfDocumentEvent.cs +++ b/itext/itext.kernel/itext/kernel/pdf/event/PdfDocumentEvent.cs @@ -23,9 +23,9 @@ You should have received a copy of the GNU Affero General Public License using System; using iText.Kernel.Pdf; -namespace iText.Kernel.Events { +namespace iText.Kernel.Pdf.Event { /// Event dispatched by PdfDocument. - public class PdfDocumentEvent : Event { + public class PdfDocumentEvent : AbstractPdfDocumentEvent { /// Dispatched after page is created. public const String START_PAGE = "StartPdfPage"; @@ -52,15 +52,10 @@ public class PdfDocumentEvent : Event { /// The PdfPage associated with this event. protected internal PdfPage page; - /// The PdfDocument associated with this event. - private PdfDocument document; - /// Creates a PdfDocumentEvent. /// type of the event that fired this event - /// document that fired this event - public PdfDocumentEvent(String type, PdfDocument document) + public PdfDocumentEvent(String type) : base(type) { - this.document = document; } /// Creates a PdfDocumentEvent. @@ -69,13 +64,6 @@ public PdfDocumentEvent(String type, PdfDocument document) public PdfDocumentEvent(String type, PdfPage page) : base(type) { this.page = page; - this.document = page.GetDocument(); - } - - /// Returns the PdfDocument associated with this event. - /// the PdfDocument associated with this event - public virtual PdfDocument GetDocument() { - return document; } /// Returns the PdfPage associated with this event. diff --git a/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs b/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs index 5e13a07fff..9f6256a009 100644 --- a/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs +++ b/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs @@ -23,11 +23,11 @@ You should have received a copy of the GNU Affero General Public License using System; using System.IO; using iText.Commons.Bouncycastle.Asn1; -using iText.Kernel.Events; +using iText.Kernel.Pdf.Event; namespace iText.Signatures.Mac { /// Represents an event firing before creating signature container. - public class SignatureContainerGenerationEvent : Event { + public class SignatureContainerGenerationEvent : AbstractPdfDocumentEvent { public const String START_SIGNATURE_CONTAINER_GENERATION = "StartSignatureContainerGeneration"; private readonly IAsn1EncodableVector unsignedAttributes; diff --git a/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs b/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs index 7568325914..29148c215b 100644 --- a/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs +++ b/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs @@ -21,12 +21,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ using System; -using iText.Kernel.Events; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; namespace iText.Signatures.Mac { /// Represents an event firing before embedding the signature into the document. - public class SignatureDocumentClosingEvent : Event { + public class SignatureDocumentClosingEvent : AbstractPdfDocumentEvent { public const String START_SIGNATURE_PRE_CLOSE = "StartSignaturePreClose"; private readonly PdfIndirectReference signatureReference; diff --git a/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs b/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs index 28c00931a7..97ff710071 100644 --- a/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs +++ b/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs @@ -26,10 +26,10 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons.Bouncycastle; using iText.Commons.Bouncycastle.Asn1; using iText.Commons.Bouncycastle.Security; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Mac; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; namespace iText.Signatures.Mac { //\cond DO_NOT_DOCUMENT @@ -77,8 +77,8 @@ private void EmbedMacContainerInUnsignedAttributes(IAsn1EncodableVector unsigned unsignedAttributes.Add(BC_FACTORY.CreateDERSequence(macAttribute)); } - private sealed class SignatureMacPdfObjectAdder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class SignatureMacPdfObjectAdder : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { if (@event is SignatureDocumentClosingEvent) { PdfDictionary signatureMacDictionary = new PdfDictionary(); signatureMacDictionary.Put(PdfName.MACLocation, PdfName.AttachedToSig); @@ -95,8 +95,8 @@ internal SignatureMacPdfObjectAdder(SignatureMacIntegrityProtector _enclosing) { private readonly SignatureMacIntegrityProtector _enclosing; } - private sealed class SignatureMacContainerEmbedder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class SignatureMacContainerEmbedder : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { if (@event is SignatureContainerGenerationEvent) { SignatureContainerGenerationEvent signatureEvent = (SignatureContainerGenerationEvent)@event; try { diff --git a/port-hash b/port-hash index 7111f8cda8..d8b853f018 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -a0fc8b8fe2956f080130695f69f406bc43a9f980 +5b9f0e9806ae424d0fbe4f7fc2cea7c11ca03c68 From 2ededc939280d1b0f6f9c64cae84f0de1052b759 Mon Sep 17 00:00:00 2001 From: iText Software Date: Mon, 7 Oct 2024 14:25:15 +0000 Subject: [PATCH 2/2] Add missing javadocs DEVSIX-8629 Autoported commit. Original commit hash: [5d52188d2] Manual files: bouncy-castle-adapter/src/main/java/com/itextpdf/bouncycastle/cert/ocsp/ResponderIDBC.java bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/ResponderIDBCFips.java --- .../itext/bouncycastle/cert/ocsp/ResponderIDBC.cs | 4 ++++ .../itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs | 4 ++++ port-hash | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/itext/itext.bouncy-castle-adapter/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs b/itext/itext.bouncy-castle-adapter/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs index 4f458913fa..770b8cd9ce 100644 --- a/itext/itext.bouncy-castle-adapter/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs +++ b/itext/itext.bouncy-castle-adapter/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs @@ -26,6 +26,10 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons.Bouncycastle.Cert.Ocsp; namespace iText.Bouncycastle.Cert.Ocsp { + /// + /// Wrapper class for + /// . + /// public class ResponderIDBC : IResponderID { private readonly ResponderID responderID; diff --git a/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs b/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs index 5fa28964cb..75b6bd9e6d 100644 --- a/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs +++ b/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs @@ -26,6 +26,10 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons.Bouncycastle.Cert.Ocsp; namespace iText.Bouncycastlefips.Cert.Ocsp { + /// + /// Wrapper class for + /// . + /// public class ResponderIDBCFips : IResponderID { private readonly ResponderID responderID; diff --git a/port-hash b/port-hash index d8b853f018..c2d50f67a1 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -5b9f0e9806ae424d0fbe4f7fc2cea7c11ca03c68 +5d52188d21a976693e808d174a519195b62f241c