Beispiel #1
0
        public void IncorrectCrcTest()
        {
            using var data         = new MemoryStream(Encoding.ASCII.GetBytes(incorrectCrc), false);
            using var packetReader = new ArmoredPacketReader(data);
            var packet = packetReader.ReadContainedPacket();

            Assert.NotNull(packet);
            Assert.AreEqual(PacketTag.Marker, packet.Tag);
            Assert.IsFalse(packetReader.VerifyCrc());
        }
Beispiel #2
0
        public void MessageTest(string type, string message)
        {
            /*ArmoredInputStream aIn = new ArmoredInputStream(
             *  new MemoryStream(Encoding.ASCII.GetBytes(message)));
             *
             * string[] headers = aIn.GetArmorHeaders();
             *
             * Assert.NotNull(headers);
             * Assert.AreEqual(1, headers.Length);
             *
             * //
             * // read the input, making sure we ingore the last newline.
             * //
             * MemoryStream bOut = new MemoryStream();
             * int ch;
             *
             * while ((ch = aIn.ReadByte()) >= 0 && aIn.IsClearText())
             * {
             *  bOut.WriteByte((byte)ch);
             * }
             *
             * PgpPublicKeyRingBundle pgpRings = new PgpPublicKeyRingBundle(publicKey);
             *
             * PgpSignature sig = new PgpSignature(aIn);
             *
             * // FIXME: This belongs directly to the armor reader
             * byte[] clearText = bOut.ToArray();
             * int clearTextLength = clearText.Length;
             * if (clearTextLength > 0 && clearText[clearTextLength - 1] == '\n')
             *  clearTextLength--;
             * if (clearTextLength > 0 && clearText[clearTextLength - 1] == '\r')
             *  clearTextLength--;
             *
             * bool verified = sig.Verify(pgpRings.GetPublicKey(sig.KeyId), new MemoryStream(clearText, 0, clearTextLength, false), ignoreTrailingWhitespace: true);
             * Assert.IsTrue(verified, "signature failed to verify m_in " + type);*/

            PgpPublicKeyRingBundle pgpRings = new PgpPublicKeyRingBundle(publicKey);

            var reader         = new ArmoredPacketReader(new MemoryStream(Encoding.ASCII.GetBytes(message)));
            var signedMessage  = (PgpSignedMessage)PgpMessage.ReadMessage(reader);
            var literalMessage = (PgpLiteralMessage)signedMessage.ReadMessage();
            var bytes          = Streams.ReadAll(literalMessage.GetStream());

            Assert.IsTrue(signedMessage.Verify(pgpRings.GetPublicKey(signedMessage.KeyId)));
            reader.VerifyCrc();
        }
Beispiel #3
0
 public void TwoMessages()
 {
     using var data = new MemoryStream(Encoding.ASCII.GetBytes(blankLineData + blankLineData), false);
     using (var packetReader = new ArmoredPacketReader(data))
     {
         var packet = packetReader.ReadContainedPacket();
         Assert.NotNull(packet);
         Assert.AreEqual(PacketTag.Marker, packet.Tag);
         Assert.IsTrue(packetReader.VerifyCrc());
     }
     using (var packetReader = new ArmoredPacketReader(data))
     {
         var packet = packetReader.ReadContainedPacket();
         Assert.NotNull(packet);
         Assert.AreEqual(PacketTag.Marker, packet.Tag);
         Assert.IsTrue(packetReader.VerifyCrc());
     }
 }
Beispiel #4
0
 public void VerifyCrcWithoutReadingTest()
 {
     using var data         = new MemoryStream(Encoding.ASCII.GetBytes(blankLineData), false);
     using var packetReader = new ArmoredPacketReader(data);
     Assert.IsTrue(packetReader.VerifyCrc());
 }