Пример #1
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle with
        /// the passed in secret key ring removed.
        /// </summary>
        /// <param name="bundle">The <c>PgpSecretKeyRingBundle</c> the key ring is to be removed from.</param>
        /// <param name="secretKeyRing">The key ring to be removed.</param>
        /// <returns>A new <c>PgpSecretKeyRingBundle</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 PgpSecretKeyRingBundle RemoveSecretKeyRing(
            PgpSecretKeyRingBundle bundle,
            PgpSecretKeyRing secretKeyRing)
        {
            long key = secretKeyRing.GetPublicKey().KeyId;

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

            IDictionary newSecretRings = Platform.CreateHashtable(bundle.secretRings);
            IList       newOrder       = Platform.CreateArrayList(bundle.order);

            newSecretRings.Remove(key);
            newOrder.Remove(key);

            return(new PgpSecretKeyRingBundle(newSecretRings, newOrder));
        }
Пример #2
0
        public PgpSecretKeyRingBundle(
            IEnumerable e)
        {
            this.secretRings = Platform.CreateHashtable();
            this.order       = Platform.CreateArrayList();

            foreach (object obj in e)
            {
                PgpSecretKeyRing pgpSecret = obj as PgpSecretKeyRing;

                if (pgpSecret == null)
                {
                    throw new PgpException(obj.GetType().FullName + " found where PgpSecretKeyRing expected");
                }

                long key = pgpSecret.GetPublicKey().KeyId;
                secretRings.Add(key, pgpSecret);
                order.Add(key);
            }
        }