MonetaryLimit.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509
  7. {
  8. /**
  9. * Monetary limit for transactions. The QcEuMonetaryLimit QC statement MUST be
  10. * used in new certificates in place of the extension/attribute MonetaryLimit
  11. * since January 1, 2004. For the sake of backward compatibility with
  12. * certificates already in use, components SHOULD support MonetaryLimit (as well
  13. * as QcEuLimitValue).
  14. * <p/>
  15. * Indicates a monetary limit within which the certificate holder is authorized
  16. * to act. (This value DOES NOT express a limit on the liability of the
  17. * certification authority).
  18. * <p/>
  19. * <pre>
  20. * MonetaryLimitSyntax ::= SEQUENCE
  21. * {
  22. * currency PrintableString (SIZE(3)),
  23. * amount INTEGER,
  24. * exponent INTEGER
  25. * }
  26. * </pre>
  27. * <p/>
  28. * currency must be the ISO code.
  29. * <p/>
  30. * value = amount�10*exponent
  31. */
  32. public class MonetaryLimit
  33. : Asn1Encodable
  34. {
  35. private readonly DerPrintableString currency;
  36. private readonly DerInteger amount;
  37. private readonly DerInteger exponent;
  38. public static MonetaryLimit GetInstance(
  39. object obj)
  40. {
  41. if (obj == null || obj is MonetaryLimit)
  42. {
  43. return (MonetaryLimit) obj;
  44. }
  45. if (obj is Asn1Sequence)
  46. {
  47. return new MonetaryLimit(Asn1Sequence.GetInstance(obj));
  48. }
  49. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  50. }
  51. private MonetaryLimit(
  52. Asn1Sequence seq)
  53. {
  54. if (seq.Count != 3)
  55. throw new ArgumentException("Bad sequence size: " + seq.Count);
  56. currency = DerPrintableString.GetInstance(seq[0]);
  57. amount = DerInteger.GetInstance(seq[1]);
  58. exponent = DerInteger.GetInstance(seq[2]);
  59. }
  60. /**
  61. * Constructor from a given details.
  62. * <p/>
  63. * <p/>
  64. * value = amount�10^exponent
  65. *
  66. * @param currency The currency. Must be the ISO code.
  67. * @param amount The amount
  68. * @param exponent The exponent
  69. */
  70. public MonetaryLimit(
  71. string currency,
  72. int amount,
  73. int exponent)
  74. {
  75. this.currency = new DerPrintableString(currency, true);
  76. this.amount = new DerInteger(amount);
  77. this.exponent = new DerInteger(exponent);
  78. }
  79. public virtual string Currency
  80. {
  81. get { return currency.GetString(); }
  82. }
  83. public virtual BigInteger Amount
  84. {
  85. get { return amount.Value; }
  86. }
  87. public virtual BigInteger Exponent
  88. {
  89. get { return exponent.Value; }
  90. }
  91. /**
  92. * Produce an object suitable for an Asn1OutputStream.
  93. * <p/>
  94. * Returns:
  95. * <p/>
  96. * <pre>
  97. * MonetaryLimitSyntax ::= SEQUENCE
  98. * {
  99. * currency PrintableString (SIZE(3)),
  100. * amount INTEGER,
  101. * exponent INTEGER
  102. * }
  103. * </pre>
  104. *
  105. * @return an Asn1Object
  106. */
  107. public override Asn1Object ToAsn1Object()
  108. {
  109. return new DerSequence(currency, amount, exponent);
  110. }
  111. }
  112. }
  113. #pragma warning restore
  114. #endif