AuthenticatedSafe.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  6. {
  7. public class AuthenticatedSafe
  8. : Asn1Encodable
  9. {
  10. private static ContentInfo[] Copy(ContentInfo[] info)
  11. {
  12. return (ContentInfo[])info.Clone();
  13. }
  14. public static AuthenticatedSafe GetInstance(object obj)
  15. {
  16. if (obj is AuthenticatedSafe)
  17. return (AuthenticatedSafe)obj;
  18. if (obj == null)
  19. return null;
  20. return new AuthenticatedSafe(Asn1Sequence.GetInstance(obj));
  21. }
  22. private readonly ContentInfo[] info;
  23. private readonly bool isBer;
  24. private AuthenticatedSafe(Asn1Sequence seq)
  25. {
  26. info = new ContentInfo[seq.Count];
  27. for (int i = 0; i != info.Length; i++)
  28. {
  29. info[i] = ContentInfo.GetInstance(seq[i]);
  30. }
  31. isBer = seq is BerSequence;
  32. }
  33. public AuthenticatedSafe(
  34. ContentInfo[] info)
  35. {
  36. this.info = Copy(info);
  37. this.isBer = true;
  38. }
  39. public ContentInfo[] GetContentInfo()
  40. {
  41. return Copy(info);
  42. }
  43. public override Asn1Object ToAsn1Object()
  44. {
  45. if (isBer)
  46. {
  47. return new BerSequence(info);
  48. }
  49. // TODO bc-java uses DL sequence
  50. //return new DLSequence(info);
  51. return new DerSequence(info);
  52. }
  53. }
  54. }
  55. #pragma warning restore
  56. #endif