Container for a list of user attribute subpackets.
Inheritance: IPgpUserAttributeSubpacketVector
コード例 #1
0
        public override bool Equals(
            object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            PgpUserAttributeSubpacketVector other = obj as PgpUserAttributeSubpacketVector;

            if (other == null)
            {
                return(false);
            }

            if (other.packets.Length != packets.Length)
            {
                return(false);
            }

            for (int i = 0; i != packets.Length; i++)
            {
                if (!other.packets[i].Equals(packets[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Verify the signature as certifying the passed in public key as associated
        /// with the passed in user attributes.
        /// </summary>
        /// <param name="userAttributes">User attributes the key was stored under.</param>
        /// <param name="key">The key to be verified.</param>
        /// <returns>True, if the signature matches, false otherwise.</returns>
        public bool VerifyCertification(
            PgpUserAttributeSubpacketVector userAttributes,
            PgpPublicKey key)
        {
            UpdateWithPublicKey(key);

            //
            // hash in the userAttributes
            //
            try
            {
                MemoryStream bOut = new MemoryStream();
                foreach (UserAttributeSubpacket packet in userAttributes.ToSubpacketArray())
                {
                    packet.Encode(bOut);
                }
                UpdateWithIdData(0xd1, bOut.ToArray());
            }
            catch (IOException e)
            {
                throw new PgpException("cannot encode subpacket array", e);
            }

            this.Update(sigPck.GetSignatureTrailer());

            return(sig.VerifySignature(this.GetSignature()));
        }
コード例 #3
0
        /// <summary>Generate a certification for the passed in userAttributes.</summary>
        /// <param name="userAttributes">The ID we are certifying against the public key.</param>
        /// <param name="pubKey">The key we are certifying against the ID.</param>
        /// <returns>The certification.</returns>
        public PgpSignature GenerateCertification(
            PgpUserAttributeSubpacketVector userAttributes,
            PgpPublicKey pubKey)
        {
            UpdateWithPublicKey(pubKey);

            //
            // hash in the attributes
            //
            try
            {
                MemoryStream bOut = new MemoryStream();
                foreach (UserAttributeSubpacket packet in userAttributes.ToSubpacketArray())
                {
                    packet.Encode(bOut);
                }
                UpdateWithIdData(0xd1, bOut.ToArray());
            }
            catch (IOException e)
            {
                throw new PgpException("cannot encode subpacket array", e);
            }

            return(this.Generate());
        }
コード例 #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 PgpPublicKey RemoveCertification(
     PgpPublicKey key,
     PgpUserAttributeSubpacketVector userAttributes,
     PgpSignature certification)
 {
     return(RemoveCert(key, userAttributes, certification));
 }
コード例 #5
0
        public void Encode(
            Stream outStr)
        {
            BcpgOutputStream bcpgOut = BcpgOutputStream.Wrap(outStr);

            bcpgOut.WritePacket(secret);
            if (pub.trustPk != null)
            {
                bcpgOut.WritePacket(pub.trustPk);
            }

            if (pub.subSigs == null) // is not a sub key
            {
                foreach (PgpSignature keySig in pub.keySigs)
                {
                    keySig.Encode(bcpgOut);
                }

                for (int i = 0; i != pub.ids.Count; i++)
                {
                    object pubID = pub.ids[i];
                    if (pubID is string)
                    {
                        string id = (string)pubID;
                        bcpgOut.WritePacket(new UserIdPacket(id));
                    }
                    else
                    {
                        PgpUserAttributeSubpacketVector v = (PgpUserAttributeSubpacketVector)pubID;
                        bcpgOut.WritePacket(new UserAttributePacket(v.ToSubpacketArray()));
                    }

                    if (pub.idTrusts[i] != null)
                    {
                        bcpgOut.WritePacket((ContainedPacket)pub.idTrusts[i]);
                    }

                    foreach (PgpSignature sig in (IList)pub.idSigs[i])
                    {
                        sig.Encode(bcpgOut);
                    }
                }
            }
            else
            {
                foreach (PgpSignature subSig in pub.subSigs)
                {
                    subSig.Encode(bcpgOut);
                }
            }

            // TODO Check that this is right/necessary
            //bcpgOut.Finish();
        }
コード例 #6
0
 public global::System.Collections.IEnumerable GetSignaturesForUserAttribute(PgpUserAttributeSubpacketVector userAttributes)
 {
     for (int i = 0; i != ((global::System.Collections.ICollection)ids).get_Count(); i++)
     {
         if (userAttributes.Equals(ids.get_Item(i)))
         {
             return(new EnumerableProxy((global::System.Collections.IEnumerable)(global::System.Collections.IList) idSigs.get_Item(i)));
         }
     }
     return(null);
 }
コード例 #7
0
        /// <summary>Allows enumeration of signatures associated with the passed in user attributes.</summary>
        /// <param name="userAttributes">The vector of user attributes to be matched.</param>
        /// <returns>An <c>IEnumerable</c> of <c>PgpSignature</c> objects.</returns>
        public IEnumerable GetSignaturesForUserAttribute(
            PgpUserAttributeSubpacketVector userAttributes)
        {
            for (int i = 0; i != ids.Count; i++)
            {
                if (userAttributes.Equals(ids[i]))
                {
                    return(new EnumerableProxy((IList)idSigs[i]));
                }
            }

            return(null);
        }
コード例 #8
0
        public void Encode(
            Stream outStr)
        {
            BcpgOutputStream bcpgOut = BcpgOutputStream.Wrap(outStr);

            bcpgOut.WritePacket(publicPk);
            if (trustPk != null)
            {
                bcpgOut.WritePacket(trustPk);
            }

            if (subSigs == null)                // not a sub-key
            {
                foreach (PgpSignature keySig in keySigs)
                {
                    keySig.Encode(bcpgOut);
                }

                for (int i = 0; i != ids.Count; i++)
                {
                    if (ids[i] is string)
                    {
                        string id = (string)ids[i];

                        bcpgOut.WritePacket(new UserIdPacket(id));
                    }
                    else
                    {
                        PgpUserAttributeSubpacketVector v = (PgpUserAttributeSubpacketVector)ids[i];
                        bcpgOut.WritePacket(new UserAttributePacket(v.ToSubpacketArray()));
                    }

                    if (idTrusts[i] != null)
                    {
                        bcpgOut.WritePacket((ContainedPacket)idTrusts[i]);
                    }

                    foreach (PgpSignature sig in (IList)idSigs[i])
                    {
                        sig.Encode(bcpgOut);
                    }
                }
            }
            else
            {
                foreach (PgpSignature subSig in subSigs)
                {
                    subSig.Encode(bcpgOut);
                }
            }
        }
コード例 #9
0
 public PgpSignature GenerateCertification(PgpUserAttributeSubpacketVector userAttributes, PgpPublicKey pubKey)
 {
     //IL_0007: Unknown result type (might be due to invalid IL or missing references)
     //IL_000d: Expected O, but got Unknown
     //IL_0046: Expected O, but got Unknown
     UpdateWithPublicKey(pubKey);
     try
     {
         MemoryStream             val   = new MemoryStream();
         UserAttributeSubpacket[] array = userAttributes.ToSubpacketArray();
         foreach (UserAttributeSubpacket userAttributeSubpacket in array)
         {
             userAttributeSubpacket.Encode((Stream)(object)val);
         }
         UpdateWithIdData(209, val.ToArray());
     }
     catch (IOException val2)
     {
         IOException exception = val2;
         throw new PgpException("cannot encode subpacket array", (global::System.Exception)(object) exception);
     }
     return(Generate());
 }
コード例 #10
0
		/// <summary>Generate a certification for the passed in userAttributes.</summary>
		/// <param name="userAttributes">The ID we are certifying against the public key.</param>
		/// <param name="pubKey">The key we are certifying against the ID.</param>
		/// <returns>The certification.</returns>
		public PgpSignature GenerateCertification(
			PgpUserAttributeSubpacketVector	userAttributes,
			PgpPublicKey					pubKey)
		{
			UpdateWithPublicKey(pubKey);

			//
			// hash in the attributes
			//
			try
			{
				MemoryStream bOut = new MemoryStream();
				foreach (UserAttributeSubpacket packet in userAttributes.ToSubpacketArray())
				{
					packet.Encode(bOut);
				}
				UpdateWithIdData(0xd1, bOut.ToArray());
			}
			catch (IOException e)
			{
				throw new PgpException("cannot encode subpacket array", e);
			}

			return this.Generate();
		}
コード例 #11
0
        public static PgpPublicKey RemoveCertification(PgpPublicKey key, PgpSignature certification)
        {
            PgpPublicKey pgpPublicKey = new PgpPublicKey(key);

            global::System.Collections.IList list = ((pgpPublicKey.subSigs != null) ? pgpPublicKey.subSigs : pgpPublicKey.keySigs);
            int  num  = list.IndexOf((object)certification);
            bool flag = num >= 0;

            if (flag)
            {
                list.RemoveAt(num);
            }
            else
            {
                {
                    global::System.Collections.IEnumerator enumerator = key.GetUserIds().GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            string id = (string)enumerator.get_Current();
                            {
                                global::System.Collections.IEnumerator enumerator2 = key.GetSignaturesForId(id).GetEnumerator();
                                try
                                {
                                    while (enumerator2.MoveNext())
                                    {
                                        object current = enumerator2.get_Current();
                                        if (certification == current)
                                        {
                                            flag         = true;
                                            pgpPublicKey = RemoveCertification(pgpPublicKey, id, certification);
                                        }
                                    }
                                }
                                finally
                                {
                                    global::System.IDisposable disposable2 = enumerator2 as global::System.IDisposable;
                                    if (disposable2 != null)
                                    {
                                        disposable2.Dispose();
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                if (!flag)
                {
                    global::System.Collections.IEnumerator enumerator = key.GetUserAttributes().GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            PgpUserAttributeSubpacketVector userAttributes = (PgpUserAttributeSubpacketVector)enumerator.get_Current();
                            {
                                global::System.Collections.IEnumerator enumerator2 = key.GetSignaturesForUserAttribute(userAttributes).GetEnumerator();
                                try
                                {
                                    while (enumerator2.MoveNext())
                                    {
                                        object current2 = enumerator2.get_Current();
                                        if (certification == current2)
                                        {
                                            flag         = true;
                                            pgpPublicKey = RemoveCertification(pgpPublicKey, userAttributes, certification);
                                        }
                                    }
                                }
                                finally
                                {
                                    global::System.IDisposable disposable4 = enumerator2 as global::System.IDisposable;
                                    if (disposable4 != null)
                                    {
                                        disposable4.Dispose();
                                    }
                                }
                            }
                        }
                        return(pgpPublicKey);
                    }
                    finally
                    {
                        global::System.IDisposable disposable3 = enumerator as global::System.IDisposable;
                        if (disposable3 != null)
                        {
                            disposable3.Dispose();
                        }
                    }
                }
            }
            return(pgpPublicKey);
        }
コード例 #12
0
        public void Encode(Stream outStr)
        {
            BcpgOutputStream bcpgOutputStream = BcpgOutputStream.Wrap(outStr);

            bcpgOutputStream.WritePacket(publicPk);
            if (trustPk != null)
            {
                bcpgOutputStream.WritePacket(trustPk);
            }
            global::System.Collections.IEnumerator enumerator;
            if (subSigs == null)
            {
                {
                    enumerator = ((global::System.Collections.IEnumerable)keySigs).GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            PgpSignature pgpSignature = (PgpSignature)enumerator.get_Current();
                            pgpSignature.Encode((Stream)(object)bcpgOutputStream);
                        }
                    }
                    finally
                    {
                        global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                for (int i = 0; i != ((global::System.Collections.ICollection)ids).get_Count(); i++)
                {
                    if (ids.get_Item(i) is string)
                    {
                        string id = (string)ids.get_Item(i);
                        bcpgOutputStream.WritePacket(new UserIdPacket(id));
                    }
                    else
                    {
                        PgpUserAttributeSubpacketVector pgpUserAttributeSubpacketVector = (PgpUserAttributeSubpacketVector)ids.get_Item(i);
                        bcpgOutputStream.WritePacket(new UserAttributePacket(pgpUserAttributeSubpacketVector.ToSubpacketArray()));
                    }
                    if (idTrusts.get_Item(i) != null)
                    {
                        bcpgOutputStream.WritePacket((ContainedPacket)idTrusts.get_Item(i));
                    }
                    {
                        enumerator = ((global::System.Collections.IEnumerable)(global::System.Collections.IList) idSigs.get_Item(i)).GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                PgpSignature pgpSignature2 = (PgpSignature)enumerator.get_Current();
                                pgpSignature2.Encode((Stream)(object)bcpgOutputStream);
                            }
                        }
                        finally
                        {
                            global::System.IDisposable disposable2 = enumerator as global::System.IDisposable;
                            if (disposable2 != null)
                            {
                                disposable2.Dispose();
                            }
                        }
                    }
                }
                return;
            }
            enumerator = ((global::System.Collections.IEnumerable)subSigs).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    PgpSignature pgpSignature3 = (PgpSignature)enumerator.get_Current();
                    pgpSignature3.Encode((Stream)(object)bcpgOutputStream);
                }
            }
            finally
            {
                global::System.IDisposable disposable3 = enumerator as global::System.IDisposable;
                if (disposable3 != null)
                {
                    disposable3.Dispose();
                }
            }
        }
コード例 #13
0
ファイル: PgpSignature.cs プロジェクト: htlp/itextsharp
		/// <summary>
		/// Verify the signature as certifying the passed in public key as associated
		/// with the passed in user attributes.
		/// </summary>
		/// <param name="userAttributes">User attributes the key was stored under.</param>
		/// <param name="key">The key to be verified.</param>
		/// <returns>True, if the signature matches, false otherwise.</returns>
		public bool VerifyCertification(
			PgpUserAttributeSubpacketVector	userAttributes,
			PgpPublicKey					key)
		{
			UpdateWithPublicKey(key);

			//
			// hash in the userAttributes
			//
			try
			{
				MemoryStream bOut = new MemoryStream();
				foreach (UserAttributeSubpacket packet in userAttributes.ToSubpacketArray())
				{
					packet.Encode(bOut);
				}
				UpdateWithIdData(0xd1, bOut.ToArray());
			}
			catch (IOException e)
			{
				throw new PgpException("cannot encode subpacket array", e);
			}

			this.Update(sigPck.GetSignatureTrailer());

			return sig.VerifySignature(this.GetSignature());
		}
コード例 #14
0
 /// <summary>
 /// Remove any certifications associated with a user attribute subpacket on a key.
 /// </summary>
 /// <param name="key">The key the certifications are to be removed from.</param>
 /// <param name="userAttributes">The attributes to be removed.</param>
 /// <returns>
 /// The re-certified key, or null if the user attribute subpacket was not found on the key.
 /// </returns>
 public static IPgpPublicKey RemoveCertification(IPgpPublicKey key, PgpUserAttributeSubpacketVector userAttributes)
 {
     return(RemoveCert(key, userAttributes));
 }
コード例 #15
0
 /// <summary>
 /// Remove any certifications associated with a user attribute subpacket on a key.
 /// </summary>
 /// <param name="key">The key the certifications are to be removed from.</param>
 /// <param name="userAttributes">The attributes to be removed.</param>
 /// <returns>
 /// The re-certified key, or null if the user attribute subpacket was not found on the key.
 /// </returns>
 public static IPgpPublicKey RemoveCertification(IPgpPublicKey key, PgpUserAttributeSubpacketVector userAttributes)
 {
     return RemoveCert(key, userAttributes);
 }
コード例 #16
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 PgpPublicKey RemoveCertification(
			PgpPublicKey					key,
			PgpUserAttributeSubpacketVector	userAttributes,
			PgpSignature					certification)
		{
			return RemoveCert(key, userAttributes, certification);
		}
コード例 #17
0
		/// <summary>Allows enumeration of signatures associated with the passed in user attributes.</summary>
		/// <param name="userAttributes">The vector of user attributes to be matched.</param>
		/// <returns>An <c>IEnumerable</c> of <c>PgpSignature</c> objects.</returns>
        public IEnumerable GetSignaturesForUserAttribute(
            PgpUserAttributeSubpacketVector userAttributes)
        {
            for (int i = 0; i != ids.Count; i++)
            {
                if (userAttributes.Equals(ids[i]))
                {
                    return new EnumerableProxy((IList) idSigs[i]);
                }
            }

			return null;
        }