LiteralDataPacket.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
  7. {
  8. /// <remarks>Generic literal data packet.</remarks>
  9. public class LiteralDataPacket
  10. : InputStreamPacket
  11. {
  12. private int format;
  13. private byte[] fileName;
  14. private long modDate;
  15. internal LiteralDataPacket(
  16. BcpgInputStream bcpgIn)
  17. : base(bcpgIn)
  18. {
  19. format = bcpgIn.ReadByte();
  20. int len = bcpgIn.ReadByte();
  21. fileName = new byte[len];
  22. for (int i = 0; i != len; ++i)
  23. {
  24. int ch = bcpgIn.ReadByte();
  25. if (ch < 0)
  26. throw new IOException("literal data truncated in header");
  27. fileName[i] = (byte)ch;
  28. }
  29. modDate = (((uint)bcpgIn.ReadByte() << 24)
  30. | ((uint)bcpgIn.ReadByte() << 16)
  31. | ((uint)bcpgIn.ReadByte() << 8)
  32. | (uint)bcpgIn.ReadByte()) * 1000L;
  33. }
  34. /// <summary>The format tag value.</summary>
  35. public int Format
  36. {
  37. get { return format; }
  38. }
  39. /// <summary>The modification time of the file in milli-seconds (since Jan 1, 1970 UTC)</summary>
  40. public long ModificationTime
  41. {
  42. get { return modDate; }
  43. }
  44. public string FileName
  45. {
  46. get { return Strings.FromUtf8ByteArray(fileName); }
  47. }
  48. public byte[] GetRawFileName()
  49. {
  50. return Arrays.Clone(fileName);
  51. }
  52. }
  53. }
  54. #pragma warning restore
  55. #endif