コード例 #1
0
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(
            PgpSecretKeyRing secretRing,
            PgpPublicKeyRing publicRing)
        {
            IList newList = Platform.CreateArrayList(secretRing.keys.Count);

            foreach (PgpSecretKey sk in secretRing.keys)
            {
                PgpPublicKey pk = publicRing.GetPublicKey(sk.KeyId);

                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return(new PgpSecretKeyRing(newList));
        }
コード例 #2
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.Contains(key))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = Platform.CreateHashtable(bundle.pubRings);
            IList       newOrder    = Platform.CreateArrayList(bundle.order);

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

            return(new PgpPublicKeyRingBundle(newPubRings, newOrder));
        }
コード例 #3
0
        public PgpPublicKeyRingBundle(
            IEnumerable e)
        {
            this.pubRings = Platform.CreateHashtable();
            this.order    = Platform.CreateArrayList();

            foreach (object obj in e)
            {
                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);
                order.Add(key);
            }
        }