Esempio n. 1
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle with
        /// the passed in public key ring removed.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be removed from.</param>
        /// <param name="publicKeyRing">The key ring to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> not containing the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is not present.</exception>
        public static PgpPublicKeyRingBundle RemovePublicKeyRing(
            PgpPublicKeyRingBundle bundle,
            PgpPublicKeyRing publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (!bundle.pubRings.ContainsKey(key))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }

            IDictionary <long, PgpPublicKeyRing> newPubRings = new Dictionary <long, PgpPublicKeyRing>(bundle.pubRings);
            IList <long> newOrder = new List <long>(bundle.order);

            newPubRings.Remove(key);
            newOrder.Remove(key);

            return(new PgpPublicKeyRingBundle(newPubRings, newOrder));
        }
Esempio n. 2
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in public key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="publicKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> merging the current one with the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is already present.</exception>
        public static PgpPublicKeyRingBundle AddPublicKeyRing(
            PgpPublicKeyRingBundle bundle,
            PgpPublicKeyRing publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (bundle.pubRings.ContainsKey(key))
            {
                throw new ArgumentException("Bundle already contains a key with a keyId for the passed in ring.");
            }

            IDictionary <long, PgpPublicKeyRing> newPubRings = new Dictionary <long, PgpPublicKeyRing>(bundle.pubRings);
            IList <long> newOrder = new List <long>(bundle.order);

            newPubRings[key] = publicKeyRing;

            newOrder.Add(key);

            return(new PgpPublicKeyRingBundle(newPubRings, newOrder));
        }