CMSProcessableInputStream.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
  7. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms
  8. {
  9. public class CmsProcessableInputStream
  10. : CmsProcessable, CmsReadable
  11. {
  12. private readonly Stream input;
  13. private bool used = false;
  14. public CmsProcessableInputStream(Stream input)
  15. {
  16. this.input = input;
  17. }
  18. public virtual Stream GetInputStream()
  19. {
  20. CheckSingleUsage();
  21. return input;
  22. }
  23. public virtual void Write(Stream output)
  24. {
  25. CheckSingleUsage();
  26. Streams.PipeAll(input, output);
  27. input.Dispose();
  28. }
  29. protected virtual void CheckSingleUsage()
  30. {
  31. lock (this)
  32. {
  33. if (used)
  34. throw new InvalidOperationException("CmsProcessableInputStream can only be used once");
  35. used = true;
  36. }
  37. }
  38. }
  39. }
  40. #pragma warning restore
  41. #endif