01: package org.bouncycastle.crypto.engines;
02:
03: import org.bouncycastle.crypto.BlockCipher;
04: import org.bouncycastle.crypto.CipherParameters;
05: import org.bouncycastle.crypto.DataLengthException;
06:
07: /**
08: * The no-op engine that just copies bytes through, irrespective of whether encrypting and decrypting.
09: * Provided for the sake of completeness.
10: */
11: public class NullEngine implements BlockCipher {
12: private boolean initialised;
13: protected static final int BLOCK_SIZE = 1;
14:
15: /**
16: * Standard constructor.
17: */
18: public NullEngine() {
19: super ();
20: }
21:
22: /* (non-Javadoc)
23: * @see org.bouncycastle.crypto.BlockCipher#init(boolean, org.bouncycastle.crypto.CipherParameters)
24: */
25: public void init(boolean forEncryption, CipherParameters params)
26: throws IllegalArgumentException {
27: // we don't mind any parameters that may come in
28: this .initialised = true;
29: }
30:
31: /* (non-Javadoc)
32: * @see org.bouncycastle.crypto.BlockCipher#getAlgorithmName()
33: */
34: public String getAlgorithmName() {
35: return "Null";
36: }
37:
38: /* (non-Javadoc)
39: * @see org.bouncycastle.crypto.BlockCipher#getBlockSize()
40: */
41: public int getBlockSize() {
42: return BLOCK_SIZE;
43: }
44:
45: /* (non-Javadoc)
46: * @see org.bouncycastle.crypto.BlockCipher#processBlock(byte[], int, byte[], int)
47: */
48: public int processBlock(byte[] in, int inOff, byte[] out, int outOff)
49: throws DataLengthException, IllegalStateException {
50: if (!initialised) {
51: throw new IllegalStateException(
52: "Null engine not initialised");
53: }
54: if ((inOff + BLOCK_SIZE) > in.length) {
55: throw new DataLengthException("input buffer too short");
56: }
57:
58: if ((outOff + BLOCK_SIZE) > out.length) {
59: throw new DataLengthException("output buffer too short");
60: }
61:
62: for (int i = 0; i < BLOCK_SIZE; ++i) {
63: out[outOff + i] = in[inOff + i];
64: }
65:
66: return BLOCK_SIZE;
67: }
68:
69: /* (non-Javadoc)
70: * @see org.bouncycastle.crypto.BlockCipher#reset()
71: */
72: public void reset() {
73: // nothing needs to be done
74: }
75: }
|