Exemple #1
0
 public override void Encode(IPacketWriter outStr)
 {
     foreach (long key in order)
     {
         PgpPublicKeyRing sec = pubRings[key];
         sec.Encode(outStr);
     }
 }
Exemple #2
0
        /// <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)
        {
            IList <PgpPublicKey> keys = new List <PgpPublicKey>(pubRing.keys);

            return(RemoveKey(keys, pubKey) ? new PgpPublicKeyRing(keys) : null);
        }
Exemple #3
0
        /// <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 <PgpPublicKey> keys = new List <PgpPublicKey>(pubRing.keys);

            InsertKey(keys, pubKey);
            return(new PgpPublicKeyRing(keys));
        }
Exemple #4
0
        public PgpPublicKeyRingBundle(IPacketReader packetReader)
        {
            this.pubRings = new Dictionary <long, PgpPublicKeyRing>();
            this.order    = new List <long>();

            while (packetReader.NextPacketTag() == PacketTag.PublicKey)
            {
                var  keyRing = new PgpPublicKeyRing(packetReader);
                long key     = keyRing.GetPublicKey().KeyId;
                pubRings.Add(key, keyRing);
                order.Add(key);
            }
        }
Exemple #5
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));
        }
Exemple #6
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));
        }