private SignatureSubpacket[] insertSubpacket(SignatureSubpacket[] packets, SignatureSubpacket subpacket)
 {
     SignatureSubpacket[] array = new SignatureSubpacket[packets.Length + 1];
     array[0] = subpacket;
     ((global::System.Array)packets).CopyTo((global::System.Array)array, 1);
     return(array);
 }
Beispiel #2
0
        /**
         * Return all signature subpackets of the passed in type.
         * @param type subpacket type code
         * @return an array of zero or more matching subpackets.
         */
        public SignatureSubpacket[] GetSubpackets(
            SignatureSubpacketTag type)
        {
            int count = 0;

            for (int i = 0; i < packets.Length; ++i)
            {
                if (packets[i].SubpacketType == type)
                {
                    ++count;
                }
            }

            SignatureSubpacket[] result = new SignatureSubpacket[count];

            int pos = 0;

            for (int i = 0; i < packets.Length; ++i)
            {
                if (packets[i].SubpacketType == type)
                {
                    result[pos++] = packets[i];
                }
            }

            return(result);
        }
		/**
		 * Return all signature subpackets of the passed in type.
		 * @param type subpacket type code
		 * @return an array of zero or more matching subpackets.
		 */
		public SignatureSubpacket[] GetSubpackets(
			SignatureSubpacketTag type)
		{
            int count = 0;
            for (int i = 0; i < packets.Length; ++i)
            {
                if (packets[i].SubpacketType == type)
                {
                    ++count;
                }
            }

            SignatureSubpacket[] result = new SignatureSubpacket[count];

            int pos = 0;
            for (int i = 0; i < packets.Length; ++i)
            {
                if (packets[i].SubpacketType == type)
                {
                    result[pos++] = packets[i];
                }
            }

            return result;
        }
Beispiel #4
0
 private SignatureSubpacket[] insertSubpacket(SignatureSubpacket[] packets, SignatureSubpacket subpacket)
 {
     SignatureSubpacket[] array = new SignatureSubpacket[packets.Length + 1];
     array[0] = subpacket;
     packets.CopyTo(array, 1);
     return(array);
 }
        /// <summary>
        /// Inserts the subpacket.
        /// </summary>
        /// <param name="packets">The packets.</param>
        /// <param name="subpacket">The subpacket.</param>
        /// <returns></returns>
        private static SignatureSubpacket[] InsertSubpacket(ISignatureSubpacket[] packets, SignatureSubpacket subpacket)
        {
            var tmp = new SignatureSubpacket[packets.Length + 1];

            tmp[0] = subpacket;
            packets.CopyTo(tmp, 1);
            return(tmp);
        }
Beispiel #6
0
 public PgpSignatureSubpacketVector Generate()
 {
     SignatureSubpacket[] array = new SignatureSubpacket[list.Count];
     for (int i = 0; i < list.Count; i++)
     {
         array[i] = (SignatureSubpacket)list[i];
     }
     return(new PgpSignatureSubpacketVector(array));
 }
Beispiel #7
0
 private SignatureSubpacket[] insertSubpacket(
     SignatureSubpacket[]    packets,
     SignatureSubpacket subpacket)
 {
     SignatureSubpacket[] tmp = new SignatureSubpacket[packets.Length + 1];
     tmp[0] = subpacket;
     packets.CopyTo(tmp, 1);
     return(tmp);
 }
Beispiel #8
0
 public PgpSignatureSubpacketVector Generate()
 {
     SignatureSubpacket[] a = new SignatureSubpacket[list.Count];
     for (int i = 0; i < list.Count; ++i)
     {
         a[i] = (SignatureSubpacket)list[i];
     }
     return(new PgpSignatureSubpacketVector(a));
 }
 public PgpSignatureSubpacketVector Generate()
 {
     SignatureSubpacket[] array = new SignatureSubpacket[((global::System.Collections.ICollection)list).get_Count()];
     for (int i = 0; i < ((global::System.Collections.ICollection)list).get_Count(); i++)
     {
         array[i] = (SignatureSubpacket)list.get_Item(i);
     }
     return(new PgpSignatureSubpacketVector(array));
 }
Beispiel #10
0
    public Features GetFeatures()
    {
        SignatureSubpacket subpacket = GetSubpacket(SignatureSubpacketTag.Features);

        if (subpacket == null)
        {
            return(null);
        }
        return(new Features(subpacket.IsCritical(), subpacket.IsLongLength(), subpacket.GetData()));
    }
Beispiel #11
0
    public string GetSignerUserId()
    {
        SignatureSubpacket subpacket = GetSubpacket(SignatureSubpacketTag.SignerUserId);

        if (subpacket != null)
        {
            return(((SignerUserId)subpacket).GetId());
        }
        return(null);
    }
Beispiel #12
0
    public int GetKeyFlags()
    {
        SignatureSubpacket subpacket = GetSubpacket(SignatureSubpacketTag.KeyFlags);

        if (subpacket != null)
        {
            return(((KeyFlags)subpacket).Flags);
        }
        return(0);
    }
Beispiel #13
0
    public int[] GetPreferredCompressionAlgorithms()
    {
        SignatureSubpacket subpacket = GetSubpacket(SignatureSubpacketTag.PreferredCompressionAlgorithms);

        if (subpacket != null)
        {
            return(((PreferredAlgorithms)subpacket).GetPreferences());
        }
        return(null);
    }
Beispiel #14
0
    public long GetKeyExpirationTime()
    {
        SignatureSubpacket subpacket = GetSubpacket(SignatureSubpacketTag.KeyExpireTime);

        if (subpacket != null)
        {
            return(((KeyExpirationTime)subpacket).Time);
        }
        return(0L);
    }
Beispiel #15
0
    public DateTime GetSignatureCreationTime()
    {
        SignatureSubpacket subpacket = GetSubpacket(SignatureSubpacketTag.CreationTime);

        if (subpacket == null)
        {
            throw new PgpException("SignatureCreationTime not available");
        }
        return(((SignatureCreationTime)subpacket).GetTime());
    }
Beispiel #16
0
    public long GetIssuerKeyId()
    {
        SignatureSubpacket subpacket = GetSubpacket(SignatureSubpacketTag.IssuerKeyId);

        if (subpacket != null)
        {
            return(((IssuerKeyId)subpacket).KeyId);
        }
        return(0L);
    }
Beispiel #17
0
        public Features GetFeatures()
        {
            SignatureSubpacket p = this.GetSubpacket(SignatureSubpacketTag.Features);

            if (p == null)
            {
                return(null);
            }

            return(new Features(p.IsCritical(), p.IsLongLength(), p.GetData()));
        }
Beispiel #18
0
    public SignatureSubpacket[] GetSubpackets(SignatureSubpacketTag type)
    {
        int num = 0;

        for (int i = 0; i < packets.Length; i++)
        {
            if (packets[i].SubpacketType == type)
            {
                num++;
            }
        }
        SignatureSubpacket[] array = new SignatureSubpacket[num];
        int num2 = 0;

        for (int j = 0; j < packets.Length; j++)
        {
            if (packets[j].SubpacketType == type)
            {
                array[num2++] = packets[j];
            }
        }
        return(array);
    }
Beispiel #19
0
        public string GetSignerUserId()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.SignerUserId);

            return(p == null ? null : ((SignerUserId)p).GetId());
        }
Beispiel #20
0
        public int GetKeyFlags()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.KeyFlags);

            return(p == null ? 0 : ((KeyFlags)p).Flags);
        }
Beispiel #21
0
        public int[] GetPreferredCompressionAlgorithms()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.PreferredCompressionAlgorithms);

            return(p == null ? null : ((PreferredAlgorithms)p).GetPreferences());
        }
Beispiel #22
0
        /// <summary>
        /// Return the number of seconds a key is valid for after its creation date.
        /// A value of zero means the key never expires.
        /// </summary>
        /// <returns>Seconds a signature is valid for.</returns>
        public long GetKeyExpirationTime()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.KeyExpireTime);

            return(p == null ? 0 : ((KeyExpirationTime)p).Time);
        }
Beispiel #23
0
        public int[] GetPreferredSymmetricAlgorithms()
        {
            SignatureSubpacket p = this.GetSubpacket(SignatureSubpacketTag.PreferredSymmetricAlgorithms);

            return(p == null ? null : ((PreferredAlgorithms)p).GetPreferences());
        }
Beispiel #24
0
        /// <summary>
        /// Return the number of seconds a signature is valid for after its creation date.
        /// A value of zero means the signature never expires.
        /// </summary>
        /// <returns>Seconds a signature is valid for.</returns>
        public long GetSignatureExpirationTime()
        {
            SignatureSubpacket p = this.GetSubpacket(SignatureSubpacketTag.ExpireTime);

            return(p == null ? 0 : ((SignatureExpirationTime)p).Time);
        }
		public PgpSignatureSubpacketVector Generate()
        {
            SignatureSubpacket[] a = new SignatureSubpacket[list.Count];
            for (int i = 0; i < list.Count; ++i)
            {
                a[i] = (SignatureSubpacket)list[i];
            }
            return new PgpSignatureSubpacketVector(a);
        }
 /// <summary>
 /// Inserts the subpacket.
 /// </summary>
 /// <param name="packets">The packets.</param>
 /// <param name="subpacket">The subpacket.</param>
 /// <returns></returns>
 private static SignatureSubpacket[] InsertSubpacket(ISignatureSubpacket[] packets, SignatureSubpacket subpacket)
 {
     var tmp = new SignatureSubpacket[packets.Length + 1];
     tmp[0] = subpacket;
     packets.CopyTo(tmp, 1);
     return tmp;
 }
Beispiel #27
0
		private PgpSignatureSubpacketVector createSubpacketVector(SignatureSubpacket[] pcks)
		{
			return pcks == null ? null : new PgpSignatureSubpacketVector(pcks);
		}
Beispiel #28
0
    internal SignaturePacket(BcpgInputStream bcpgIn)
    {
        version = bcpgIn.ReadByte();
        if (version == 3 || version == 2)
        {
            bcpgIn.ReadByte();
            signatureType = bcpgIn.ReadByte();
            creationTime  = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16) | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000;
            keyId        |= (long)bcpgIn.ReadByte() << 56;
            keyId        |= (long)bcpgIn.ReadByte() << 48;
            keyId        |= (long)bcpgIn.ReadByte() << 40;
            keyId        |= (long)bcpgIn.ReadByte() << 32;
            keyId        |= (long)bcpgIn.ReadByte() << 24;
            keyId        |= (long)bcpgIn.ReadByte() << 16;
            keyId        |= (long)bcpgIn.ReadByte() << 8;
            keyId        |= (uint)bcpgIn.ReadByte();
            keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
            hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
        }
        else
        {
            if (version != 4)
            {
                throw new Exception("unsupported version: " + version);
            }
            signatureType = bcpgIn.ReadByte();
            keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
            hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
            int    num    = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            byte[] buffer = new byte[num];
            bcpgIn.ReadFully(buffer);
            SignatureSubpacketsParser signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer, writable: false));
            IList list = Platform.CreateArrayList();
            SignatureSubpacket value;
            while ((value = signatureSubpacketsParser.ReadPacket()) != null)
            {
                list.Add(value);
            }
            hashedData = new SignatureSubpacket[list.Count];
            for (int i = 0; i != hashedData.Length; i++)
            {
                SignatureSubpacket signatureSubpacket = (SignatureSubpacket)list[i];
                if (signatureSubpacket is IssuerKeyId)
                {
                    keyId = ((IssuerKeyId)signatureSubpacket).KeyId;
                }
                else if (signatureSubpacket is SignatureCreationTime)
                {
                    creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime());
                }
                hashedData[i] = signatureSubpacket;
            }
            int    num2    = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            byte[] buffer2 = new byte[num2];
            bcpgIn.ReadFully(buffer2);
            signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer2, writable: false));
            list.Clear();
            while ((value = signatureSubpacketsParser.ReadPacket()) != null)
            {
                list.Add(value);
            }
            unhashedData = new SignatureSubpacket[list.Count];
            for (int j = 0; j != unhashedData.Length; j++)
            {
                SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list[j];
                if (signatureSubpacket2 is IssuerKeyId)
                {
                    keyId = ((IssuerKeyId)signatureSubpacket2).KeyId;
                }
                unhashedData[j] = signatureSubpacket2;
            }
        }
        fingerprint = new byte[2];
        bcpgIn.ReadFully(fingerprint);
        switch (keyAlgorithm)
        {
        case PublicKeyAlgorithmTag.RsaGeneral:
        case PublicKeyAlgorithmTag.RsaSign:
        {
            MPInteger mPInteger8 = new MPInteger(bcpgIn);
            signature = new MPInteger[1]
            {
                mPInteger8
            };
            return;
        }

        case PublicKeyAlgorithmTag.Dsa:
        {
            MPInteger mPInteger6 = new MPInteger(bcpgIn);
            MPInteger mPInteger7 = new MPInteger(bcpgIn);
            signature = new MPInteger[2]
            {
                mPInteger6,
                mPInteger7
            };
            return;
        }

        case PublicKeyAlgorithmTag.ElGamalEncrypt:
        case PublicKeyAlgorithmTag.ElGamalGeneral:
        {
            MPInteger mPInteger3 = new MPInteger(bcpgIn);
            MPInteger mPInteger4 = new MPInteger(bcpgIn);
            MPInteger mPInteger5 = new MPInteger(bcpgIn);
            signature = new MPInteger[3]
            {
                mPInteger3,
                mPInteger4,
                mPInteger5
            };
            return;
        }

        case PublicKeyAlgorithmTag.ECDsa:
        {
            MPInteger mPInteger  = new MPInteger(bcpgIn);
            MPInteger mPInteger2 = new MPInteger(bcpgIn);
            signature = new MPInteger[2]
            {
                mPInteger,
                mPInteger2
            };
            return;
        }
        }
        if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
        {
            signature = null;
            MemoryStream memoryStream = new MemoryStream();
            int          num3;
            while ((num3 = bcpgIn.ReadByte()) >= 0)
            {
                memoryStream.WriteByte((byte)num3);
            }
            signatureEncoding = memoryStream.ToArray();
            return;
        }
        throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
    }
Beispiel #29
0
        public long GetIssuerKeyId()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.IssuerKeyId);

            return(p == null ? 0 : ((IssuerKeyId)p).KeyId);
        }
		private bool packetPresent(
			SignatureSubpacket[]	packets,
			SignatureSubpacketTag	type)
		{
			for (int i = 0; i != packets.Length; i++)
			{
				if (packets[i].SubpacketType == type)
				{
					return true;
				}
			}

			return false;
		}
		private SignatureSubpacket[] insertSubpacket(
			SignatureSubpacket[]	packets,
			SignatureSubpacket		subpacket)
		{
			SignatureSubpacket[] tmp = new SignatureSubpacket[packets.Length + 1];
			tmp[0] = subpacket;
			packets.CopyTo(tmp, 1);
			return tmp;
		}
		internal PgpSignatureSubpacketVector(
            SignatureSubpacket[] packets)
        {
            this.packets = packets;
        }