BerSet.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. namespace Org.BouncyCastle.Asn1
  3. {
  4. public class BerSet
  5. : DerSet
  6. {
  7. public static new readonly BerSet Empty = new BerSet();
  8. public static new BerSet FromVector(
  9. Asn1EncodableVector v)
  10. {
  11. return v.Count < 1 ? Empty : new BerSet(v);
  12. }
  13. internal static new BerSet FromVector(
  14. Asn1EncodableVector v,
  15. bool needsSorting)
  16. {
  17. return v.Count < 1 ? Empty : new BerSet(v, needsSorting);
  18. }
  19. /**
  20. * create an empty sequence
  21. */
  22. public BerSet()
  23. {
  24. }
  25. /**
  26. * create a set containing one object
  27. */
  28. public BerSet(Asn1Encodable obj) : base(obj)
  29. {
  30. }
  31. /**
  32. * create a set containing a vector of objects.
  33. */
  34. public BerSet(Asn1EncodableVector v) : base(v, false)
  35. {
  36. }
  37. internal BerSet(Asn1EncodableVector v, bool needsSorting) : base(v, needsSorting)
  38. {
  39. }
  40. /*
  41. */
  42. internal override void Encode(
  43. DerOutputStream derOut)
  44. {
  45. if (derOut is Asn1OutputStream || derOut is BerOutputStream)
  46. {
  47. derOut.WriteByte(Asn1Tags.Set | Asn1Tags.Constructed);
  48. derOut.WriteByte(0x80);
  49. foreach (Asn1Encodable o in this)
  50. {
  51. derOut.WriteObject(o);
  52. }
  53. derOut.WriteByte(0x00);
  54. derOut.WriteByte(0x00);
  55. }
  56. else
  57. {
  58. base.Encode(derOut);
  59. }
  60. }
  61. }
  62. }
  63. #endif