Beispiel #1
0
        /// <summary>Remove a certification from the key.</summary>
        /// <param name="key">The key the certifications are to be removed from.</param>
        /// <param name="certification">The certfication to be removed.</param>
        /// <returns>The modified key, null if the certification was not found.</returns>
        public static PgpPublicKey RemoveCertification(
            PgpPublicKey key,
            PgpSignature certification)
        {
            PgpPublicKey returnKey = new PgpPublicKey(key);
            IList        sigs      = returnKey.subSigs != null
                                ?       returnKey.subSigs
                                :       returnKey.keySigs;

//			bool found = sigs.Remove(certification);
            int  pos   = sigs.IndexOf(certification);
            bool found = pos >= 0;

            if (found)
            {
                sigs.RemoveAt(pos);
            }
            else
            {
                foreach (String id in key.GetUserIds())
                {
                    foreach (object sig in key.GetSignaturesForId(id))
                    {
                        // TODO Is this the right type of equality test?
                        if (certification == sig)
                        {
                            found     = true;
                            returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification);
                        }
                    }
                }

                if (!found)
                {
                    foreach (PgpUserAttributeSubpacketVector id in key.GetUserAttributes())
                    {
                        foreach (object sig in key.GetSignaturesForUserAttribute(id))
                        {
                            // TODO Is this the right type of equality test?
                            if (certification == sig)
                            {
                                found     = true;
                                returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification);
                            }
                        }
                    }
                }
            }

            return(returnKey);
        }
		/// <summary>Remove a certification from the key.</summary>
		/// <param name="key">The key the certifications are to be removed from.</param>
		/// <param name="certification">The certfication to be removed.</param>
		/// <returns>The modified key, null if the certification was not found.</returns>
		public static PgpPublicKey RemoveCertification(
			PgpPublicKey	key,
			PgpSignature	certification)
		{
			PgpPublicKey returnKey = new PgpPublicKey(key);
			IList sigs = returnKey.subSigs != null
				?	returnKey.subSigs
				:	returnKey.keySigs;

//			bool found = sigs.Remove(certification);
			int pos = sigs.IndexOf(certification);
			bool found = pos >= 0;

			if (found)
			{
				sigs.RemoveAt(pos);
			}
			else
			{
				foreach (String id in key.GetUserIds())
				{
					foreach (object sig in key.GetSignaturesForId(id))
					{
						// TODO Is this the right type of equality test?
						if (certification == sig)
						{
							found = true;
							returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification);
						}
					}
				}

				if (!found)
				{
					foreach (PgpUserAttributeSubpacketVector id in key.GetUserAttributes())
					{
						foreach (object sig in key.GetSignaturesForUserAttribute(id))
						{
							// TODO Is this the right type of equality test?
							if (certification == sig)
							{
								found = true;
								returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification);
							}
						}
					}
				}
			}

			return returnKey;
		}