Example #1
0
        internal PgpEncryptedMessage(IPacketReader packetReader)
        {
            this.packetReader = packetReader;
            this.publicKeyEncSessionPackets    = new List <PublicKeyEncSessionPacket>();
            this.symmetricKeyEncSessionPackets = new List <SymmetricKeyEncSessionPacket>();

            while (packetReader.NextPacketTag() == PacketTag.PublicKeyEncryptedSession ||
                   packetReader.NextPacketTag() == PacketTag.SymmetricKeyEncryptedSessionKey)
            {
                var keyPacket = packetReader.ReadContainedPacket();
                if (keyPacket is SymmetricKeyEncSessionPacket symmetricKeyEncSessionPacket)
                {
                    symmetricKeyEncSessionPackets.Add(symmetricKeyEncSessionPacket);
                }
                else
                {
                    publicKeyEncSessionPackets.Add((PublicKeyEncSessionPacket)keyPacket);
                }
            }

            var packet = packetReader.ReadStreamablePacket();

            if (!(packet.Packet is SymmetricEncDataPacket) &&
                !(packet.Packet is SymmetricEncIntegrityPacket))
            {
                throw new IOException("unexpected packet in stream: " + packet);
            }

            this.encryptedPacket = packet.Packet;
            this.inputStream     = packet.Stream;
        }
Example #2
0
 public Stream GetPacketStream(StreamablePacket packet)
 {
     if (!generator.onePassWritten)
     {
         WriteOnePassSignature(false);
     }
     if (packet is LiteralDataPacket)
     {
         // TODO: Version 5 signatures
         var packetStream = innerWriter.GetPacketStream(packet);
         generator.literalDataWritten = true;
         return(new CryptoStream(packetStream, hashTransform, CryptoStreamMode.Write));
     }
     else
     {
         return(innerWriter.GetPacketStream(packet));
     }
 }
Example #3
0
 public Stream GetPacketStream(StreamablePacket packet) => packetWriter.GetPacketStream(packet);