X9FieldElement.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
  7. {
  8. /**
  9. * Class for processing an ECFieldElement as a DER object.
  10. */
  11. public class X9FieldElement
  12. : Asn1Encodable
  13. {
  14. private ECFieldElement f;
  15. public X9FieldElement(
  16. ECFieldElement f)
  17. {
  18. this.f = f;
  19. }
  20. public ECFieldElement Value
  21. {
  22. get { return f; }
  23. }
  24. /**
  25. * Produce an object suitable for an Asn1OutputStream.
  26. * <pre>
  27. * FieldElement ::= OCTET STRING
  28. * </pre>
  29. * <p>
  30. * <ol>
  31. * <li> if <i>q</i> is an odd prime then the field element is
  32. * processed as an Integer and converted to an octet string
  33. * according to x 9.62 4.3.1.</li>
  34. * <li> if <i>q</i> is 2<sup>m</sup> then the bit string
  35. * contained in the field element is converted into an octet
  36. * string with the same ordering padded at the front if necessary.
  37. * </li>
  38. * </ol>
  39. * </p>
  40. */
  41. public override Asn1Object ToAsn1Object()
  42. {
  43. int byteCount = X9IntegerConverter.GetByteLength(f);
  44. byte[] paddedBigInteger = X9IntegerConverter.IntegerToBytes(f.ToBigInteger(), byteCount);
  45. return new DerOctetString(paddedBigInteger);
  46. }
  47. }
  48. }
  49. #pragma warning restore
  50. #endif