< Summary

Information
Class: Renci.SshNet.Security.Cryptography.Ciphers.Modes.CfbCipherMode
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs
Line coverage
71%
Covered lines: 30
Uncovered lines: 12
Coverable lines: 42
Total lines: 105
Line coverage: 71.4%
Branch coverage
62%
Covered branches: 10
Total branches: 16
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
EncryptBlock(...)62.5%868.42%
DecryptBlock(...)62.5%868.42%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3
 4namespace Renci.SshNet.Security.Cryptography.Ciphers.Modes
 5{
 6    /// <summary>
 7    /// Implements CFB cipher mode.
 8    /// </summary>
 9    public class CfbCipherMode : CipherMode
 10    {
 11        private readonly byte[] _ivOutput;
 12
 13        /// <summary>
 14        /// Initializes a new instance of the <see cref="CfbCipherMode"/> class.
 15        /// </summary>
 16        /// <param name="iv">The iv.</param>
 17        public CfbCipherMode(byte[] iv)
 2118            : base(iv)
 2119        {
 2120            _ivOutput = new byte[iv.Length];
 2121        }
 22
 23        /// <summary>
 24        /// Encrypts the specified region of the input byte array and copies the encrypted data to the specified region 
 25        /// </summary>
 26        /// <param name="inputBuffer">The input data to encrypt.</param>
 27        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
 28        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
 29        /// <param name="outputBuffer">The output to which to write encrypted data.</param>
 30        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
 31        /// <returns>
 32        /// The number of bytes encrypted.
 33        /// </returns>
 34        public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o
 2135        {
 2136            if (inputBuffer.Length - inputOffset < _blockSize)
 037            {
 038                throw new ArgumentException("Invalid input buffer");
 39            }
 40
 2141            if (outputBuffer.Length - outputOffset < _blockSize)
 042            {
 043                throw new ArgumentException("Invalid output buffer");
 44            }
 45
 2146            if (inputCount != _blockSize)
 047            {
 048                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "inputCount must be {0}.", _blockS
 49            }
 50
 2151            _ = Cipher.EncryptBlock(IV, 0, IV.Length, _ivOutput, 0);
 52
 71453            for (var i = 0; i < _blockSize; i++)
 33654            {
 33655                outputBuffer[outputOffset + i] = (byte)(_ivOutput[i] ^ inputBuffer[inputOffset + i]);
 33656            }
 57
 2158            Buffer.BlockCopy(IV, _blockSize, IV, 0, IV.Length - _blockSize);
 2159            Buffer.BlockCopy(outputBuffer, outputOffset, IV, IV.Length - _blockSize, _blockSize);
 60
 2161            return _blockSize;
 2162        }
 63
 64        /// <summary>
 65        /// Decrypts the specified region of the input byte array and copies the decrypted data to the specified region 
 66        /// </summary>
 67        /// <param name="inputBuffer">The input data to decrypt.</param>
 68        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
 69        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
 70        /// <param name="outputBuffer">The output to which to write decrypted data.</param>
 71        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
 72        /// <returns>
 73        /// The number of bytes decrypted.
 74        /// </returns>
 75        public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o
 24976        {
 24977            if (inputBuffer.Length - inputOffset < _blockSize)
 078            {
 079                throw new ArgumentException("Invalid input buffer");
 80            }
 81
 24982            if (outputBuffer.Length - outputOffset < _blockSize)
 083            {
 084                throw new ArgumentException("Invalid output buffer");
 85            }
 86
 24987            if (inputCount != _blockSize)
 088            {
 089                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "inputCount must be {0}.", _blockS
 90            }
 91
 24992            _ = Cipher.EncryptBlock(IV, 0, IV.Length, _ivOutput, 0);
 93
 24994            Buffer.BlockCopy(IV, _blockSize, IV, 0, IV.Length - _blockSize);
 24995            Buffer.BlockCopy(inputBuffer, inputOffset, IV, IV.Length - _blockSize, _blockSize);
 96
 481897            for (var i = 0; i < _blockSize; i++)
 216098            {
 216099                outputBuffer[outputOffset + i] = (byte)(_ivOutput[i] ^ inputBuffer[inputOffset + i]);
 2160100            }
 101
 249102            return _blockSize;
 249103        }
 104    }
 105}