< Summary

Information
Class: Renci.SshNet.Security.Cryptography.Ciphers.Modes.OfbCipherMode
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs
Line coverage
76%
Covered lines: 19
Uncovered lines: 6
Coverable lines: 25
Total lines: 79
Line coverage: 76%
Branch coverage
62%
Covered branches: 5
Total branches: 8
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(...)100%1100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Globalization;
 3
 4namespace Renci.SshNet.Security.Cryptography.Ciphers.Modes
 5{
 6    /// <summary>
 7    /// Implements OFB cipher mode.
 8    /// </summary>
 9    public class OfbCipherMode : CipherMode
 10    {
 11        private readonly byte[] _ivOutput;
 12
 13        /// <summary>
 14        /// Initializes a new instance of the <see cref="OfbCipherMode"/> class.
 15        /// </summary>
 16        /// <param name="iv">The iv.</param>
 17        public OfbCipherMode(byte[] iv)
 5418            : base(iv)
 5419        {
 5420            _ivOutput = new byte[iv.Length];
 5421        }
 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
 12635        {
 12636            if (inputBuffer.Length - inputOffset < _blockSize)
 037            {
 038                throw new ArgumentException("Invalid input buffer");
 39            }
 40
 12641            if (outputBuffer.Length - outputOffset < _blockSize)
 042            {
 043                throw new ArgumentException("Invalid output buffer");
 44            }
 45
 12646            if (inputCount != _blockSize)
 047            {
 048                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "inputCount must be {0}.", _blockS
 49            }
 50
 12651            _ = Cipher.EncryptBlock(IV, 0, IV.Length, _ivOutput, 0);
 52
 12653            Buffer.BlockCopy(_ivOutput, 0, IV, 0, IV.Length);
 54
 428455            for (var i = 0; i < _blockSize; i++)
 201656            {
 201657                outputBuffer[outputOffset + i] = (byte) (_ivOutput[i] ^ inputBuffer[inputOffset + i]);
 201658            }
 59
 12660            return _blockSize;
 12661        }
 62
 63        /// <summary>
 64        /// Decrypts the specified region of the input byte array and copies the decrypted data to the specified region 
 65        /// </summary>
 66        /// <param name="inputBuffer">The input data to decrypt.</param>
 67        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
 68        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
 69        /// <param name="outputBuffer">The output to which to write decrypted data.</param>
 70        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
 71        /// <returns>
 72        /// The number of bytes decrypted.
 73        /// </returns>
 74        public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o
 6375        {
 6376            return EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
 6377        }
 78    }
 79}