Beispiel #1
0
        public void GetBytesCountTest(int byteCount)
        {
            IPrng prng = new PrngSHA256();

            byte[] bytes = prng.GetRandomBytes(byteCount);

            Assert.True(bytes.Length == byteCount);
        }
Beispiel #2
0
        public void NegativeByteCountTest()
        {
            const int byteCounnt = -1;
            IPrng     prng       = new PrngSHA256();

            byte[]    bytes;
            Exception ex = Assert.Throws <ArgumentException>(() => bytes = prng.GetRandomBytes(byteCounnt));

            Assert.Contains("A non-negative integer is required.", ex.Message);
        }
Beispiel #3
0
        public void GetBytesEntropyTest(int byteCount)
        {
            IPrng prng     = new PrngSHA256();
            bool  isFilled = false;

            byte[] bytes = prng.GetRandomBytes(byteCount);
            foreach (var b in bytes)
            {
                if (Convert.ToInt32(b) > 0)
                {
                    //Testing that we are getting at least some non-zero values. Not testing the quality of the PRNG.
                    isFilled = true;
                }
            }

            Assert.True(isFilled);
        }