< Summary

Information
Class: Renci.SshNet.Security.Org.BouncyCastle.Crypto.Digests.GeneralDigest
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\crypto\digests\GeneralDigest.cs
Line coverage
57%
Covered lines: 37
Uncovered lines: 27
Coverable lines: 64
Total lines: 129
Line coverage: 57.8%
Branch coverage
57%
Covered branches: 8
Total branches: 14
Branch coverage: 57.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor()100%1100%
.ctor(...)100%10%
CopyIn(...)100%10%
Update(...)100%2100%
BlockUpdate(...)40%1046.15%
Finish()100%2100%
Reset()100%1100%
GetByteLength()100%10%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\crypto\digests\GeneralDigest.cs

#LineLine coverage
 1using System;
 2
 3using Renci.SshNet.Security.Org.BouncyCastle.Utilities;
 4
 5namespace Renci.SshNet.Security.Org.BouncyCastle.Crypto.Digests
 6{
 7    internal abstract class GeneralDigest
 8    : IDigest, IMemoable
 9    {
 10        private const int BYTE_LENGTH = 64;
 11
 12        private byte[]  xBuf;
 13        private int     xBufOff;
 14
 15        private long    byteCount;
 16
 1017        internal GeneralDigest()
 1018        {
 1019            xBuf = new byte[4];
 1020        }
 21
 022        internal GeneralDigest(GeneralDigest t)
 023    {
 024      xBuf = new byte[t.xBuf.Length];
 025      CopyIn(t);
 026    }
 27
 28    protected void CopyIn(GeneralDigest t)
 029    {
 030            Array.Copy(t.xBuf, 0, xBuf, 0, t.xBuf.Length);
 31
 032            xBufOff = t.xBufOff;
 033            byteCount = t.byteCount;
 034        }
 35
 36        public void Update(byte input)
 15237        {
 15238            xBuf[xBufOff++] = input;
 39
 15240            if (xBufOff == xBuf.Length)
 3841            {
 3842                ProcessWord(xBuf, 0);
 3843                xBufOff = 0;
 3844            }
 45
 15246            byteCount++;
 15247        }
 48
 49        public void BlockUpdate(
 50            byte[]  input,
 51            int     inOff,
 52            int     length)
 9453        {
 9454            length = System.Math.Max(0, length);
 55
 56            //
 57            // fill the current word
 58            //
 9459            int i = 0;
 9460            if (xBufOff != 0)
 061            {
 062                while (i < length)
 063                {
 064                    xBuf[xBufOff++] = input[inOff + i++];
 065                    if (xBufOff == 4)
 066                    {
 067                        ProcessWord(xBuf, 0);
 068                        xBufOff = 0;
 069                        break;
 70                    }
 071                }
 072            }
 73
 74            //
 75            // process whole words.
 76            //
 9477            int limit = ((length - i) & ~3) + i;
 126278            for (; i < limit; i += 4)
 58479            {
 58480                ProcessWord(input, inOff + i);
 58481            }
 82
 83            //
 84            // load in the remainder.
 85            //
 9486            while (i < length)
 087            {
 088                xBuf[xBufOff++] = input[inOff + i++];
 089            }
 90
 9491            byteCount += length;
 9492        }
 93
 94        public void Finish()
 3895        {
 3896            long    bitLength = (byteCount << 3);
 97
 98            //
 99            // add the pad bytes.
 100            //
 38101            Update((byte)128);
 102
 266103            while (xBufOff != 0) Update((byte)0);
 38104            ProcessLength(bitLength);
 38105            ProcessBlock();
 38106        }
 107
 108        public virtual void Reset()
 38109        {
 38110            byteCount = 0;
 38111            xBufOff = 0;
 38112      Array.Clear(xBuf, 0, xBuf.Length);
 38113        }
 114
 115    public int GetByteLength()
 0116    {
 0117      return BYTE_LENGTH;
 0118    }
 119
 120    internal abstract void ProcessWord(byte[] input, int inOff);
 121        internal abstract void ProcessLength(long bitLength);
 122        internal abstract void ProcessBlock();
 123        public abstract string AlgorithmName { get; }
 124    public abstract int GetDigestSize();
 125        public abstract int DoFinal(byte[] output, int outOff);
 126    public abstract IMemoable Copy();
 127    public abstract void Reset(IMemoable t);
 128    }
 129}