368c8edece9d7194863b490ccdfb041a31124023
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / SymmetricAlgorithmTest.cs
1 //\r
2 // TestSuite.System.Security.Cryptography.SymmetricAlgorithmTest.cs\r
3 //\r
4 // Author:\r
5 //      Thomas Neidhart (tome@sbox.tugraz.at)\r
6 //\r
7 \r
8 \r
9 using System;\r
10 using System.Security.Cryptography;\r
11 \r
12 using NUnit.Framework;\r
13 \r
14 namespace Testsuite.System.Security.Cryptography {\r
15 \r
16         public class SymmetricAlgorithmTest : TestCase {\r
17                 private SymmetricAlgorithm _algo;\r
18                 \r
19                 public SymmetricAlgorithmTest(String name) : base(name) {\r
20                         _algo = null;\r
21                 }\r
22                 \r
23                 public static ITest Suite {\r
24                         get {\r
25                                 return new TestSuite(typeof(SymmetricAlgorithmTest));\r
26                         }\r
27                 }\r
28 \r
29                 protected override void SetUp() {\r
30                         _algo = SymmetricAlgorithm.Create();\r
31                 }\r
32 \r
33                 private void SetDefaultData() {\r
34                 }\r
35                 \r
36                 public void TestProperties() {\r
37                         Assert("Properties (1)", _algo != null);\r
38                         \r
39                         bool thrown = false;\r
40                         try \r
41                         {\r
42                                 // try setting an illegal blocksize -> must throw an exception\r
43                                 _algo.BlockSize = 12;\r
44                         } catch (CryptographicException) {thrown = true;}\r
45                         Assert("Properties (2)", thrown);\r
46                         \r
47                         byte[] key = _algo.Key;\r
48                         Assert("Properties (3)", key != null);\r
49                         \r
50                         thrown = false;\r
51                         try {\r
52                                 KeySizes[] keys = _algo.LegalKeySizes;\r
53                                 foreach (KeySizes myKey in keys) {\r
54                                         for (int i=myKey.MinSize; i<=myKey.MaxSize; i+=myKey.SkipSize) {\r
55                                                 _algo.KeySize = i;\r
56                                         }\r
57                                 }\r
58                         } catch (CryptographicException) {thrown=true;}\r
59                         Assert("Properties (4)", !thrown);\r
60                 }\r
61         }\r
62 }\r