summary refs log tree commit diff
path: root/crypto/src/openpgp
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-07-21 14:17:55 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-07-21 14:17:55 +0700
commitfdefe6547948e0c30e4d3d652932f0689aab3da4 (patch)
treec17a562e7ac641f25aa19aa7cc80baab4d45536e /crypto/src/openpgp
parentPort constant-time extensions from Java (diff)
downloadBouncyCastle.NET-ed25519-fdefe6547948e0c30e4d3d652932f0689aab3da4.tar.xz
Port a few Java openpgp updates
Diffstat (limited to 'crypto/src/openpgp')
-rw-r--r--crypto/src/openpgp/PgpPublicKeyRing.cs176
1 files changed, 88 insertions, 88 deletions
diff --git a/crypto/src/openpgp/PgpPublicKeyRing.cs b/crypto/src/openpgp/PgpPublicKeyRing.cs
index ecb935e4b..7b1ac93bf 100644
--- a/crypto/src/openpgp/PgpPublicKeyRing.cs
+++ b/crypto/src/openpgp/PgpPublicKeyRing.cs
@@ -7,164 +7,164 @@ using Org.BouncyCastle.Utilities.Collections;
 
 namespace Org.BouncyCastle.Bcpg.OpenPgp
 {
-	/// <remarks>
-	/// Class to hold a single master public key and its subkeys.
-	/// <p>
-	/// Often PGP keyring files consist of multiple master keys, if you are trying to process
-	/// or construct one of these you should use the <c>PgpPublicKeyRingBundle</c> class.
-	/// </p>
-	/// </remarks>
-	public class PgpPublicKeyRing
-		: PgpKeyRing
+    /// <remarks>
+    /// Class to hold a single master public key and its subkeys.
+    /// <p>
+    /// Often PGP keyring files consist of multiple master keys, if you are trying to process
+    /// or construct one of these you should use the <c>PgpPublicKeyRingBundle</c> class.
+    /// </p>
+    /// </remarks>
+    public class PgpPublicKeyRing
+        : PgpKeyRing
     {
         private readonly IList keys;
 
-		public PgpPublicKeyRing(
+        public PgpPublicKeyRing(
             byte[] encoding)
             : this(new MemoryStream(encoding, false))
         {
         }
 
-		internal PgpPublicKeyRing(
+        internal PgpPublicKeyRing(
             IList pubKeys)
         {
             this.keys = pubKeys;
         }
 
-		public PgpPublicKeyRing(
+        public PgpPublicKeyRing(
             Stream inputStream)
         {
-			this.keys = Platform.CreateArrayList();
+            this.keys = Platform.CreateArrayList();
 
             BcpgInputStream bcpgInput = BcpgInputStream.Wrap(inputStream);
 
-			PacketTag initialTag = bcpgInput.NextPacketTag();
+            PacketTag initialTag = bcpgInput.NextPacketTag();
             if (initialTag != PacketTag.PublicKey && initialTag != PacketTag.PublicSubkey)
             {
                 throw new IOException("public key ring doesn't start with public key tag: "
-					+ "tag 0x" + ((int)initialTag).ToString("X"));
+                    + "tag 0x" + ((int)initialTag).ToString("X"));
             }
 
-			PublicKeyPacket pubPk = (PublicKeyPacket) bcpgInput.ReadPacket();;
-			TrustPacket trustPk = ReadOptionalTrustPacket(bcpgInput);
+            PublicKeyPacket pubPk = (PublicKeyPacket) bcpgInput.ReadPacket();;
+            TrustPacket trustPk = ReadOptionalTrustPacket(bcpgInput);
 
             // direct signatures and revocations
-			IList keySigs = ReadSignaturesAndTrust(bcpgInput);
+            IList keySigs = ReadSignaturesAndTrust(bcpgInput);
 
-			IList ids, idTrusts, idSigs;
-			ReadUserIDs(bcpgInput, out ids, out idTrusts, out idSigs);
+            IList ids, idTrusts, idSigs;
+            ReadUserIDs(bcpgInput, out ids, out idTrusts, out idSigs);
 
-			keys.Add(new PgpPublicKey(pubPk, trustPk, keySigs, ids, idTrusts, idSigs));
+            keys.Add(new PgpPublicKey(pubPk, trustPk, keySigs, ids, idTrusts, idSigs));
 
 
-			// Read subkeys
-			while (bcpgInput.NextPacketTag() == PacketTag.PublicSubkey)
+            // Read subkeys
+            while (bcpgInput.NextPacketTag() == PacketTag.PublicSubkey)
             {
-				keys.Add(ReadSubkey(bcpgInput));
+                keys.Add(ReadSubkey(bcpgInput));
             }
         }
 
-		/// <summary>Return the first public key in the ring.</summary>
-        public PgpPublicKey GetPublicKey()
+        /// <summary>Return the first public key in the ring.</summary>
+        public virtual PgpPublicKey GetPublicKey()
         {
             return (PgpPublicKey) keys[0];
         }
 
-		/// <summary>Return the public key referred to by the passed in key ID if it is present.</summary>
-        public PgpPublicKey GetPublicKey(
+        /// <summary>Return the public key referred to by the passed in key ID if it is present.</summary>
+        public virtual PgpPublicKey GetPublicKey(
             long keyId)
         {
-			foreach (PgpPublicKey k in keys)
-			{
-				if (keyId == k.KeyId)
+            foreach (PgpPublicKey k in keys)
+            {
+                if (keyId == k.KeyId)
                 {
                     return k;
                 }
             }
 
-			return null;
+            return null;
         }
 
-		/// <summary>Allows enumeration of all the public keys.</summary>
-		/// <returns>An <c>IEnumerable</c> of <c>PgpPublicKey</c> objects.</returns>
-        public IEnumerable GetPublicKeys()
+        /// <summary>Allows enumeration of all the public keys.</summary>
+        /// <returns>An <c>IEnumerable</c> of <c>PgpPublicKey</c> objects.</returns>
+        public virtual IEnumerable GetPublicKeys()
         {
             return new EnumerableProxy(keys);
         }
 
-		public byte[] GetEncoded()
+        public virtual byte[] GetEncoded()
         {
             MemoryStream bOut = new MemoryStream();
 
-			Encode(bOut);
+            Encode(bOut);
 
-			return bOut.ToArray();
+            return bOut.ToArray();
         }
 
-		public void Encode(
+        public virtual void Encode(
             Stream outStr)
         {
-			if (outStr == null)
-				throw new ArgumentNullException("outStr");
+            if (outStr == null)
+                throw new ArgumentNullException("outStr");
 
-			foreach (PgpPublicKey k in keys)
-			{
-				k.Encode(outStr);
+            foreach (PgpPublicKey k in keys)
+            {
+                k.Encode(outStr);
             }
         }
 
-		/// <summary>
-		/// Returns a new key ring with the public key passed in either added or
-		/// replacing an existing one.
-		/// </summary>
-		/// <param name="pubRing">The public key ring to be modified.</param>
-		/// <param name="pubKey">The public key to be inserted.</param>
-		/// <returns>A new <c>PgpPublicKeyRing</c></returns>
+        /// <summary>
+        /// Returns a new key ring with the public key passed in either added or
+        /// replacing an existing one.
+        /// </summary>
+        /// <param name="pubRing">The public key ring to be modified.</param>
+        /// <param name="pubKey">The public key to be inserted.</param>
+        /// <returns>A new <c>PgpPublicKeyRing</c></returns>
         public static PgpPublicKeyRing InsertPublicKey(
             PgpPublicKeyRing	pubRing,
             PgpPublicKey		pubKey)
         {
             IList keys = Platform.CreateArrayList(pubRing.keys);
             bool found = false;
-			bool masterFound = false;
+            bool masterFound = false;
 
-			for (int i = 0; i != keys.Count; i++)
+            for (int i = 0; i != keys.Count; i++)
             {
                 PgpPublicKey key = (PgpPublicKey) keys[i];
 
-				if (key.KeyId == pubKey.KeyId)
+                if (key.KeyId == pubKey.KeyId)
                 {
                     found = true;
                     keys[i] = pubKey;
                 }
-				if (key.IsMasterKey)
-				{
-					masterFound = true;
-				}
-			}
+                if (key.IsMasterKey)
+                {
+                    masterFound = true;
+                }
+            }
 
-			if (!found)
+            if (!found)
             {
-				if (pubKey.IsMasterKey)
-				{
-					if (masterFound)
-						throw new ArgumentException("cannot add a master key to a ring that already has one");
-
-					keys.Insert(0, pubKey);
-				}
-				else
-				{
-					keys.Add(pubKey);
-				}
-			}
-
-			return new PgpPublicKeyRing(keys);
+                if (pubKey.IsMasterKey)
+                {
+                    if (masterFound)
+                        throw new ArgumentException("cannot add a master key to a ring that already has one");
+
+                    keys.Insert(0, pubKey);
+                }
+                else
+                {
+                    keys.Add(pubKey);
+                }
+            }
+
+            return new PgpPublicKeyRing(keys);
         }
 
-		/// <summary>Returns a new key ring with the public key passed in removed from the key ring.</summary>
-		/// <param name="pubRing">The public key ring to be modified.</param>
-		/// <param name="pubKey">The public key to be removed.</param>
-		/// <returns>A new <c>PgpPublicKeyRing</c>, or null if pubKey is not found.</returns>
+        /// <summary>Returns a new key ring with the public key passed in removed from the key ring.</summary>
+        /// <param name="pubRing">The public key ring to be modified.</param>
+        /// <param name="pubKey">The public key to be removed.</param>
+        /// <returns>A new <c>PgpPublicKeyRing</c>, or null if pubKey is not found.</returns>
         public static PgpPublicKeyRing RemovePublicKey(
             PgpPublicKeyRing	pubRing,
             PgpPublicKey		pubKey)
@@ -172,29 +172,29 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             IList keys = Platform.CreateArrayList(pubRing.keys);
             bool found = false;
 
-			for (int i = 0; i < keys.Count; i++)
+            for (int i = 0; i < keys.Count; i++)
             {
                 PgpPublicKey key = (PgpPublicKey) keys[i];
 
-				if (key.KeyId == pubKey.KeyId)
+                if (key.KeyId == pubKey.KeyId)
                 {
                     found = true;
                     keys.RemoveAt(i);
                 }
             }
 
-			return found ? new PgpPublicKeyRing(keys) : null;
+            return found ? new PgpPublicKeyRing(keys) : null;
         }
 
-		internal static PgpPublicKey ReadSubkey(BcpgInputStream bcpgInput)
-		{
+        internal static PgpPublicKey ReadSubkey(BcpgInputStream bcpgInput)
+        {
             PublicKeyPacket	pk = (PublicKeyPacket) bcpgInput.ReadPacket();
-			TrustPacket kTrust = ReadOptionalTrustPacket(bcpgInput);
+            TrustPacket kTrust = ReadOptionalTrustPacket(bcpgInput);
 
-			// PGP 8 actually leaves out the signature.
-			IList sigList = ReadSignaturesAndTrust(bcpgInput);
+            // PGP 8 actually leaves out the signature.
+            IList sigList = ReadSignaturesAndTrust(bcpgInput);
 
-			return new PgpPublicKey(pk, kTrust, sigList);
-		}
+            return new PgpPublicKey(pk, kTrust, sigList);
+        }
     }
 }