(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Security.Cryptography / DSASignatureDeformatterTest.cs
blob069e348370a9b872461e49500ce97ef380b36910
1 //
2 // DSASignatureDeformatterTest.cs - NUnit Test Cases for DSASignatureDeformatter
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
31 using System;
32 using System.Security;
33 using System.Security.Cryptography;
35 namespace MonoTests.System.Security.Cryptography {
37 [TestFixture]
38 public class DSASignatureDeformatterTest {
39 protected DSASignatureDeformatter def;
40 protected static DSA dsa;
41 protected static RSA rsa;
43 static byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
44 static byte[] sign = { 0x50, 0xd2, 0xb0, 0x8b, 0xcd, 0x5e, 0xb2, 0xc2, 0x35, 0x82, 0xd3, 0x76, 0x07, 0x79, 0xbb, 0x55, 0x98, 0x72, 0x43, 0xe8,
45 0x74, 0xc9, 0x35, 0xf8, 0xc9, 0xbd, 0x69, 0x2f, 0x08, 0x34, 0xfa, 0x5a, 0x59, 0x23, 0x2a, 0x85, 0x7b, 0xa3, 0xb3, 0x82 };
47 [TestFixtureSetUp]
48 public void FixtureSetUp ()
50 // key generation is VERY long so one time is enough
51 dsa = DSA.Create ();
52 rsa = RSA.Create ();
55 [SetUp]
56 public void SetUp ()
58 def = new DSASignatureDeformatter ();
61 [Test]
62 public void Constructor_Empty ()
64 DSASignatureDeformatter def = new DSASignatureDeformatter ();
65 Assert.IsNotNull (def);
68 [Test]
69 #if NET_2_0
70 [ExpectedException (typeof (ArgumentNullException))]
71 #endif
72 public void Constructor_Null ()
74 DSASignatureDeformatter def = new DSASignatureDeformatter (null);
75 Assert.IsNotNull (def);
78 [Test]
79 public void Constructor_DSA ()
81 DSASignatureDeformatter def = new DSASignatureDeformatter (dsa);
82 Assert.IsNotNull (def);
85 [Test]
86 [ExpectedException (typeof (InvalidCastException))]
87 public void Constructor_RSA ()
89 DSASignatureDeformatter def = new DSASignatureDeformatter (rsa);
92 [Test]
93 [ExpectedException (typeof (ArgumentNullException))]
94 public void SetHash_Null ()
96 def.SetHashAlgorithm (null);
99 [Test]
100 public void SetHash_SHA1 ()
102 def.SetHashAlgorithm ("SHA1");
105 [Test]
106 [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
107 public void SetHash_MD5 ()
109 def.SetHashAlgorithm ("MD5");
112 [Test]
113 #if NET_2_0
114 [ExpectedException (typeof (ArgumentNullException))]
115 #endif
116 public void SetKey_Null ()
118 def.SetKey (null);
121 [Test]
122 [ExpectedException (typeof (InvalidCastException))]
123 public void SetKey_RSA ()
125 def.SetKey (rsa);
128 [Test]
129 public void SetKey_DSA ()
131 def.SetKey (dsa);
134 [Test]
135 [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
136 public void Verify_NoKeyPair ()
138 def.VerifySignature (hash, sign);
141 [Test]
142 [ExpectedException (typeof (ArgumentNullException))]
143 public void Verify_NullSignature ()
145 dsa.ImportParameters (AllTests.GetKey (false));
146 def.SetKey (dsa);
147 def.VerifySignature (hash, null);
150 [Test]
151 [ExpectedException (typeof (ArgumentNullException))]
152 public void Verify_NullHash ()
154 dsa.ImportParameters (AllTests.GetKey (false));
155 def.SetKey (dsa);
156 byte[] s = null; // overloaded method
157 def.VerifySignature (s, sign);
160 [Test]
161 public void Verify ()
163 dsa.ImportParameters (AllTests.GetKey (false));
164 def.SetKey (dsa);
165 Assert.IsTrue (def.VerifySignature (hash, sign));
168 [Test]
169 public void Verify_Bad ()
171 dsa.ImportParameters (AllTests.GetKey (false));
172 def.SetKey (dsa);
173 byte[] badSign = { 0x49, 0xd2, 0xb0, 0x8b, 0xcd, 0x5e, 0xb2, 0xc2, 0x35, 0x82, 0xd3, 0x76, 0x07, 0x79, 0xbb, 0x55, 0x98, 0x72, 0x43, 0xe8,
174 0x74, 0xc9, 0x35, 0xf8, 0xc9, 0xbd, 0x69, 0x2f, 0x08, 0x34, 0xfa, 0x5a, 0x59, 0x23, 0x2a, 0x85, 0x7b, 0xa3, 0xb3, 0x82 };
175 Assert.IsFalse (def.VerifySignature (hash, badSign));