X9FieldElement.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
  6. namespace BestHTTP.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. [Obsolete("Will be removed")]
  21. public X9FieldElement(
  22. BigInteger p,
  23. Asn1OctetString s)
  24. : this(new FpFieldElement(p, new BigInteger(1, s.GetOctets())))
  25. {
  26. }
  27. [Obsolete("Will be removed")]
  28. public X9FieldElement(
  29. int m,
  30. int k1,
  31. int k2,
  32. int k3,
  33. Asn1OctetString s)
  34. : this(new F2mFieldElement(m, k1, k2, k3, new BigInteger(1, s.GetOctets())))
  35. {
  36. }
  37. public ECFieldElement Value
  38. {
  39. get { return f; }
  40. }
  41. /**
  42. * Produce an object suitable for an Asn1OutputStream.
  43. * <pre>
  44. * FieldElement ::= OCTET STRING
  45. * </pre>
  46. * <p>
  47. * <ol>
  48. * <li> if <i>q</i> is an odd prime then the field element is
  49. * processed as an Integer and converted to an octet string
  50. * according to x 9.62 4.3.1.</li>
  51. * <li> if <i>q</i> is 2<sup>m</sup> then the bit string
  52. * contained in the field element is converted into an octet
  53. * string with the same ordering padded at the front if necessary.
  54. * </li>
  55. * </ol>
  56. * </p>
  57. */
  58. public override Asn1Object ToAsn1Object()
  59. {
  60. int byteCount = X9IntegerConverter.GetByteLength(f);
  61. byte[] paddedBigInteger = X9IntegerConverter.IntegerToBytes(f.ToBigInteger(), byteCount);
  62. return new DerOctetString(paddedBigInteger);
  63. }
  64. }
  65. }
  66. #pragma warning restore
  67. #endif