summary refs log tree commit diff
path: root/crypto/src/cms/CMSProcessableInputStream.cs
blob: 7fdd1dfef786b71e059e33f72da4b2ea1a5dfca0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.IO;

using Org.BouncyCastle.Utilities.IO;

namespace Org.BouncyCastle.Cms
{
	public class CmsProcessableInputStream
		: CmsProcessable, CmsReadable
	{
		private Stream input;
		private bool used = false;

		public CmsProcessableInputStream(
			Stream input)
		{
			this.input = input;
		}

		public Stream GetInputStream()
		{
			CheckSingleUsage();

			return input;
		}

		public void Write(Stream output)
		{
			CheckSingleUsage();

			Streams.PipeAll(input, output);
			input.Close();
		}

		[Obsolete]
		public object GetContent()
		{
			return GetInputStream();
		}

		private void CheckSingleUsage()
		{
			lock (this)
			{
				if (used)
					throw new InvalidOperationException("CmsProcessableInputStream can only be used once");

				used = true;
			}
		}
	}
}