summary refs log tree commit diff
path: root/crypto/src/bcpg/LiteralDataPacket.cs
blob: b4d28a201960dc6c2cfbdca964bbbf0636398a5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.IO;

using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Bcpg
{
	/// <remarks>Generic literal data packet.</remarks>
    public class LiteralDataPacket
        : InputStreamPacket
	{
		private int		format;
        private byte[]	fileName;
        private long	modDate;

		internal LiteralDataPacket(
            BcpgInputStream bcpgIn)
			: base(bcpgIn)
        {
            format = bcpgIn.ReadByte();
            int len = bcpgIn.ReadByte();

			fileName = new byte[len];
			for (int i = 0; i != len; ++i)
            {
                int ch = bcpgIn.ReadByte();
                if (ch < 0)
                    throw new IOException("literal data truncated in header");

                fileName[i] = (byte)ch;
            }

			modDate = (((uint)bcpgIn.ReadByte() << 24)
				| ((uint)bcpgIn.ReadByte() << 16)
                | ((uint)bcpgIn.ReadByte() << 8)
				| (uint)bcpgIn.ReadByte()) * 1000L;
        }

		/// <summary>The format tag value.</summary>
        public int Format
		{
			get { return format; }
		}

		/// <summary>The modification time of the file in milli-seconds (since Jan 1, 1970 UTC)</summary>
        public long ModificationTime
		{
			get { return modDate; }
		}

		public string FileName
		{
			get { return Strings.FromUtf8ByteArray(fileName); }
		}

		public byte[] GetRawFileName()
		{
			return Arrays.Clone(fileName);
		}
	}
}