X9ECPoint.cs 1.9 KB

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