< Summary

Information
Class: Renci.SshNet.Security.Org.BouncyCastle.Crypto.Prng.CryptoApiRandomGenerator
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\crypto\prng\CryptoApiRandomGenerator.cs
Line coverage
34%
Covered lines: 10
Uncovered lines: 19
Coverable lines: 29
Total lines: 59
Line coverage: 34.4%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor()100%1100%
.ctor(...)100%1100%
AddSeedMaterial(...)100%10%
AddSeedMaterial(...)100%10%
NextBytes(...)100%1100%
NextBytes(...)0%80%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\crypto\prng\CryptoApiRandomGenerator.cs

#LineLine coverage
 1using System;
 2using System.Security.Cryptography;
 3
 4namespace Renci.SshNet.Security.Org.BouncyCastle.Crypto.Prng
 5{
 6    internal class CryptoApiRandomGenerator
 7        : IRandomGenerator
 8    {
 9        private readonly RandomNumberGenerator rndProv;
 10
 11        public CryptoApiRandomGenerator()
 112            : this(Abstractions.CryptoAbstraction.CreateRandomNumberGenerator())
 113        {
 114        }
 15
 116        public CryptoApiRandomGenerator(RandomNumberGenerator rng)
 117        {
 118            this.rndProv = rng;
 119        }
 20
 21        #region IRandomGenerator Members
 22
 23        public virtual void AddSeedMaterial(byte[] seed)
 024        {
 25            // We don't care about the seed
 026        }
 27
 28        public virtual void AddSeedMaterial(long seed)
 029        {
 30            // We don't care about the seed
 031        }
 32
 33        public virtual void NextBytes(byte[] bytes)
 1034        {
 1035            rndProv.GetBytes(bytes);
 1036        }
 37
 38        public virtual void NextBytes(byte[] bytes, int start, int len)
 039        {
 040            if (start < 0)
 041                throw new ArgumentException("Start offset cannot be negative", "start");
 042            if (bytes.Length < (start + len))
 043                throw new ArgumentException("Byte array too small for requested offset and length");
 44
 045            if (bytes.Length == len && start == 0)
 046            {
 047                NextBytes(bytes);
 048            }
 49            else
 050            {
 051                byte[] tmpBuf = new byte[len];
 052                NextBytes(tmpBuf);
 053                Array.Copy(tmpBuf, 0, bytes, start, len);
 054            }
 055        }
 56
 57        #endregion
 58    }
 59}