From aa67c1309df1bfd1d9eac195fb82d9c75984901c Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Fri, 21 Feb 2020 18:32:24 +0700 Subject: Add utility method --- crypto/src/openpgp/PgpObjectFactory.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'crypto') diff --git a/crypto/src/openpgp/PgpObjectFactory.cs b/crypto/src/openpgp/PgpObjectFactory.cs index c5c6fcb68..c31cd221c 100644 --- a/crypto/src/openpgp/PgpObjectFactory.cs +++ b/crypto/src/openpgp/PgpObjectFactory.cs @@ -139,5 +139,24 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp } return result; } - } + + /// + /// Read all available objects, returning only those that are assignable to the specified type. + /// + /// The type of objects to return. All other objects are ignored. + /// An IList containing the filtered objects from this factory, in order. + public IList FilterPgpObjects(Type type) + { + IList result = Platform.CreateArrayList(); + PgpObject pgpObject; + while ((pgpObject = NextPgpObject()) != null) + { + if (type.IsAssignableFrom(pgpObject.GetType())) + { + result.Add(pgpObject); + } + } + return result; + } + } } -- cgit 1.4.1