MonetaryValue.cs 2.2 KB

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