Example #1
0
        public static PgpUser AddCertification(PgpUser user, PgpKey publicKey, PgpSignature signature)
        {
            var newUser = new PgpUser(user, publicKey);

            newUser.AddCertification(publicKey, signature);
            return(newUser);
        }
Example #2
0
        public static PgpUser RemoveCertification(PgpUser user, PgpKey publicKey, PgpCertification certification)
        {
            var newUser = new PgpUser(user, publicKey);

            newUser.selfCertifications.RemoveAll(c => Equals(c.Signature, certification.Signature));
            newUser.otherCertifications.RemoveAll(c => Equals(c.Signature, certification.Signature));
            newUser.revocationSignatures.RemoveAll(c => Equals(c.Signature, certification.Signature));
            return(newUser);
        }
Example #3
0
 internal PgpUser(PgpUser user, PgpKey publicKey)
 {
     this.userPacket = user.userPacket;
     //this.publicKey = publicKey;
     this.selfCertifications   = new List <PgpCertification>();
     this.otherCertifications  = new List <PgpCertification>();
     this.revocationSignatures = new List <PgpCertification>();
     foreach (var certification in user.selfCertifications)
     {
         this.selfCertifications.Add(new PgpCertification(certification.Signature, userPacket, publicKey));
     }
     foreach (var certification in user.otherCertifications)
     {
         this.otherCertifications.Add(new PgpCertification(certification.Signature, userPacket, publicKey));
     }
     foreach (var certification in user.revocationSignatures)
     {
         this.revocationSignatures.Add(new PgpCertification(certification.Signature, userPacket, publicKey));
     }
 }
Example #4
0
        /// <summary>Remove a certification associated with a given user attributes on a key.</summary>
        /// <param name="key">The key the certifications are to be removed from.</param>
        /// <param name="userAttributes">The user attributes that the certfication is to be removed from.</param>
        /// <param name="certification">The certification to be removed.</param>
        /// <returns>The re-certified key, or null if the certification was not found.</returns>
        public static TKey?RemoveCertification <TKey>(
            TKey key,
            PgpUserAttributes userAttributes,
            PgpCertification certification)
            where TKey : PgpKey
        {
            Debug.Assert(certification.PublicKey.KeyId == key.KeyId);

            for (int i = 0; i < key.ids.Count; i++)
            {
                if (key.ids[i].UserAttributes?.Equals(userAttributes) == true)
                {
                    var returnKey = (TKey)key.CreateMutableCopy();
                    returnKey.ids[i] = PgpUser.RemoveCertification(returnKey.ids[i], returnKey, certification);
                    return(returnKey);
                }
            }

            return(null);
        }
Example #5
0
        /// <summary>Add a certification for the given UserAttributeSubpackets to the given public key.</summary>
        /// <param name="key">The key the certification is to be added to.</param>
        /// <param name="userAttributes">The attributes the certification is associated with.</param>
        /// <param name="certification">The new certification.</param>
        /// <returns>The re-certified key.</returns>
        public static TKey AddCertification <TKey>(
            TKey key,
            PgpUserAttributes userAttributes,
            PgpCertification certification)
            where TKey : PgpKey
        {
            var returnKey = (TKey)key.CreateMutableCopy();

            Debug.Assert(certification.PublicKey.KeyId == key.KeyId);

            for (int i = 0; i < returnKey.ids.Count; i++)
            {
                if (returnKey.ids[i].UserAttributes?.Equals(userAttributes) == true)
                {
                    returnKey.ids[i] = PgpUser.AddCertification(returnKey.ids[i], returnKey, certification.Signature);
                    return(returnKey);
                }
            }

            returnKey.ids.Add(new PgpUser(new UserAttributePacket(userAttributes.ToSubpacketArray()), returnKey, certification.Signature));
            return(returnKey);
        }
Example #6
0
        /// <summary>Add a certification for an id to the given public key.</summary>
        /// <param name="key">The key the certification is to be added to.</param>
        /// <param name="id">The ID the certification is associated with.</param>
        /// <param name="certification">The new certification.</param>
        /// <returns>The re-certified key.</returns>
        public static TKey AddCertification <TKey>(
            TKey key,
            string id,
            PgpCertification certification)
            where TKey : PgpKey
        {
            var returnKey = (TKey)key.CreateMutableCopy();

            Debug.Assert(certification.PublicKey.KeyId == key.KeyId);

            for (int i = 0; i < returnKey.ids.Count; i++)
            {
                if (returnKey.ids[i].UserId?.Equals(id) == true)
                {
                    returnKey.ids[i] = PgpUser.AddCertification(returnKey.ids[i], returnKey, certification.Signature);
                    return(returnKey);
                }
            }

            returnKey.ids.Add(new PgpUser(new UserIdPacket(id), returnKey, certification.Signature));
            return(returnKey);
        }