< Summary

Information
Class: Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs
Line coverage
69%
Covered lines: 27
Uncovered lines: 12
Coverable lines: 39
Total lines: 100
Line coverage: 69.2%
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%866.66%
DecryptBlock(...)62.5%866.66%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Globalization;
 3
 4namespace Renci.SshNet.Security.Cryptography.Ciphers.Modes
 5{
 6    /// <summary>
 7    /// Implements CBC cipher mode.
 8    /// </summary>
 9    public class CbcCipherMode : CipherMode
 10    {
 11        /// <summary>
 12        /// Initializes a new instance of the <see cref="CbcCipherMode"/> class.
 13        /// </summary>
 14        /// <param name="iv">The iv.</param>
 15        public CbcCipherMode(byte[] iv)
 4016            : base(iv)
 4017        {
 4018        }
 19
 20        /// <summary>
 21        /// Encrypts the specified region of the input byte array and copies the encrypted data to the specified region 
 22        /// </summary>
 23        /// <param name="inputBuffer">The input data to encrypt.</param>
 24        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
 25        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
 26        /// <param name="outputBuffer">The output to which to write encrypted data.</param>
 27        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
 28        /// <returns>
 29        /// The number of bytes encrypted.
 30        /// </returns>
 31        public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o
 35632        {
 35633            if (inputBuffer.Length - inputOffset < _blockSize)
 034            {
 035                throw new ArgumentException("Invalid input buffer");
 36            }
 37
 35638            if (outputBuffer.Length - outputOffset < _blockSize)
 039            {
 040                throw new ArgumentException("Invalid output buffer");
 41            }
 42
 35643            if (inputCount != _blockSize)
 044            {
 045                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "inputCount must be {0}.", _blockS
 46            }
 47
 640848            for (var i = 0; i < _blockSize; i++)
 284849            {
 284850                IV[i] ^= inputBuffer[inputOffset + i];
 284851            }
 52
 35653            _ = Cipher.EncryptBlock(IV, 0, inputCount, outputBuffer, outputOffset);
 54
 35655            Buffer.BlockCopy(outputBuffer, outputOffset, IV, 0, IV.Length);
 56
 35657            return _blockSize;
 35658        }
 59
 60        /// <summary>
 61        /// Decrypts the specified region of the input byte array and copies the decrypted data to the specified region 
 62        /// </summary>
 63        /// <param name="inputBuffer">The input data to decrypt.</param>
 64        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
 65        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
 66        /// <param name="outputBuffer">The output to which to write decrypted data.</param>
 67        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
 68        /// <returns>
 69        /// The number of bytes decrypted.
 70        /// </returns>
 71        public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o
 209272        {
 209273            if (inputBuffer.Length - inputOffset < _blockSize)
 074            {
 075                throw new ArgumentException("Invalid input buffer");
 76            }
 77
 209278            if (outputBuffer.Length - outputOffset < _blockSize)
 079            {
 080                throw new ArgumentException("Invalid output buffer");
 81            }
 82
 209283            if (inputCount != _blockSize)
 084            {
 085                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "inputCount must be {0}.", _blockS
 86            }
 87
 209288            _ = Cipher.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
 89
 3765690            for (var i = 0; i < _blockSize; i++)
 1673691            {
 1673692                outputBuffer[outputOffset + i] ^= IV[i];
 1673693            }
 94
 209295            Buffer.BlockCopy(inputBuffer, inputOffset, IV, 0, IV.Length);
 96
 209297            return _blockSize;
 209298        }
 99    }
 100}