public void TestTstInfo2() { TimeStampTokenInfo tstInfo = getTimeStampTokenInfo(tstInfo2); // // verify // GenTimeAccuracy accuracy = tstInfo.GenTimeAccuracy; Assert.AreEqual(3, accuracy.Seconds); Assert.AreEqual(1, accuracy.Millis); Assert.AreEqual(2, accuracy.Micros); Assert.AreEqual(new BigInteger("23"), tstInfo.SerialNumber); Assert.AreEqual(1130833785000L, DateTimeUtilities.DateTimeToUnixMs(tstInfo.GenTime)); Assert.AreEqual("1.2.3", tstInfo.Policy); Assert.AreEqual(false, tstInfo.IsOrdered); Assert.AreEqual(tstInfo.Nonce, BigInteger.ValueOf(100)); Assert.IsTrue(Arrays.AreEqual(Hex.Decode("ffffffffffffffffffffffffffffffffffffffff"), tstInfo.GetMessageImprintDigest())); Assert.IsTrue(Arrays.AreEqual(tstInfo2, tstInfo.GetEncoded())); }
public void TestTstInfo3() { TimeStampTokenInfo tstInfo = getTimeStampTokenInfo(tstInfo3); // // verify // GenTimeAccuracy accuracy = tstInfo.GenTimeAccuracy; Assert.AreEqual(3, accuracy.Seconds); Assert.AreEqual(1, accuracy.Millis); Assert.AreEqual(2, accuracy.Micros); Assert.AreEqual(new BigInteger("23"), tstInfo.SerialNumber); Assert.AreEqual(1130834855000L, DateTimeUtilities.DateTimeToUnixMs(tstInfo.GenTime)); Assert.AreEqual("1.2.3", tstInfo.Policy); Assert.AreEqual(true, tstInfo.IsOrdered); Assert.AreEqual(tstInfo.Nonce, BigInteger.ValueOf(100)); Assert.AreEqual(TspAlgorithms.Sha1, tstInfo.MessageImprintAlgOid); Assert.IsTrue(Arrays.AreEqual(new byte[20], tstInfo.GetMessageImprintDigest())); Assert.IsTrue(Arrays.AreEqual(tstInfo3, tstInfo.GetEncoded())); }
/// <summary> /// <p> /// Open a literal data packet, returning a stream to store the data inside the packet. /// </p> /// <p> /// The stream created can be closed off by either calling Close() /// on the stream or Close() on the generator. Closing the returned /// stream does not close off the Stream parameter <c>outStr</c>. /// </p> /// </summary> /// <param name="outStr">The stream we want the packet in.</param> /// <param name="format">The format we are using.</param> /// <param name="name">The name of the 'file'.</param> /// <param name="length">The length of the data we will write.</param> /// <param name="modificationTime">The time of last modification we want stored.</param> public Stream Open( Stream outStr, char format, string name, long length, DateTime modificationTime) { if (pkOut != null) { throw new InvalidOperationException("generator already in open state"); } if (outStr == null) { throw new ArgumentNullException("outStr"); } // Do this first, since it might throw an exception long unixMs = DateTimeUtilities.DateTimeToUnixMs(modificationTime); pkOut = new BcpgOutputStream(outStr, PacketTag.LiteralData, length + 2 + name.Length + 4, oldFormat); WriteHeader(pkOut, format, name, unixMs); return(new WrappedGeneratorStream(this, pkOut)); }
/// <summary> /// <p> /// Open a literal data packet, returning a stream to store the data inside the packet, /// as an indefinite length stream. The stream is written out as a series of partial /// packets with a chunk size determined by the size of the passed in buffer. /// </p> /// <p> /// The stream created can be closed off by either calling Close() /// on the stream or Close() on the generator. Closing the returned /// stream does not close off the Stream parameter <c>outStr</c>. /// </p> /// <p> /// <b>Note</b>: if the buffer is not a power of 2 in length only the largest power of 2 /// bytes worth of the buffer will be used.</p> /// </summary> /// <param name="outStr">The stream we want the packet in.</param> /// <param name="format">The format we are using.</param> /// <param name="name">The name of the 'file'.</param> /// <param name="modificationTime">The time of last modification we want stored.</param> /// <param name="buffer">The buffer to use for collecting data to put into chunks.</param> public Stream Open( Stream outStr, char format, string name, DateTime modificationTime, byte[] buffer) { if (pkOut != null) { throw new InvalidOperationException("generator already in open state"); } if (outStr == null) { throw new ArgumentNullException("outStr"); } // Do this first, since it might throw an exception long unixMs = DateTimeUtilities.DateTimeToUnixMs(modificationTime); byte[] encName = Strings.ToUtf8ByteArray(name); pkOut = new BcpgOutputStream(outStr, PacketTag.LiteralData, buffer); WriteHeader(pkOut, format, encName, unixMs); return(new WrappedGeneratorStream(this, pkOut)); }
public PublicKeyPacket(PublicKeyAlgorithmTag algorithm, DateTime time, IBcpgKey key) { version = 4; this.time = DateTimeUtilities.DateTimeToUnixMs(time) / 1000; this.algorithm = algorithm; this.key = key; }
public void TestTstInfo1() { TimeStampTokenInfo tstInfo = getTimeStampTokenInfo(tstInfo1); // // verify // GenTimeAccuracy accuracy = tstInfo.GenTimeAccuracy; Assert.IsNull(accuracy); Assert.AreEqual(new BigInteger("24"), tstInfo.SerialNumber); Assert.AreEqual(1130833041000L, DateTimeUtilities.DateTimeToUnixMs(tstInfo.GenTime)); Assert.AreEqual("1.2.3", tstInfo.Policy); Assert.AreEqual(false, tstInfo.IsOrdered); Assert.IsNull(tstInfo.Nonce); Assert.AreEqual(TspAlgorithms.Sha1, tstInfo.MessageImprintAlgOid); Assert.IsTrue(Arrays.AreEqual(new byte[20], tstInfo.GetMessageImprintDigest())); Assert.IsTrue(Arrays.AreEqual(tstInfo1, tstInfo.GetEncoded())); }
protected static byte[] TimeToBytes(DateTime time) { var t = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L; var data = new byte[4]; data[0] = (byte)(t >> 24); data[1] = (byte)(t >> 16); data[2] = (byte)(t >> 8); data[3] = (byte)t; return(data); }
private void setCreationTime() { SignatureSubpacket[] array = hashedData; foreach (SignatureSubpacket signatureSubpacket in array) { if (signatureSubpacket is SignatureCreationTime) { creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime()); break; } } }
protected static byte[] TimeToBytes(global::System.DateTime time) { long num = DateTimeUtilities.DateTimeToUnixMs(time) / 1000; return(new byte[4] { (byte)(num >> 24), (byte)(num >> 16), (byte)(num >> 8), (byte)num }); }
private void setCreationTime() { foreach (SignatureSubpacket p in hashedData) { if (p is SignatureCreationTime) { creationTime = DateTimeUtilities.DateTimeToUnixMs( ((SignatureCreationTime)p).GetTime()); break; } } }
private void setCreationTime() { SignatureSubpacket[] array = this.hashedData; for (int i = 0; i < array.Length; i++) { SignatureSubpacket signatureSubpacket = array[i]; if (signatureSubpacket is SignatureCreationTime) { this.creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime()); return; } } }
private void SetCreationTime() { foreach (var data in _hashedData) { var creationTime = data as SignatureCreationTime; if (creationTime == null) { continue; } CreationTime = DateTimeUtilities.DateTimeToUnixMs(creationTime.GetTime()); break; } }
public Stream Open(Stream outStr, char format, string name, long length, DateTime modificationTime) { if (pkOut != null) { throw new InvalidOperationException("generator already in open state"); } if (outStr == null) { throw new ArgumentNullException("outStr"); } long modificationTime2 = DateTimeUtilities.DateTimeToUnixMs(modificationTime); byte[] array = Strings.ToUtf8ByteArray(name); pkOut = new BcpgOutputStream(outStr, PacketTag.LiteralData, length + 2 + array.Length + 4, oldFormat); WriteHeader(pkOut, format, array, modificationTime2); return(new WrappedGeneratorStream(this, pkOut)); }
public Stream Open(Stream outStr, char format, string name, global::System.DateTime modificationTime, byte[] buffer) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (pkOut != null) { throw new InvalidOperationException("generator already in open state"); } if (outStr == null) { throw new ArgumentNullException("outStr"); } long modificationTime2 = DateTimeUtilities.DateTimeToUnixMs(modificationTime); byte[] encName = Strings.ToUtf8ByteArray(name); pkOut = new BcpgOutputStream(outStr, PacketTag.LiteralData, buffer); WriteHeader(pkOut, format, encName, modificationTime2); return((Stream)(object)new WrappedGeneratorStream(this, (Stream)(object)pkOut)); }
private void setCreationTime() { SignatureSubpacket[] array = hashedData; int num = 0; SignatureSubpacket signatureSubpacket; while (true) { if (num < array.Length) { signatureSubpacket = array[num]; if (signatureSubpacket is SignatureCreationTime) { break; } num++; continue; } return; } creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime()); }
internal SignaturePacket(BcpgInputStream bcpgIn) { //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Expected O, but got Unknown //IL_0422: Unknown result type (might be due to invalid IL or missing references) //IL_0429: Expected O, but got Unknown //IL_0464: Unknown result type (might be due to invalid IL or missing references) version = ((Stream)bcpgIn).ReadByte(); if (version == 3 || version == 2) { ((Stream)bcpgIn).ReadByte(); signatureType = ((Stream)bcpgIn).ReadByte(); creationTime = (((long)((Stream)bcpgIn).ReadByte() << 24) | ((long)((Stream)bcpgIn).ReadByte() << 16) | ((long)((Stream)bcpgIn).ReadByte() << 8) | (uint)((Stream)bcpgIn).ReadByte()) * 1000; keyId |= (long)((Stream)bcpgIn).ReadByte() << 56; keyId |= (long)((Stream)bcpgIn).ReadByte() << 48; keyId |= (long)((Stream)bcpgIn).ReadByte() << 40; keyId |= (long)((Stream)bcpgIn).ReadByte() << 32; keyId |= (long)((Stream)bcpgIn).ReadByte() << 24; keyId |= (long)((Stream)bcpgIn).ReadByte() << 16; keyId |= (long)((Stream)bcpgIn).ReadByte() << 8; keyId |= (uint)((Stream)bcpgIn).ReadByte(); keyAlgorithm = (PublicKeyAlgorithmTag)((Stream)bcpgIn).ReadByte(); hashAlgorithm = (HashAlgorithmTag)((Stream)bcpgIn).ReadByte(); } else { if (version != 4) { throw new global::System.Exception(string.Concat((object)"unsupported version: ", (object)version)); } signatureType = ((Stream)bcpgIn).ReadByte(); keyAlgorithm = (PublicKeyAlgorithmTag)((Stream)bcpgIn).ReadByte(); hashAlgorithm = (HashAlgorithmTag)((Stream)bcpgIn).ReadByte(); int num = (((Stream)bcpgIn).ReadByte() << 8) | ((Stream)bcpgIn).ReadByte(); byte[] array = new byte[num]; bcpgIn.ReadFully(array); SignatureSubpacketsParser signatureSubpacketsParser = new SignatureSubpacketsParser((Stream) new MemoryStream(array, false)); global::System.Collections.IList list = Platform.CreateArrayList(); SignatureSubpacket signatureSubpacket; while ((signatureSubpacket = signatureSubpacketsParser.ReadPacket()) != null) { list.Add((object)signatureSubpacket); } hashedData = new SignatureSubpacket[((global::System.Collections.ICollection)list).get_Count()]; for (int i = 0; i != hashedData.Length; i++) { SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list.get_Item(i); if (signatureSubpacket2 is IssuerKeyId) { keyId = ((IssuerKeyId)signatureSubpacket2).KeyId; } else if (signatureSubpacket2 is SignatureCreationTime) { creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket2).GetTime()); } hashedData[i] = signatureSubpacket2; } int num2 = (((Stream)bcpgIn).ReadByte() << 8) | ((Stream)bcpgIn).ReadByte(); byte[] array2 = new byte[num2]; bcpgIn.ReadFully(array2); signatureSubpacketsParser = new SignatureSubpacketsParser((Stream) new MemoryStream(array2, false)); list.Clear(); while ((signatureSubpacket = signatureSubpacketsParser.ReadPacket()) != null) { list.Add((object)signatureSubpacket); } unhashedData = new SignatureSubpacket[((global::System.Collections.ICollection)list).get_Count()]; for (int j = 0; j != unhashedData.Length; j++) { SignatureSubpacket signatureSubpacket3 = (SignatureSubpacket)list.get_Item(j); if (signatureSubpacket3 is IssuerKeyId) { keyId = ((IssuerKeyId)signatureSubpacket3).KeyId; } unhashedData[j] = signatureSubpacket3; } } 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 val = new MemoryStream(); int num3; while ((num3 = ((Stream)bcpgIn).ReadByte()) >= 0) { ((Stream)val).WriteByte((byte)num3); } signatureEncoding = val.ToArray(); return; } throw new IOException(string.Concat((object)"unknown signature key algorithm: ", (object)keyAlgorithm)); }
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); }
internal SignaturePacket(BcpgInputStream bcpgIn) { this.version = bcpgIn.ReadByte(); if (this.version == 3 || this.version == 2) { bcpgIn.ReadByte(); this.signatureType = bcpgIn.ReadByte(); this.creationTime = ((long)bcpgIn.ReadByte() << 24 | (long)bcpgIn.ReadByte() << 16 | (long)bcpgIn.ReadByte() << 8 | (long)((ulong)bcpgIn.ReadByte())) * 1000L; this.keyId |= (long)bcpgIn.ReadByte() << 56; this.keyId |= (long)bcpgIn.ReadByte() << 48; this.keyId |= (long)bcpgIn.ReadByte() << 40; this.keyId |= (long)bcpgIn.ReadByte() << 32; this.keyId |= (long)bcpgIn.ReadByte() << 24; this.keyId |= (long)bcpgIn.ReadByte() << 16; this.keyId |= (long)bcpgIn.ReadByte() << 8; this.keyId |= (long)((ulong)bcpgIn.ReadByte()); this.keyAlgorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte(); this.hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte(); } else { if (this.version != 4) { throw new Exception("unsupported version: " + this.version); } this.signatureType = bcpgIn.ReadByte(); this.keyAlgorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte(); this.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, false)); IList list = Platform.CreateArrayList(); SignatureSubpacket value; while ((value = signatureSubpacketsParser.ReadPacket()) != null) { list.Add(value); } this.hashedData = new SignatureSubpacket[list.Count]; for (int num2 = 0; num2 != this.hashedData.Length; num2++) { SignatureSubpacket signatureSubpacket = (SignatureSubpacket)list[num2]; if (signatureSubpacket is IssuerKeyId) { this.keyId = ((IssuerKeyId)signatureSubpacket).KeyId; } else if (signatureSubpacket is SignatureCreationTime) { this.creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime()); } this.hashedData[num2] = signatureSubpacket; } int num3 = bcpgIn.ReadByte() << 8 | bcpgIn.ReadByte(); byte[] buffer2 = new byte[num3]; bcpgIn.ReadFully(buffer2); signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer2, false)); list.Clear(); while ((value = signatureSubpacketsParser.ReadPacket()) != null) { list.Add(value); } this.unhashedData = new SignatureSubpacket[list.Count]; for (int num4 = 0; num4 != this.unhashedData.Length; num4++) { SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list[num4]; if (signatureSubpacket2 is IssuerKeyId) { this.keyId = ((IssuerKeyId)signatureSubpacket2).KeyId; } this.unhashedData[num4] = signatureSubpacket2; } } this.fingerprint = new byte[2]; bcpgIn.ReadFully(this.fingerprint); PublicKeyAlgorithmTag publicKeyAlgorithmTag = this.keyAlgorithm; switch (publicKeyAlgorithmTag) { case PublicKeyAlgorithmTag.RsaGeneral: case PublicKeyAlgorithmTag.RsaSign: { MPInteger mPInteger = new MPInteger(bcpgIn); this.signature = new MPInteger[] { mPInteger }; return; } case PublicKeyAlgorithmTag.RsaEncrypt: break; default: switch (publicKeyAlgorithmTag) { case PublicKeyAlgorithmTag.ElGamalEncrypt: case PublicKeyAlgorithmTag.ElGamalGeneral: { MPInteger mPInteger2 = new MPInteger(bcpgIn); MPInteger mPInteger3 = new MPInteger(bcpgIn); MPInteger mPInteger4 = new MPInteger(bcpgIn); this.signature = new MPInteger[] { mPInteger2, mPInteger3, mPInteger4 }; return; } case PublicKeyAlgorithmTag.Dsa: { MPInteger mPInteger5 = new MPInteger(bcpgIn); MPInteger mPInteger6 = new MPInteger(bcpgIn); this.signature = new MPInteger[] { mPInteger5, mPInteger6 }; return; } } break; } if (this.keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && this.keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11) { this.signature = null; MemoryStream memoryStream = new MemoryStream(); int num5; while ((num5 = bcpgIn.ReadByte()) >= 0) { memoryStream.WriteByte((byte)num5); } this.signatureEncoding = memoryStream.ToArray(); return; } throw new IOException("unknown signature key algorithm: " + this.keyAlgorithm); }
internal SignaturePacket( BcpgInputStream bcpgIn) { version = bcpgIn.ReadByte(); if (version == 3 || version == 2) { // int l = bcpgIn.ReadByte(); signatureType = bcpgIn.ReadByte(); creationTime = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16) | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000L; 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) { signatureType = bcpgIn.ReadByte(); keyAlgorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte(); hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte(); int hashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte(); byte[] hashed = new byte[hashedLength]; bcpgIn.ReadFully(hashed); // // read the signature sub packet data. // SignatureSubpacketsParser sIn = new SignatureSubpacketsParser( new MemoryStream(hashed, false)); ArrayList v = new ArrayList(); SignatureSubpacket sub; while ((sub = sIn.ReadPacket()) != null) { v.Add(sub); } hashedData = new SignatureSubpacket[v.Count]; for (int i = 0; i != hashedData.Length; i++) { SignatureSubpacket p = (SignatureSubpacket)v[i]; if (p is IssuerKeyId) { keyId = ((IssuerKeyId)p).KeyId; } else if (p is SignatureCreationTime) { creationTime = DateTimeUtilities.DateTimeToUnixMs( ((SignatureCreationTime)p).GetTime()); } hashedData[i] = p; } int unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte(); byte[] unhashed = new byte[unhashedLength]; bcpgIn.ReadFully(unhashed); sIn = new SignatureSubpacketsParser(new MemoryStream(unhashed, false)); v.Clear(); while ((sub = sIn.ReadPacket()) != null) { v.Add(sub); } unhashedData = new SignatureSubpacket[v.Count]; for (int i = 0; i != unhashedData.Length; i++) { SignatureSubpacket p = (SignatureSubpacket)v[i]; if (p is IssuerKeyId) { keyId = ((IssuerKeyId)p).KeyId; } else if (p is SignatureCreationTime) { creationTime = DateTimeUtilities.DateTimeToUnixMs( ((SignatureCreationTime)p).GetTime()); } unhashedData[i] = (SignatureSubpacket)p; } } else { throw new Exception("unsupported version: " + version); } fingerprint = new byte[2]; bcpgIn.ReadFully(fingerprint); switch (keyAlgorithm) { case PublicKeyAlgorithmTag.RsaGeneral: case PublicKeyAlgorithmTag.RsaSign: MPInteger v = new MPInteger(bcpgIn); signature = new MPInteger[] { v }; break; case PublicKeyAlgorithmTag.Dsa: MPInteger r = new MPInteger(bcpgIn); MPInteger s = new MPInteger(bcpgIn); signature = new MPInteger[] { r, s }; break; case PublicKeyAlgorithmTag.ElGamalEncrypt: // yep, this really does happen sometimes. case PublicKeyAlgorithmTag.ElGamalGeneral: MPInteger p = new MPInteger(bcpgIn); MPInteger g = new MPInteger(bcpgIn); MPInteger y = new MPInteger(bcpgIn); signature = new MPInteger[] { p, g, y }; break; default: throw new IOException("unknown signature key algorithm: " + keyAlgorithm); } }
internal SignaturePacket(BcpgInputStream bcpgIn) { _version = bcpgIn.ReadByte(); //TODO: refactor switch (_version) { case 2: case 3: bcpgIn.ReadByte(); _signatureType = bcpgIn.ReadByte(); CreationTime = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16) | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000L; _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(); break; case 4: { _signatureType = bcpgIn.ReadByte(); _keyAlgorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte(); _hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte(); var hashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte(); var hashed = new byte[hashedLength]; bcpgIn.ReadFully(hashed); // // read the signature sub packet data. // using (var hashedStream = new MemoryStream(hashed, false)) { var sIn = new SignatureSubpacketsParser(hashedStream); var v = Platform.CreateArrayList <ISignatureSubpacket>(); SignatureSubpacket sub; while ((sub = sIn.ReadPacket()) != null) { v.Add(sub); var issuerKeyId = sub as IssuerKeyId; if (issuerKeyId != null) { _keyId = issuerKeyId.KeyId; } else { var signatureCreationTime = sub as SignatureCreationTime; if (signatureCreationTime != null) { CreationTime = DateTimeUtilities.DateTimeToUnixMs(signatureCreationTime.GetTime()); } } } _hashedData = v.ToArray(); var unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte(); var unhashed = new byte[unhashedLength]; bcpgIn.ReadFully(unhashed); v.Clear(); using (var unhashedStream = new MemoryStream(unhashed, false)) { sIn = new SignatureSubpacketsParser(unhashedStream); while ((sub = sIn.ReadPacket()) != null) { v.Add(sub); var issuerKeyId = sub as IssuerKeyId; if (issuerKeyId != null) { _keyId = issuerKeyId.KeyId; } } } _unhashedData = v.ToArray(); } } break; default: throw new Exception("unsupported version: " + _version); } _fingerprint = new byte[2]; bcpgIn.ReadFully(_fingerprint); switch (_keyAlgorithm) { case PublicKeyAlgorithmTag.RsaGeneral: case PublicKeyAlgorithmTag.RsaSign: var v = new MPInteger(bcpgIn); _signature = new[] { v }; break; case PublicKeyAlgorithmTag.Dsa: case PublicKeyAlgorithmTag.Ecdsa: case PublicKeyAlgorithmTag.Ecdh: var r = new MPInteger(bcpgIn); var s = new MPInteger(bcpgIn); _signature = new[] { r, s }; break; case PublicKeyAlgorithmTag.ElGamalEncrypt: // yep, this really does happen sometimes. case PublicKeyAlgorithmTag.ElGamalGeneral: var p = new MPInteger(bcpgIn); var g = new MPInteger(bcpgIn); var y = new MPInteger(bcpgIn); _signature = new[] { p, g, y }; break; default: if (_keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && _keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11) { _signature = null; using (var bOut = new MemoryStream()) { int ch; while ((ch = bcpgIn.ReadByte()) >= 0) { bOut.WriteByte((byte)ch); } _signatureEncoding = bOut.ToArray(); } } else { throw new IOException("unknown signature key algorithm: " + _keyAlgorithm); } break; } }