2 // TestSuite.System.Security.Cryptography.RNGCryptoServiceProviderTest.cs
5 // Mark Crichton (crichton@gimp.org)
6 // Sebastien Pouliot (sebastien@ximian.com)
8 // Copyright (C) 2004 Novell (http://www.novell.com)
12 using System
.Security
.Cryptography
;
14 using NUnit
.Framework
;
16 namespace MonoTests
.System
.Security
.Cryptography
{
19 public class RNGCryptoServiceProviderTest
: Assertion
{
21 private RNGCryptoServiceProvider _algo
;
26 _algo
= new RNGCryptoServiceProvider ();
30 public void ConstructorByteArray ()
32 byte[] array
= new byte [16];
33 byte[] seed
= (byte[]) array
.Clone ();
34 RNGCryptoServiceProvider rng
= new RNGCryptoServiceProvider (seed
);
35 AssertEquals ("Seed", BitConverter
.ToString (array
), BitConverter
.ToString (seed
));
39 public void ConstructorByteArray_Null ()
42 RNGCryptoServiceProvider rng
= new RNGCryptoServiceProvider (array
);
46 public void ConstructorCsp_Null ()
48 CspParameters csp
= null;
49 RNGCryptoServiceProvider rng
= new RNGCryptoServiceProvider (csp
);
53 public void ConstructorString ()
55 string s
= "Mono seed";
56 RNGCryptoServiceProvider rng
= new RNGCryptoServiceProvider (s
);
57 AssertEquals ("Seed", "Mono seed", s
);
61 public void ConstructorString_Null ()
64 RNGCryptoServiceProvider rng
= new RNGCryptoServiceProvider (s
);
68 public void GetBytes ()
70 byte[] random
= new byte [25];
71 // The C code doesn't throw an exception yet.
72 _algo
.GetBytes (random
);
76 public void GetNonZeroBytes ()
78 byte[] random
= new byte [25];
79 // This one we can check...
80 _algo
.GetNonZeroBytes (random
);
82 foreach (Byte rnd_byte
in random
) {
83 Assert("Properties (2)", rnd_byte
!= 0);
88 [ExpectedException (typeof (ArgumentNullException
))]
89 public void GetBytesNull ()
91 _algo
.GetBytes (null);
95 [ExpectedException (typeof (ArgumentNullException
))]
96 public void GetNonZeroBytesNull ()
98 _algo
.GetNonZeroBytes (null);