X9ECPoint.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
  6. {
  7. /**
  8. * class for describing an ECPoint as a Der object.
  9. */
  10. public class X9ECPoint
  11. : Asn1Encodable
  12. {
  13. private readonly Asn1OctetString encoding;
  14. private ECCurve c;
  15. private ECPoint p;
  16. public X9ECPoint(ECPoint p)
  17. : this(p, false)
  18. {
  19. }
  20. public X9ECPoint(ECPoint p, bool compressed)
  21. {
  22. this.p = p.Normalize();
  23. this.encoding = new DerOctetString(p.GetEncoded(compressed));
  24. }
  25. public X9ECPoint(ECCurve c, byte[] encoding)
  26. {
  27. this.c = c;
  28. this.encoding = new DerOctetString(Arrays.Clone(encoding));
  29. }
  30. public X9ECPoint(ECCurve c, Asn1OctetString s)
  31. : this(c, s.GetOctets())
  32. {
  33. }
  34. public byte[] GetPointEncoding()
  35. {
  36. return Arrays.Clone(encoding.GetOctets());
  37. }
  38. public ECPoint Point
  39. {
  40. get
  41. {
  42. if (p == null)
  43. {
  44. p = c.DecodePoint(encoding.GetOctets()).Normalize();
  45. }
  46. return p;
  47. }
  48. }
  49. public bool IsPointCompressed
  50. {
  51. get
  52. {
  53. byte[] octets = encoding.GetOctets();
  54. return octets != null && octets.Length > 0 && (octets[0] == 2 || octets[0] == 3);
  55. }
  56. }
  57. /**
  58. * Produce an object suitable for an Asn1OutputStream.
  59. * <pre>
  60. * ECPoint ::= OCTET STRING
  61. * </pre>
  62. * <p>
  63. * Octet string produced using ECPoint.GetEncoded().</p>
  64. */
  65. public override Asn1Object ToAsn1Object()
  66. {
  67. return encoding;
  68. }
  69. }
  70. }
  71. #pragma warning restore
  72. #endif