ImageAttrib.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Attr
  6. {
  7. /// <remarks>Basic type for a image attribute packet.</remarks>
  8. public class ImageAttrib
  9. : UserAttributeSubpacket
  10. {
  11. public enum Format : byte
  12. {
  13. Jpeg = 1
  14. }
  15. private static readonly byte[] Zeroes = new byte[12];
  16. private int hdrLength;
  17. private int _version;
  18. private int _encoding;
  19. private byte[] imageData;
  20. public ImageAttrib(byte[] data)
  21. : this(false, data)
  22. {
  23. }
  24. public ImageAttrib(bool forceLongLength, byte[] data)
  25. : base(UserAttributeSubpacketTag.ImageAttribute, forceLongLength, data)
  26. {
  27. hdrLength = ((data[1] & 0xff) << 8) | (data[0] & 0xff);
  28. _version = data[2] & 0xff;
  29. _encoding = data[3] & 0xff;
  30. imageData = new byte[data.Length - hdrLength];
  31. Array.Copy(data, hdrLength, imageData, 0, imageData.Length);
  32. }
  33. public ImageAttrib(
  34. Format imageType,
  35. byte[] imageData)
  36. : this(ToByteArray(imageType, imageData))
  37. {
  38. }
  39. private static byte[] ToByteArray(
  40. Format imageType,
  41. byte[] imageData)
  42. {
  43. MemoryStream bOut = new MemoryStream();
  44. bOut.WriteByte(0x10); bOut.WriteByte(0x00); bOut.WriteByte(0x01);
  45. bOut.WriteByte((byte) imageType);
  46. bOut.Write(Zeroes, 0, Zeroes.Length);
  47. bOut.Write(imageData, 0, imageData.Length);
  48. return bOut.ToArray();
  49. }
  50. public virtual int Version
  51. {
  52. get { return _version; }
  53. }
  54. public virtual int Encoding
  55. {
  56. get { return _encoding; }
  57. }
  58. public virtual byte[] GetImageData()
  59. {
  60. return imageData;
  61. }
  62. }
  63. }
  64. #pragma warning restore
  65. #endif