diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/crypto/BufferedAsymmetricBlockCipher.cs | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/crypto/src/crypto/BufferedAsymmetricBlockCipher.cs b/crypto/src/crypto/BufferedAsymmetricBlockCipher.cs index 382d6a2cb..1a20516e6 100644 --- a/crypto/src/crypto/BufferedAsymmetricBlockCipher.cs +++ b/crypto/src/crypto/BufferedAsymmetricBlockCipher.cs @@ -19,8 +19,7 @@ namespace Org.BouncyCastle.Crypto * * @param cipher the cipher this buffering object wraps. */ - public BufferedAsymmetricBlockCipher( - IAsymmetricBlockCipher cipher) + public BufferedAsymmetricBlockCipher(IAsymmetricBlockCipher cipher) { this.cipher = cipher; } @@ -45,16 +44,14 @@ namespace Org.BouncyCastle.Crypto return cipher.GetInputBlockSize(); } - public override int GetOutputSize( - int length) - { - return cipher.GetOutputBlockSize(); + public override int GetOutputSize(int length) + { + return cipher.GetOutputBlockSize(); } - public override int GetUpdateOutputSize( - int length) - { - return 0; + public override int GetUpdateOutputSize(int length) + { + return 0; } /** @@ -64,9 +61,7 @@ namespace Org.BouncyCastle.Crypto * encryption, if false for decryption. * @param param the key and other data required by the cipher. */ - public override void Init( - bool forEncryption, - ICipherParameters parameters) + public override void Init(bool forEncryption, ICipherParameters parameters) { Reset(); @@ -80,11 +75,9 @@ namespace Org.BouncyCastle.Crypto this.bufOff = 0; } - public override byte[] ProcessByte( - byte input) - { - if (bufOff >= buffer.Length) - throw new DataLengthException("attempt to process message too long for cipher"); + public override byte[] ProcessByte(byte input) + { + Check.DataLength(bufOff >= buffer.Length, "attempt to process message too long for cipher"); buffer[bufOff++] = input; return null; @@ -92,8 +85,7 @@ namespace Org.BouncyCastle.Crypto public override int ProcessByte(byte input, byte[] output, int outOff) { - if (bufOff >= buffer.Length) - throw new DataLengthException("attempt to process message too long for cipher"); + Check.DataLength(bufOff >= buffer.Length, "attempt to process message too long for cipher"); buffer[bufOff++] = input; return 0; @@ -102,26 +94,21 @@ namespace Org.BouncyCastle.Crypto #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER public override int ProcessByte(byte input, Span<byte> output) { - if (bufOff >= buffer.Length) - throw new DataLengthException("attempt to process message too long for cipher"); + Check.DataLength(bufOff >= buffer.Length, "attempt to process message too long for cipher"); buffer[bufOff++] = input; return 0; } #endif - public override byte[] ProcessBytes( - byte[] input, - int inOff, - int length) - { - if (length < 1) + public override byte[] ProcessBytes(byte[] input, int inOff, int length) + { + if (length < 1) return null; if (input == null) throw new ArgumentNullException("input"); - if (bufOff + length > buffer.Length) - throw new DataLengthException("attempt to process message too long for cipher"); + Check.DataLength(length > buffer.Length - bufOff, "attempt to process message too long for cipher"); Array.Copy(input, inOff, buffer, bufOff, length); bufOff += length; @@ -158,12 +145,9 @@ namespace Org.BouncyCastle.Crypto return outBytes; } - public override byte[] DoFinal( - byte[] input, - int inOff, - int length) - { - ProcessBytes(input, inOff, length); + public override byte[] DoFinal(byte[] input, int inOff, int length) + { + ProcessBytes(input, inOff, length); return DoFinal(); } |