2 // DSASignatureDeformatterTest.cs - NUnit Test Cases for DSASignatureDeformatter
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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
;
32 using System
.Security
;
33 using System
.Security
.Cryptography
;
35 namespace MonoTests
.System
.Security
.Cryptography
{
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 };
48 public void FixtureSetUp ()
50 // key generation is VERY long so one time is enough
58 def
= new DSASignatureDeformatter ();
62 public void Constructor_Empty ()
64 DSASignatureDeformatter def
= new DSASignatureDeformatter ();
65 Assert
.IsNotNull (def
);
70 [ExpectedException (typeof (ArgumentNullException
))]
72 public void Constructor_Null ()
74 DSASignatureDeformatter def
= new DSASignatureDeformatter (null);
75 Assert
.IsNotNull (def
);
79 public void Constructor_DSA ()
81 DSASignatureDeformatter def
= new DSASignatureDeformatter (dsa
);
82 Assert
.IsNotNull (def
);
86 [ExpectedException (typeof (InvalidCastException
))]
87 public void Constructor_RSA ()
89 DSASignatureDeformatter def
= new DSASignatureDeformatter (rsa
);
93 [ExpectedException (typeof (ArgumentNullException
))]
94 public void SetHash_Null ()
96 def
.SetHashAlgorithm (null);
100 public void SetHash_SHA1 ()
102 def
.SetHashAlgorithm ("SHA1");
106 [ExpectedException (typeof (CryptographicUnexpectedOperationException
))]
107 public void SetHash_MD5 ()
109 def
.SetHashAlgorithm ("MD5");
114 [ExpectedException (typeof (ArgumentNullException
))]
116 public void SetKey_Null ()
122 [ExpectedException (typeof (InvalidCastException
))]
123 public void SetKey_RSA ()
129 public void SetKey_DSA ()
135 [ExpectedException (typeof (CryptographicUnexpectedOperationException
))]
136 public void Verify_NoKeyPair ()
138 def
.VerifySignature (hash
, sign
);
142 [ExpectedException (typeof (ArgumentNullException
))]
143 public void Verify_NullSignature ()
145 dsa
.ImportParameters (AllTests
.GetKey (false));
147 def
.VerifySignature (hash
, null);
151 [ExpectedException (typeof (ArgumentNullException
))]
152 public void Verify_NullHash ()
154 dsa
.ImportParameters (AllTests
.GetKey (false));
156 byte[] s
= null; // overloaded method
157 def
.VerifySignature (s
, sign
);
161 public void Verify ()
163 dsa
.ImportParameters (AllTests
.GetKey (false));
165 Assert
.IsTrue (def
.VerifySignature (hash
, sign
));
169 public void Verify_Bad ()
171 dsa
.ImportParameters (AllTests
.GetKey (false));
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
));