public void Encode( Stream outStr) { BcpgOutputStream bcpgOut = BcpgOutputStream.Wrap(outStr); foreach (long key in order) { PgpPublicKeyRing sec = (PgpPublicKeyRing)pubRings[key]; sec.Encode(bcpgOut); } }
/// <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)); }
/// <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)); }
/// <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 keys = Platform.CreateArrayList(pubRing.keys); bool found = false; bool masterFound = false; for (int i = 0; i != keys.Count; i++) { PgpPublicKey key = (PgpPublicKey)keys[i]; if (key.KeyId == pubKey.KeyId) { found = true; keys[i] = pubKey; } if (key.IsMasterKey) { masterFound = true; } } if (!found) { if (pubKey.IsMasterKey) { if (masterFound) { throw new ArgumentException("cannot add a master key to a ring that already has one"); } keys.Insert(0, pubKey); } else { keys.Add(pubKey); } } return(new PgpPublicKeyRing(keys)); }
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(obj.GetType().FullName + " found where PgpPublicKeyRing expected"); } long key = pgpPub.GetPublicKey().KeyId; pubRings.Add(key, pgpPub); order.Add(key); } }
/// <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 keys = Platform.CreateArrayList(pubRing.keys); bool found = false; for (int i = 0; i < keys.Count; i++) { PgpPublicKey key = (PgpPublicKey)keys[i]; if (key.KeyId == pubKey.KeyId) { found = true; keys.RemoveAt(i); } } return(found ? new PgpPublicKeyRing(keys) : null); }