You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
947 B
54 lines
947 B
2 months ago
|
using System;
|
||
|
using System.IO;
|
||
|
|
||
|
using Org.BouncyCastle.Utilities;
|
||
|
using Org.BouncyCastle.Utilities.IO;
|
||
|
|
||
|
namespace Org.BouncyCastle.Cms
|
||
|
{
|
||
|
public class CmsProcessableInputStream
|
||
|
: CmsProcessable, CmsReadable
|
||
|
{
|
||
|
private readonly Stream input;
|
||
|
|
||
|
private bool used = false;
|
||
|
|
||
|
public CmsProcessableInputStream(Stream input)
|
||
|
{
|
||
|
this.input = input;
|
||
|
}
|
||
|
|
||
|
public virtual Stream GetInputStream()
|
||
|
{
|
||
|
CheckSingleUsage();
|
||
|
|
||
|
return input;
|
||
|
}
|
||
|
|
||
|
public virtual void Write(Stream output)
|
||
|
{
|
||
|
CheckSingleUsage();
|
||
|
|
||
|
Streams.PipeAll(input, output);
|
||
|
Platform.Dispose(input);
|
||
|
}
|
||
|
|
||
|
[Obsolete]
|
||
|
public virtual object GetContent()
|
||
|
{
|
||
|
return GetInputStream();
|
||
|
}
|
||
|
|
||
|
protected virtual void CheckSingleUsage()
|
||
|
{
|
||
|
lock (this)
|
||
|
{
|
||
|
if (used)
|
||
|
throw new InvalidOperationException("CmsProcessableInputStream can only be used once");
|
||
|
|
||
|
used = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|