Esempio n. 1
0
        internal PgpLiteralMessage(IPacketReader packetReader)
        {
            var packet = packetReader.ReadStreamablePacket();

            this.literalDataPacket = (LiteralDataPacket)packet.Packet;
            this.inputStream       = packet.Stream;
        }
        public PgpLiteralData(
            BcpgInputStream bcpgInput)
        {
            Packet packet = bcpgInput.ReadPacket();

            if (!(packet is LiteralDataPacket))
            {
                throw new IOException("unexpected packet in stream: " + packet);
            }

            this.data = (LiteralDataPacket)packet;
        }
        /// <summary>
        /// Open a literal data packet.
        /// </summary>
        /// <param name="writer">The writer 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>
        public PgpLiteralMessageGenerator(
            IPacketWriter writer,
            PgpDataFormat format,
            string name,
            DateTime modificationTime)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            var packet = new LiteralDataPacket(format, name, modificationTime);

            this.outputStream = writer.GetPacketStream(packet);
            this.writer       = writer;
        }
Esempio n. 4
0
        /// <summary>
        /// Parses a literal message out of the given array of packets.
        /// In this special case, the first packet in packets MUST be
        /// a literal data packet.
        /// </summary>
        /// <returns>Returns the number of packets used by the function.
        /// If everything works fine, it will always return 1.</returns>
        /// <param name="packets">Array of packets. The first packet in
        /// the array MUST be a literal data packet. Otherwise an exception
        /// is thrown.</param>
        /// <remarks>No remarks</remarks>
        public override int ParseMessage(Packet[] packets)
        {
            if (packets[0] is LiteralDataPacket)
            {
                this.pPackets = new Packet[1];
                pPackets[0]   = packets[0];
                LiteralDataPacket ldpPacket = (LiteralDataPacket)packets[0];
                dftDataFormat = ldpPacket.DataFormat;
                Binary        = ldpPacket.LiteralData;
                strFilename   = ldpPacket.Filename;
                dtTimeCreated = ldpPacket.TimeCreated;
            }
            else
            {
                throw new System.ArgumentException("Expected a literal data packet as first packet in the array, but did not find it. Looks like something went terribly wrong.");
            }

            return(1);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the OpenPGP encoded representation of the literal data
        /// message.
        /// </summary>
        /// <returns>Returns a byte array that contains the binary
        /// representation of the literal message.</returns>
        /// <remarks>No remarks</remarks>
        public override byte[] GetEncoded()
        {
            if (pPackets.Length > 1)
            {
                throw new System.ApplicationException("A literal data message can contain only one packet. Something /really/ strange happened!");
            }

            if (pPackets.Length == 0)
            {
                pPackets = new Packet[1];
                LiteralDataPacket ldpPacket = new LiteralDataPacket();
                ldpPacket.DataFormat  = DataFormat;
                ldpPacket.LiteralData = Binary;
                ldpPacket.Filename    = strFilename;
                ldpPacket.TimeCreated = dtTimeCreated;
                pPackets[0]           = ldpPacket;
            }

            return(pPackets[0].Generate());
        }
Esempio n. 6
0
 public PgpLiteralData(BcpgInputStream bcpgInput)
 {
     data = (LiteralDataPacket)bcpgInput.ReadPacket();
 }
Esempio n. 7
0
		public PgpLiteralData(
            BcpgInputStream bcpgInput)
        {
            data = (LiteralDataPacket) bcpgInput.ReadPacket();
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the OpenPGP encoded representation of the literal data
        /// message.
        /// </summary>
        /// <returns>Returns a byte array that contains the binary
        /// representation of the literal message.</returns>
        /// <remarks>No remarks</remarks>
        public override byte[] GetEncoded()
        {
            if (pPackets.Length > 1)
                throw new System.ApplicationException("A literal data message can contain only one packet. Something /really/ strange happened!");

            if (pPackets.Length == 0) {
                pPackets = new Packet[1];
                LiteralDataPacket ldpPacket = new LiteralDataPacket();
                ldpPacket.DataFormat = DataFormat;
                ldpPacket.LiteralData = Binary;
                ldpPacket.Filename = strFilename;
                ldpPacket.TimeCreated = dtTimeCreated;
                pPackets[0] = ldpPacket;
            }

            return pPackets[0].Generate();
        }