MonetaryValue.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.Utilities;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509.Qualified
  7. {
  8. /**
  9. * The MonetaryValue object.
  10. * <pre>
  11. * MonetaryValue ::= SEQUENCE {
  12. * currency Iso4217CurrencyCode,
  13. * amount INTEGER,
  14. * exponent INTEGER }
  15. * -- value = amount * 10^exponent
  16. * </pre>
  17. */
  18. public class MonetaryValue
  19. : Asn1Encodable
  20. {
  21. internal Iso4217CurrencyCode currency;
  22. internal DerInteger amount;
  23. internal DerInteger exponent;
  24. public static MonetaryValue GetInstance(
  25. object obj)
  26. {
  27. if (obj == null || obj is MonetaryValue)
  28. {
  29. return (MonetaryValue) obj;
  30. }
  31. if (obj is Asn1Sequence)
  32. {
  33. return new MonetaryValue(Asn1Sequence.GetInstance(obj));
  34. }
  35. throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  36. }
  37. private MonetaryValue(
  38. Asn1Sequence seq)
  39. {
  40. if (seq.Count != 3)
  41. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  42. currency = Iso4217CurrencyCode.GetInstance(seq[0]);
  43. amount = DerInteger.GetInstance(seq[1]);
  44. exponent = DerInteger.GetInstance(seq[2]);
  45. }
  46. public MonetaryValue(
  47. Iso4217CurrencyCode currency,
  48. int amount,
  49. int exponent)
  50. {
  51. this.currency = currency;
  52. this.amount = new DerInteger(amount);
  53. this.exponent = new DerInteger(exponent);
  54. }
  55. public Iso4217CurrencyCode Currency
  56. {
  57. get { return currency; }
  58. }
  59. public BigInteger Amount
  60. {
  61. get { return amount.Value; }
  62. }
  63. public BigInteger Exponent
  64. {
  65. get { return exponent.Value; }
  66. }
  67. public override Asn1Object ToAsn1Object()
  68. {
  69. return new DerSequence(currency, amount, exponent);
  70. }
  71. }
  72. }
  73. #pragma warning restore
  74. #endif