ToSubpacketArray() private method

private ToSubpacketArray ( ) : UserAttributeSubpacket[]
return UserAttributeSubpacket[]
Example #1
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());
        }
Example #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()));
        }
        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();
        }
        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);
                }
            }
        }
 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());
 }
Example #6
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());
		}
		/// <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();
		}
Example #8
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();
                }
            }
        }