summary refs log tree commit diff
path: root/crypto/src/openpgp
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/openpgp')
-rw-r--r--crypto/src/openpgp/PGPKeyRing.cs54
-rw-r--r--crypto/src/openpgp/PgpPublicKeyRing.cs2
-rw-r--r--crypto/src/openpgp/PgpPublicKeyRingBundle.cs7
-rw-r--r--crypto/src/openpgp/PgpSecretKeyRing.cs2
-rw-r--r--crypto/src/openpgp/PgpSecretKeyRingBundle.cs7
5 files changed, 38 insertions, 34 deletions
diff --git a/crypto/src/openpgp/PGPKeyRing.cs b/crypto/src/openpgp/PGPKeyRing.cs
index 425eaca56..9d9454f54 100644
--- a/crypto/src/openpgp/PGPKeyRing.cs
+++ b/crypto/src/openpgp/PGPKeyRing.cs
@@ -12,25 +12,23 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 		{
 		}
 
-		internal static TrustPacket ReadOptionalTrustPacket(
-			BcpgInputStream bcpgInput)
+        internal static TrustPacket ReadOptionalTrustPacket(BcpgInputStream pIn)
 		{
-			return (bcpgInput.NextPacketTag() == PacketTag.Trust)
-				?	(TrustPacket)bcpgInput.ReadPacket()
-				:	null;
+            PacketTag tag = pIn.SkipMarkerPackets();
+
+            return tag == PacketTag.Trust ? (TrustPacket)pIn.ReadPacket() : null;
 		}
 
-		internal static IList ReadSignaturesAndTrust(
-			BcpgInputStream	bcpgInput)
+		internal static IList ReadSignaturesAndTrust(BcpgInputStream pIn)
 		{
-			try
-			{
+            try
+            {
 				IList sigList = Platform.CreateArrayList();
 
-				while (bcpgInput.NextPacketTag() == PacketTag.Signature)
+				while (pIn.SkipMarkerPackets() == PacketTag.Signature)
 				{
-					SignaturePacket signaturePacket = (SignaturePacket) bcpgInput.ReadPacket();
-					TrustPacket trustPacket = ReadOptionalTrustPacket(bcpgInput);
+					SignaturePacket signaturePacket = (SignaturePacket)pIn.ReadPacket();
+					TrustPacket trustPacket = ReadOptionalTrustPacket(pIn);
 
 					sigList.Add(new PgpSignature(signaturePacket, trustPacket));
 				}
@@ -43,20 +41,15 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 			}
 		}
 
-		internal static void ReadUserIDs(
-			BcpgInputStream	bcpgInput,
-			out IList       ids,
-			out IList       idTrusts,
-			out IList       idSigs)
+		internal static void ReadUserIDs(BcpgInputStream pIn, out IList ids, out IList idTrusts, out IList idSigs)
 		{
 			ids = Platform.CreateArrayList();
             idTrusts = Platform.CreateArrayList();
             idSigs = Platform.CreateArrayList();
 
-			while (bcpgInput.NextPacketTag() == PacketTag.UserId
-				|| bcpgInput.NextPacketTag() == PacketTag.UserAttribute)
+            while (IsUserTag(pIn.SkipMarkerPackets()))
 			{
-				Packet obj = bcpgInput.ReadPacket();
+				Packet obj = pIn.ReadPacket();
 				if (obj is UserIdPacket)
 				{
 					UserIdPacket id = (UserIdPacket)obj;
@@ -64,16 +57,25 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 				}
 				else
 				{
-					UserAttributePacket user = (UserAttributePacket) obj;
+					UserAttributePacket user = (UserAttributePacket)obj;
 					ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets()));
 				}
 
-				idTrusts.Add(
-					ReadOptionalTrustPacket(bcpgInput));
-
-				idSigs.Add(
-					ReadSignaturesAndTrust(bcpgInput));
+				idTrusts.Add(ReadOptionalTrustPacket(pIn));
+				idSigs.Add(ReadSignaturesAndTrust(pIn));
 			}
 		}
+
+        private static bool IsUserTag(PacketTag tag)
+        {
+            switch (tag)
+            {
+                case PacketTag.UserAttribute:
+                case PacketTag.UserId:
+                    return true;
+                default:
+                    return false;
+            }
+        }
 	}
 }
diff --git a/crypto/src/openpgp/PgpPublicKeyRing.cs b/crypto/src/openpgp/PgpPublicKeyRing.cs
index c214623b4..b35e0147b 100644
--- a/crypto/src/openpgp/PgpPublicKeyRing.cs
+++ b/crypto/src/openpgp/PgpPublicKeyRing.cs
@@ -38,7 +38,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 
             BcpgInputStream bcpgInput = BcpgInputStream.Wrap(inputStream);
 
-            PacketTag initialTag = bcpgInput.NextPacketTag();
+            PacketTag initialTag = bcpgInput.SkipMarkerPackets();
             if (initialTag != PacketTag.PublicKey && initialTag != PacketTag.PublicSubkey)
             {
                 throw new IOException("public key ring doesn't start with public key tag: "
diff --git a/crypto/src/openpgp/PgpPublicKeyRingBundle.cs b/crypto/src/openpgp/PgpPublicKeyRingBundle.cs
index 91113e904..08d0aa0a1 100644
--- a/crypto/src/openpgp/PgpPublicKeyRingBundle.cs
+++ b/crypto/src/openpgp/PgpPublicKeyRingBundle.cs
@@ -48,12 +48,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 
 			foreach (object obj in e)
             {
-				PgpPublicKeyRing pgpPub = obj as PgpPublicKeyRing;
+                // Marker packets must be ignored
+                if (obj is PgpMarker)
+                    continue;
 
+                PgpPublicKeyRing pgpPub = obj as PgpPublicKeyRing;
 				if (pgpPub == null)
-				{
 					throw new PgpException(Platform.GetTypeName(obj) + " found where PgpPublicKeyRing expected");
-				}
 
 				long key = pgpPub.GetPublicKey().KeyId;
                 pubRings.Add(key, pgpPub);
diff --git a/crypto/src/openpgp/PgpSecretKeyRing.cs b/crypto/src/openpgp/PgpSecretKeyRing.cs
index 70cd7217c..06ad4d374 100644
--- a/crypto/src/openpgp/PgpSecretKeyRing.cs
+++ b/crypto/src/openpgp/PgpSecretKeyRing.cs
@@ -49,7 +49,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 
             BcpgInputStream bcpgInput = BcpgInputStream.Wrap(inputStream);
 
-            PacketTag initialTag = bcpgInput.NextPacketTag();
+            PacketTag initialTag = bcpgInput.SkipMarkerPackets();
             if (initialTag != PacketTag.SecretKey && initialTag != PacketTag.SecretSubkey)
             {
                 throw new IOException("secret key ring doesn't start with secret key tag: "
diff --git a/crypto/src/openpgp/PgpSecretKeyRingBundle.cs b/crypto/src/openpgp/PgpSecretKeyRingBundle.cs
index c9f4d3959..26be9c10b 100644
--- a/crypto/src/openpgp/PgpSecretKeyRingBundle.cs
+++ b/crypto/src/openpgp/PgpSecretKeyRingBundle.cs
@@ -48,12 +48,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 
 			foreach (object obj in e)
 			{
-				PgpSecretKeyRing pgpSecret = obj as PgpSecretKeyRing;
+                // Marker packets must be ignored
+                if (obj is PgpMarker)
+                    continue;
 
+                PgpSecretKeyRing pgpSecret = obj as PgpSecretKeyRing;
 				if (pgpSecret == null)
-				{
 					throw new PgpException(Platform.GetTypeName(obj) + " found where PgpSecretKeyRing expected");
-				}
 
 				long key = pgpSecret.GetPublicKey().KeyId;
 				secretRings.Add(key, pgpSecret);