summary refs log tree commit diff
path: root/Crypto/src/crypto/engines/NullEngine.cs
blob: 407b8ccc6cd6118db56d1139f94b7c9ee26a74e3 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;

using Org.BouncyCastle.Crypto.Parameters;

namespace Org.BouncyCastle.Crypto.Engines
{
	/**
	* The no-op engine that just copies bytes through, irrespective of whether encrypting and decrypting.
	* Provided for the sake of completeness.
	*/
	public class NullEngine
		: IBlockCipher
	{
		private bool initialised;
		private const int BlockSize = 1;

		public NullEngine()
		{
		}

		public void Init(
			bool				forEncryption,
			ICipherParameters	parameters)
		{
			// we don't mind any parameters that may come in
			initialised = true;
		}

		public string AlgorithmName
		{
			get { return "Null"; }
		}

		public bool IsPartialBlockOkay
		{
			get { return true; }
		}

		public int GetBlockSize()
		{
			return BlockSize;
		}

		public int ProcessBlock(
			byte[]	input,
			int		inOff,
			byte[]	output,
			int		outOff)
		{
			if (!initialised)
				throw new InvalidOperationException("Null engine not initialised");
			if ((inOff + BlockSize) > input.Length)
				throw new DataLengthException("input buffer too short");
			if ((outOff + BlockSize) > output.Length)
				throw new DataLengthException("output buffer too short");

			for (int i = 0; i < BlockSize; ++i)
			{
				output[outOff + i] = input[inOff + i];
			}

			return BlockSize;
		}

		public void Reset()
		{
			// nothing needs to be done
		}
	}
}