Iso4217CurrencyCode.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509.Qualified
  6. {
  7. /**
  8. * The Iso4217CurrencyCode object.
  9. * <pre>
  10. * Iso4217CurrencyCode ::= CHOICE {
  11. * alphabetic PrintableString (SIZE 3), --Recommended
  12. * numeric INTEGER (1..999) }
  13. * -- Alphabetic or numeric currency code as defined in ISO 4217
  14. * -- It is recommended that the Alphabetic form is used
  15. * </pre>
  16. */
  17. public class Iso4217CurrencyCode
  18. : Asn1Encodable, IAsn1Choice
  19. {
  20. internal const int AlphabeticMaxSize = 3;
  21. internal const int NumericMinSize = 1;
  22. internal const int NumericMaxSize = 999;
  23. internal Asn1Encodable obj;
  24. // internal int numeric;
  25. public static Iso4217CurrencyCode GetInstance(
  26. object obj)
  27. {
  28. if (obj == null || obj is Iso4217CurrencyCode)
  29. {
  30. return (Iso4217CurrencyCode) obj;
  31. }
  32. if (obj is DerInteger)
  33. {
  34. DerInteger numericobj = DerInteger.GetInstance(obj);
  35. int numeric = numericobj.IntValueExact;
  36. return new Iso4217CurrencyCode(numeric);
  37. }
  38. if (obj is DerPrintableString)
  39. {
  40. DerPrintableString alphabetic = DerPrintableString.GetInstance(obj);
  41. return new Iso4217CurrencyCode(alphabetic.GetString());
  42. }
  43. throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  44. }
  45. public Iso4217CurrencyCode(
  46. int numeric)
  47. {
  48. if (numeric > NumericMaxSize || numeric < NumericMinSize)
  49. {
  50. throw new ArgumentException("wrong size in numeric code : not in (" + NumericMinSize + ".." + NumericMaxSize + ")");
  51. }
  52. obj = new DerInteger(numeric);
  53. }
  54. public Iso4217CurrencyCode(
  55. string alphabetic)
  56. {
  57. if (alphabetic.Length > AlphabeticMaxSize)
  58. {
  59. throw new ArgumentException("wrong size in alphabetic code : max size is " + AlphabeticMaxSize);
  60. }
  61. obj = new DerPrintableString(alphabetic);
  62. }
  63. public bool IsAlphabetic { get { return obj is DerPrintableString; } }
  64. public string Alphabetic { get { return ((DerPrintableString) obj).GetString(); } }
  65. public int Numeric { get { return ((DerInteger)obj).IntValueExact; } }
  66. public override Asn1Object ToAsn1Object()
  67. {
  68. return obj.ToAsn1Object();
  69. }
  70. }
  71. }
  72. #pragma warning restore
  73. #endif