DeclarationOfMajority.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.IsisMtt.X509
  6. {
  7. /**
  8. * A declaration of majority.
  9. * <p/>
  10. * <pre>
  11. * DeclarationOfMajoritySyntax ::= CHOICE
  12. * {
  13. * notYoungerThan [0] IMPLICIT INTEGER,
  14. * fullAgeAtCountry [1] IMPLICIT SEQUENCE
  15. * {
  16. * fullAge BOOLEAN DEFAULT TRUE,
  17. * country PrintableString (SIZE(2))
  18. * }
  19. * dateOfBirth [2] IMPLICIT GeneralizedTime
  20. * }
  21. * </pre>
  22. * <p/>
  23. * fullAgeAtCountry indicates the majority of the owner with respect to the laws
  24. * of a specific country.
  25. */
  26. public class DeclarationOfMajority
  27. : Asn1Encodable, IAsn1Choice
  28. {
  29. public enum Choice
  30. {
  31. NotYoungerThan = 0,
  32. FullAgeAtCountry = 1,
  33. DateOfBirth = 2
  34. };
  35. private readonly Asn1TaggedObject declaration;
  36. public DeclarationOfMajority(
  37. int notYoungerThan)
  38. {
  39. declaration = new DerTaggedObject(false, 0, new DerInteger(notYoungerThan));
  40. }
  41. public DeclarationOfMajority(
  42. bool fullAge,
  43. string country)
  44. {
  45. if (country.Length > 2)
  46. throw new ArgumentException("country can only be 2 characters");
  47. DerPrintableString countryString = new DerPrintableString(country, true);
  48. DerSequence seq;
  49. if (fullAge)
  50. {
  51. seq = new DerSequence(countryString);
  52. }
  53. else
  54. {
  55. seq = new DerSequence(DerBoolean.False, countryString);
  56. }
  57. this.declaration = new DerTaggedObject(false, 1, seq);
  58. }
  59. public DeclarationOfMajority(
  60. DerGeneralizedTime dateOfBirth)
  61. {
  62. this.declaration = new DerTaggedObject(false, 2, dateOfBirth);
  63. }
  64. public static DeclarationOfMajority GetInstance(
  65. object obj)
  66. {
  67. if (obj == null || obj is DeclarationOfMajority)
  68. {
  69. return (DeclarationOfMajority) obj;
  70. }
  71. if (obj is Asn1TaggedObject)
  72. {
  73. return new DeclarationOfMajority((Asn1TaggedObject) obj);
  74. }
  75. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  76. }
  77. private DeclarationOfMajority(
  78. Asn1TaggedObject o)
  79. {
  80. if (o.TagNo > 2)
  81. throw new ArgumentException("Bad tag number: " + o.TagNo);
  82. this.declaration = o;
  83. }
  84. /**
  85. * Produce an object suitable for an Asn1OutputStream.
  86. * <p/>
  87. * Returns:
  88. * <p/>
  89. * <pre>
  90. * DeclarationOfMajoritySyntax ::= CHOICE
  91. * {
  92. * notYoungerThan [0] IMPLICIT INTEGER,
  93. * fullAgeAtCountry [1] IMPLICIT SEQUENCE
  94. * {
  95. * fullAge BOOLEAN DEFAULT TRUE,
  96. * country PrintableString (SIZE(2))
  97. * }
  98. * dateOfBirth [2] IMPLICIT GeneralizedTime
  99. * }
  100. * </pre>
  101. *
  102. * @return an Asn1Object
  103. */
  104. public override Asn1Object ToAsn1Object()
  105. {
  106. return declaration;
  107. }
  108. public Choice Type
  109. {
  110. get { return (Choice) declaration.TagNo; }
  111. }
  112. /**
  113. * @return notYoungerThan if that's what we are, -1 otherwise
  114. */
  115. public virtual int NotYoungerThan
  116. {
  117. get
  118. {
  119. switch ((Choice) declaration.TagNo)
  120. {
  121. case Choice.NotYoungerThan:
  122. return DerInteger.GetInstance(declaration, false).IntValueExact;
  123. default:
  124. return -1;
  125. }
  126. }
  127. }
  128. public virtual Asn1Sequence FullAgeAtCountry
  129. {
  130. get
  131. {
  132. switch ((Choice) declaration.TagNo)
  133. {
  134. case Choice.FullAgeAtCountry:
  135. return Asn1Sequence.GetInstance(declaration, false);
  136. default:
  137. return null;
  138. }
  139. }
  140. }
  141. public virtual DerGeneralizedTime DateOfBirth
  142. {
  143. get
  144. {
  145. switch ((Choice) declaration.TagNo)
  146. {
  147. case Choice.DateOfBirth:
  148. return DerGeneralizedTime.GetInstance(declaration, false);
  149. default:
  150. return null;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. #pragma warning restore
  157. #endif