예제 #1
0
        /// <summary>
        /// Enumerate all public keyrings.
        /// </summary>
        /// <remarks>
        /// Enumerates all public keyrings.
        /// </remarks>
        /// <returns>The list of available public keyrings.</returns>
        public virtual IEnumerable <PgpPublicKeyRing> EnumeratePublicKeyRings()
        {
            foreach (PgpPublicKeyRing keyring in PublicKeyRingBundle.GetKeyRings())
            {
                yield return(keyring);
            }

            yield break;
        }
예제 #2
0
        bool TryGetPublicKeyRing(long keyId, out PgpPublicKeyRing keyring)
        {
            foreach (PgpPublicKeyRing ring in PublicKeyRingBundle.GetKeyRings())
            {
                foreach (PgpPublicKey key in ring.GetPublicKeys())
                {
                    if (key.KeyId == keyId)
                    {
                        keyring = ring;
                        return(true);
                    }
                }
            }

            keyring = null;

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Helper method to retrieve a public key, and its keyring, given a key's ID
        /// </summary>
        /// <param name="keyId"></param>
        /// <param name="doAsync"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task <KeyRetrievalResults> GetPublicKeyRingAsync(long keyId, bool doAsync, CancellationToken cancellationToken)
        {
            foreach (PgpPublicKeyRing ring in PublicKeyRingBundle.GetKeyRings())
            {
                foreach (PgpPublicKey key in ring.GetPublicKeys())
                {
                    if (key.KeyId == keyId)
                    {
                        return(new KeyRetrievalResults(ring, key));
                    }
                }
            }

            if (AutoKeyRetrieve && IsValidKeyServer)
            {
                var keyring = await RetrievePublicKeyRingAsync(keyId, doAsync, cancellationToken).ConfigureAwait(false);

                return(new KeyRetrievalResults(keyring, keyring.GetPublicKey(keyId)));
            }

            return(new KeyRetrievalResults(null, null));
        }