Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -173,28 +173,12 @@ namespace MonoTests.System.Security.Cryptography {
Assert.AreEqual ("F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-D4-E9-69-25-C0-BF-CF-FB-52-F8-A1-87-EE-77-4A-AB-C3-28-91-ED-46-6E-6F-98-C1-4D-65-14-ED-9D-1E-5B",
Roundtrip (Rijndael.Create (), CipherMode.CBC), "Encrypted data");
}
#if NET_2_0
[Test]
public void Rijndael_CFB ()
{
Assert.AreEqual ("F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-D4-E9-69-25-C0-BF-CF-FB-52-F8-A1-87-EE-77-4A-AB-26-03-7F-B7-B5-88-AE-0A-F8-AF-1E-CF-9C-F5-3A-8A",
Roundtrip (Rijndael.Create (), CipherMode.CFB), "Encrypted data");
}
#else
// CFB was confused with OFB in Fx 1.0 and 1.1 (and wasn't supported because of that)
// However Mono does support it (because the same code is executed for all managed ciphers).
[Test]
public void Rijndael_CFB ()
{
try {
Assert.AreEqual ("F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-D4-E9-69-25-C0-BF-CF-FB-52-F8-A1-87-EE-77-4A-AB-26-03-7F-B7-B5-88-AE-0A-F8-AF-1E-CF-9C-F5-3A-8A",
Roundtrip (Rijndael.Create (), CipherMode.CFB), "Encrypted data");
}
catch (CryptographicException) {
// we assume this is the bugged MS implementation
}
}
#endif
[Test]
[ExpectedException (typeof (CryptographicException))]
public void Rijndael_OFB ()

View File

@@ -168,7 +168,6 @@ public class CryptoConfigTest {
CreateFromName ("http://www.w3.org/2000/09/xmldsig# KeyValue/DSAKeyValue", "System.Security.Cryptography.Xml.DSAKeyValue");
CreateFromName ("http://www.w3.org/2000/09/xmldsig# KeyValue/RSAKeyValue", "System.Security.Cryptography.Xml.RSAKeyValue");
CreateFromName ("http://www.w3.org/2000/09/xmldsig# RetrievalMethod", "System.Security.Cryptography.Xml.KeyInfoRetrievalMethod");
#if NET_2_0
CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha256", "System.Security.Cryptography.SHA256Managed");
CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha384", null);
CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha512", "System.Security.Cryptography.SHA512Managed");
@@ -177,47 +176,30 @@ public class CryptoConfigTest {
CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384", "System.Security.Cryptography.HMACSHA384");
CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha512", "System.Security.Cryptography.HMACSHA512");
CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160", "System.Security.Cryptography.HMACRIPEMD160");
#endif
}
[Test]
public void CreateFromName_UpperCase ()
{
CreateFromName ("SHA", "System.Security.Cryptography.SHA1CryptoServiceProvider");
#if NET_2_0
CreateFromName ("SYSTEM.SECURITY.CRYPTOGRAPHY.TRIPLEDES", "System.Security.Cryptography.TripleDESCryptoServiceProvider");
CreateFromName ("HTTP://WWW.W3.ORG/2000/09/XMLDSIG#DSA-SHA1", "System.Security.Cryptography.DSASignatureDescription");
#else
CreateFromName ("SYSTEM.SECURITY.CRYPTOGRAPHY.TRIPLEDES", null);
CreateFromName ("HTTP://WWW.W3.ORG/2000/09/XMLDSIG#DSA-SHA1", null);
#endif
}
[Test]
public void CreateFromName_LowerCase ()
{
#if NET_2_0
CreateFromName ("sha", "System.Security.Cryptography.SHA1CryptoServiceProvider");
CreateFromName ("system.security.cryptography.tripledes", "System.Security.Cryptography.TripleDESCryptoServiceProvider");
#else
CreateFromName ("sha", null);
CreateFromName ("system.security.cryptography.tripledes", null);
#endif
CreateFromName ("http://www.w3.org/2000/09/xmldsig#dsa-sha1", "System.Security.Cryptography.DSASignatureDescription");
}
[Test]
public void CreateFromName_MixedCase ()
{
#if NET_2_0
CreateFromName ("ShA", "System.Security.Cryptography.SHA1CryptoServiceProvider");
CreateFromName ("SyStEm.SeCuRiTy.CrYpToGrApHy.TrIpLeDeS", "System.Security.Cryptography.TripleDESCryptoServiceProvider");
CreateFromName ("hTtP://wWw.W3.oRg/2000/09/xMlDsIg#dSa-sHa1", "System.Security.Cryptography.DSASignatureDescription");
#else
CreateFromName ("ShA", null);
CreateFromName ("SyStEm.SeCuRiTy.CrYpToGrApHy.TrIpLeDeS", null);
CreateFromName ("hTtP://wWw.W3.oRg/2000/09/xMlDsIg#dSa-sHa1", null);
#endif
}
// Tests created using "A Layer Man Guide to ASN.1" from RSA, page 19-20
@@ -228,11 +210,7 @@ public class CryptoConfigTest {
static byte[] oidmd5withRSAEncryption = { 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x04 };
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void EncodeOIDNull ()
{
byte[] o = CryptoConfig.EncodeOID (null);
@@ -329,7 +307,6 @@ public class CryptoConfigTest {
MapNameToOID ("MD5", "1.2.840.113549.2.5");
MapNameToOID ("System.Security.Cryptography.MD5", "1.2.840.113549.2.5");
MapNameToOID ("System.Security.Cryptography.MD5CryptoServiceProvider", "1.2.840.113549.2.5");
#if NET_2_0
MapNameToOID ("SHA256", "2.16.840.1.101.3.4.2.1");
MapNameToOID ("System.Security.Cryptography.SHA256", "2.16.840.1.101.3.4.2.1");
MapNameToOID ("System.Security.Cryptography.SHA256Managed", "2.16.840.1.101.3.4.2.1");
@@ -342,33 +319,12 @@ public class CryptoConfigTest {
MapNameToOID ("RIPEMD160", "1.3.36.3.2.1");
MapNameToOID ("System.Security.Cryptography.RIPEMD160", "1.3.36.3.2.1");
MapNameToOID ("System.Security.Cryptography.RIPEMD160Managed", "1.3.36.3.2.1");
#else
MapNameToOID ("SHA256", "2.16.840.1.101.3.4.1");
// MapNameToOID ("SHA-256", "2.16.840.1.101.3.4.1");
MapNameToOID ("System.Security.Cryptography.SHA256", "2.16.840.1.101.3.4.1");
MapNameToOID ("System.Security.Cryptography.SHA256Managed", "2.16.840.1.101.3.4.1");
MapNameToOID ("SHA384", "2.16.840.1.101.3.4.2");
// MapNameToOID ("SHA-384", "2.16.840.1.101.3.4.2");
MapNameToOID ("System.Security.Cryptography.SHA384", "2.16.840.1.101.3.4.2");
MapNameToOID ("System.Security.Cryptography.SHA384Managed", "2.16.840.1.101.3.4.2");
MapNameToOID ("SHA512", "2.16.840.1.101.3.4.3");
// MapNameToOID ("SHA-512", "2.16.840.1.101.3.4.3");
MapNameToOID ("System.Security.Cryptography.SHA512", "2.16.840.1.101.3.4.3");
MapNameToOID ("System.Security.Cryptography.SHA512Managed", "2.16.840.1.101.3.4.3");
#endif
// LAMESPEC: only documentated in ".NET Framework Security" book
MapNameToOID ("TripleDESKeyWrap", "1.2.840.113549.1.9.16.3.6");
#if NET_2_0
// new OID defined in Fx 2.0
MapNameToOID ("DES", "1.3.14.3.2.7");
MapNameToOID ("TripleDES", "1.2.840.113549.3.7");
MapNameToOID ("RC2", "1.2.840.113549.3.2");
#else
// no OID defined before Fx 2.0
MapNameToOID ("DES", null);
MapNameToOID ("TripleDES", null);
MapNameToOID ("RC2", null);
#endif
MapNameToOID ("RSA", null);
MapNameToOID ("DSA", null);
MapNameToOID ("3DES", null);
@@ -387,7 +343,6 @@ public class CryptoConfigTest {
MapNameToOID ("RandomNumberGenerator", null);
MapNameToOID ("System.Security.Cryptography.RandomNumberGenerator", null);
MapNameToOID ("System.Security.Cryptography.KeyedHashAlgorithm", null);
#if NET_2_0
MapNameToOID ("HMAC", null);
MapNameToOID ("System.Security.Cryptography.HMAC", null);
MapNameToOID ("HMACMD5", null);
@@ -400,7 +355,6 @@ public class CryptoConfigTest {
MapNameToOID ("System.Security.Cryptography.HMACSHA384", null);
MapNameToOID ("HMACSHA512", null);
MapNameToOID ("System.Security.Cryptography.HMACSHA512", null);
#endif
MapNameToOID ("HMACSHA1", null);
MapNameToOID ("System.Security.Cryptography.HMACSHA1", null);
MapNameToOID ("MACTripleDES", null);
@@ -413,35 +367,21 @@ public class CryptoConfigTest {
public void MapNameToOID_UpperCase ()
{
MapNameToOID ("SHA1", "1.3.14.3.2.26");
#if NET_2_0
MapNameToOID ("SYSTEM.SECURITY.CRYPTOGRAPHY.MD5CRYPTOSERVICEPROVIDER", "1.2.840.113549.2.5");
#else
MapNameToOID ("SYSTEM.SECURITY.CRYPTOGRAPHY.MD5CRYPTOSERVICEPROVIDER", null);
#endif
}
[Test]
public void MapNameToOID_LowerCase ()
{
#if NET_2_0
MapNameToOID ("sha1", "1.3.14.3.2.26");
MapNameToOID ("system.security.cryptography.md5cryptoserviceprovider", "1.2.840.113549.2.5");
#else
MapNameToOID ("sha1", null);
MapNameToOID ("system.security.cryptography.md5cryptoserviceprovider", null);
#endif
}
[Test]
public void MapNameToOID_MixedCase ()
{
#if NET_2_0
MapNameToOID ("sHa1", "1.3.14.3.2.26");
MapNameToOID ("SySteM.SeCuRiTy.CrYpToGrApHy.Md5cRyPtOsErViCePrOvIdEr", "1.2.840.113549.2.5");
#else
MapNameToOID ("sHa1", null);
MapNameToOID ("SySteM.SeCuRiTy.CrYpToGrApHy.Md5cRyPtOsErViCePrOvIdEr", null);
#endif
}
[Test]

View File

@@ -274,9 +274,6 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if ONLY_1_1
[ExpectedException (typeof (NotSupportedException))]
#endif
public void FlushFinalBlockReadStream ()
{
cs = new CryptoStream (readStream, encryptor, CryptoStreamMode.Read);
@@ -299,11 +296,7 @@ namespace MonoTests.System.Security.Cryptography {
[Test]
// LAMESPEC or MS BUG [ExpectedException (typeof (ObjectDisposedException))]
#if NET_2_0
[ExpectedException (typeof (NotSupportedException))]
#else
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void FlushFinalBlock_Disposed ()
{
// do no corrupt writeStream in further tests
@@ -316,9 +309,6 @@ namespace MonoTests.System.Security.Cryptography {
[Test]
// LAMESPEC or MS BUG [ExpectedException (typeof (ObjectDisposedException))]
#if ONLY_1_1
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void Read_Disposed ()
{
// do no corrupt readStream in further tests
@@ -333,13 +323,8 @@ namespace MonoTests.System.Security.Cryptography {
#if !NET_2_1
[Test]
// MS BUG [ExpectedException (typeof (ObjectDisposedException))]
#if NET_2_0
[Category ("NotWorking")]
[ExpectedException (typeof (IndexOutOfRangeException))]
#else
[Category ("NotDotNet")] // Test cause System.ExecutionEngineException on MS runtime
[ExpectedException (typeof (ArgumentNullException))] // should fail like previous test case
#endif
public void Read_Disposed_Break ()
{
// do no corrupt readStream in further tests
@@ -437,13 +422,8 @@ namespace MonoTests.System.Security.Cryptography {
#if !NET_2_1
[Test]
// MS BUG [ExpectedException (typeof (ObjectDisposedException))]
#if NET_2_0
[Category ("NotWorking")]
[ExpectedException (typeof (IndexOutOfRangeException))]
#else
[Category ("NotDotNet")] // Test cause System.ExecutionEngineException on MS runtime
[ExpectedException (typeof (ArgumentNullException))] // to match exception throw by Read in a similar case
#endif
public void Write_Disposed ()
{
// do no corrupt writeStream in further tests
@@ -839,9 +819,7 @@ namespace MonoTests.System.Security.Cryptography {
Assert.AreEqual ("ximian", Encoding.Unicode.GetString (data, 0, len), "Unicode DES Roundtrip");
}
#if NET_2_0
[Category ("NotWorking")]
#endif
[Test]
public void DecryptPartial_TransformFinalBlock_2Pass ()
{
@@ -868,9 +846,7 @@ namespace MonoTests.System.Security.Cryptography {
}
// based on http://www.c-sharpcorner.com/Code/2002/May/FileEncryption.asp
#if NET_2_0
[Category ("NotWorking")]
#endif
[Test]
public void WriteByteReadByte ()
{
@@ -1262,9 +1238,7 @@ namespace MonoTests.System.Security.Cryptography {
byte[] digest = hash.Hash;
Assert.AreEqual ("71-04-12-D1-95-01-CF-F9-8D-8F-F8-0D-F9-AA-11-7D", BitConverter.ToString (digest), "Hash");
}
#if NET_2_0
[Category ("NotWorking")]
#endif
[Test]
public void CascadedCryptoStream_Read ()
{
@@ -1385,10 +1359,8 @@ namespace MonoTests.System.Security.Cryptography {
WriteByte (PaddingMode.None, false);
WriteByte (PaddingMode.Zeros, false);
WriteByte (PaddingMode.PKCS7, true); // related to bug #81597
#if NET_2_0
WriteByte (PaddingMode.ANSIX923, true);
WriteByte (PaddingMode.ISO10126, true);
#endif
}
[Test]

View File

@@ -38,34 +38,25 @@ namespace MonoTests.System.Security.Cryptography {
[Test]
public void Values ()
{
#if NET_2_0
Assert.AreEqual ((int)CspProviderFlags.NoFlags, 0, "NoFlags");
#endif
Assert.AreEqual ((int)CspProviderFlags.UseMachineKeyStore, 1, "UseMachineKeyStore");
Assert.AreEqual ((int)CspProviderFlags.UseDefaultKeyContainer, 2, "UseDefaultKeyContainer");
#if NET_2_0
Assert.AreEqual ((int)CspProviderFlags.NoPrompt, 64, "NoPrompt");
Assert.AreEqual ((int)CspProviderFlags.UseArchivableKey, 16, "UseArchivableKey");
Assert.AreEqual ((int)CspProviderFlags.UseExistingKey, 8, "UseExistingKey");
Assert.AreEqual ((int)CspProviderFlags.UseNonExportableKey, 4, "UseNonExportableKey");
Assert.AreEqual ((int)CspProviderFlags.UseUserProtectedKey, 32, "UseUserProtectedKey");
#endif
}
[Test]
public void Flags ()
{
CspProviderFlags cpf = CspProviderFlags.UseDefaultKeyContainer | CspProviderFlags.UseMachineKeyStore
#if NET_2_0
| CspProviderFlags.NoFlags | CspProviderFlags.NoPrompt
| CspProviderFlags.UseArchivableKey | CspProviderFlags.UseExistingKey
| CspProviderFlags.UseNonExportableKey | CspProviderFlags.UseUserProtectedKey;
int expected = 127;
#else
;
int expected = 3;
#endif
Assert.AreEqual (expected, (int)cpf, "All");
}
}

View File

@@ -62,11 +62,7 @@ namespace MonoTests.System.Security.Cryptography {
// (in DESTest.cs) but executed here
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void CreateEncryptor_KeyNull ()
{
ICryptoTransform encryptor = des.CreateEncryptor (null, des.IV);
@@ -116,11 +112,7 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void CreateDecryptor_KeyNull ()
{
ICryptoTransform encryptor = des.CreateEncryptor (des.Key, des.IV);
@@ -185,18 +177,14 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateEncryptor_IV_Zero ()
{
CreateEncryptor_IV (0);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateEncryptor_IV_TooSmall ()
{
int size = (des.BlockSize >> 3) - 1;
@@ -230,18 +218,14 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateDecryptor_IV_Zero ()
{
CreateDecryptor_IV (0);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateDecryptor_IV_TooSmall ()
{
int size = (des.BlockSize >> 3) - 1;

View File

@@ -1 +1 @@
b10cbf3693449292ac103b05ea7691685ac44c3b
574b4b3c64d4d56d2b9aa666f98c276172ec048c

View File

@@ -65,9 +65,7 @@ public class DSASignatureDeformatterTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void Constructor_Null ()
{
DSASignatureDeformatter def = new DSASignatureDeformatter (null);
@@ -109,9 +107,7 @@ public class DSASignatureDeformatterTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void SetKey_Null ()
{
def.SetKey (null);

View File

@@ -68,9 +68,7 @@ public class DSASignatureFormatterTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void Constructor_Null ()
{
DSASignatureFormatter fmt = new DSASignatureFormatter (null);
@@ -105,9 +103,7 @@ public class DSASignatureFormatterTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void SetKey_Null ()
{
fmt.SetKey (null);

View File

@@ -33,7 +33,6 @@ using System.Security.Cryptography;
namespace MonoTests.System.Security.Cryptography {
#if NET_2_0
public class NonAbstractDSAForUnitTests : DSA {
protected DSAParameters dsa;
@@ -89,7 +88,6 @@ namespace MonoTests.System.Security.Cryptography {
protected override void Dispose (bool disposing) { }
}
#endif
[TestFixture]
public class DSATest {
@@ -103,11 +101,7 @@ namespace MonoTests.System.Security.Cryptography {
[SetUp]
public void SetUp ()
{
#if NET_2_0
dsa = new NonAbstractDSAForUnitTests ();
#else
dsa = new DSACryptoServiceProvider ();
#endif
}
public void AssertEquals (string msg, byte [] array1, byte [] array2)
@@ -158,11 +152,7 @@ namespace MonoTests.System.Security.Cryptography {
// importing and exporting a DSA key (including private key)
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (CryptographicException))]
#endif
public void DSAImportPublicExportPrivate ()
{
DSAParameters input = AllTests.GetKey (false);

View File

@@ -8,7 +8,6 @@
// Copyright (C) 2006, 2007 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using NUnit.Framework;
using System;
@@ -214,4 +213,3 @@ namespace MonoTests.System.Security.Cryptography {
}
#endif

View File

@@ -28,7 +28,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
@@ -417,12 +416,14 @@ namespace MonoTests.System.Security.Cryptography {
[Test]
public void Invariants ()
{
var hmac = new HMACRIPEMD160 ();
Assert.IsTrue (hmac.CanReuseTransform, "HMACRIPEMD160.CanReuseTransform");
Assert.IsTrue (hmac.CanTransformMultipleBlocks, "HMACRIPEMD160.CanTransformMultipleBlocks");
Assert.AreEqual ("RIPEMD160", hmac.HashName, "HMACRIPEMD160.HashName");
Assert.AreEqual (160, hmac.HashSize, "HMACRIPEMD160.HashSize");
Assert.AreEqual (1, hmac.InputBlockSize, "HMACRIPEMD160.InputBlockSize");
Assert.AreEqual (1, hmac.OutputBlockSize, "HMACRIPEMD160.OutputBlockSize");
Assert.AreEqual (64, hmac.Key.Length, "HMACRIPEMD160.Key.Length");
Assert.AreEqual ("System.Security.Cryptography.HMACRIPEMD160", hmac.ToString (), "HMACRIPEMD160.ToString()");
}
@@ -435,4 +436,3 @@ namespace MonoTests.System.Security.Cryptography {
}
}
#endif

View File

@@ -35,7 +35,6 @@ using System.Text;
namespace MonoTests.System.Security.Cryptography {
#if NET_2_0
public class HS160 : HMACSHA1 {
public int BlockSize {
@@ -43,7 +42,6 @@ namespace MonoTests.System.Security.Cryptography {
set { base.BlockSizeValue = value; }
}
}
#endif
// References:
// a. The Keyed-Hash Message Authentication Code (HMAC)
@@ -90,28 +88,16 @@ public class HMACSHA1Test : KeyedHashAlgorithmTest {
Assert.AreEqual (160, algo.HashSize, "HMACSHA1.HashSize");
Assert.AreEqual (1, algo.InputBlockSize, "HMACSHA1.InputBlockSize");
Assert.AreEqual (1, algo.OutputBlockSize, "HMACSHA1.OutputBlockSize");
Assert.AreEqual (64, algo.Key.Length, "HMACSHA1.Key.Length");
Assert.AreEqual ("System.Security.Cryptography.HMACSHA1", algo.ToString (), "HMACSHA1.ToString()");
}
#if NET_2_0
[Test]
public void BlockSize ()
{
HS160 hmac = new HS160 ();
Assert.AreEqual (64, hmac.BlockSize, "BlockSizeValue");
}
#else
// this is legal in .NET 2.0 because HMACSHA1 derives from HMAC
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void InvalidHashName ()
{
algo = new HMACSHA1 ();
algo.HashName = "MD5";
byte[] data = Encoding.Default.GetBytes ("MD5");
byte[] hmac = algo.ComputeHash (data);
}
#endif
public void Check (string testName, byte[] key, byte[] data, byte[] result)
{
@@ -126,11 +112,7 @@ public class HMACSHA1Test : KeyedHashAlgorithmTest {
public void CheckA (string testName, byte[] key, byte[] data, byte[] result)
{
#if NET_2_0
algo = new HMACSHA1 (key, true);
#else
algo = new HMACSHA1 (key);
#endif
byte[] hmac = algo.ComputeHash (data);
Assert.AreEqual (result, hmac, testName + "a1");
Assert.AreEqual (result, algo.Hash, testName + "a2");
@@ -138,11 +120,7 @@ public class HMACSHA1Test : KeyedHashAlgorithmTest {
public void CheckB (string testName, byte[] key, byte[] data, byte[] result)
{
#if NET_2_0
algo = new HMACSHA1 (key, false);
#else
algo = new HMACSHA1 (key);
#endif
byte[] hmac = algo.ComputeHash (data, 0, data.Length);
Assert.AreEqual (result, hmac, testName + "b1");
Assert.AreEqual (result, algo.Hash, testName + "b2");

View File

@@ -8,7 +8,6 @@
// Copyright (C) 2006, 2007 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using NUnit.Framework;
using System;
@@ -69,12 +68,14 @@ namespace MonoTests.System.Security.Cryptography {
[Test]
public void Invariants ()
{
var algo = new HMACSHA256 ();
Assert.IsTrue (algo.CanReuseTransform, "HMACSHA256.CanReuseTransform");
Assert.IsTrue (algo.CanTransformMultipleBlocks, "HMACSHA256.CanTransformMultipleBlocks");
Assert.AreEqual ("SHA256", algo.HashName, "HMACSHA256.HashName");
Assert.AreEqual (256, algo.HashSize, "HMACSHA256.HashSize");
Assert.AreEqual (1, algo.InputBlockSize, "HMACSHA256.InputBlockSize");
Assert.AreEqual (1, algo.OutputBlockSize, "HMACSHA256.OutputBlockSize");
Assert.AreEqual (64, algo.Key.Length, "HMACSHA256.Key.Length");
Assert.AreEqual ("System.Security.Cryptography.HMACSHA256", algo.ToString (), "HMACSHA256.ToString()");
}
@@ -254,4 +255,3 @@ namespace MonoTests.System.Security.Cryptography {
}
}
#endif

View File

@@ -8,7 +8,6 @@
// Copyright (C) 2006, 2007 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using NUnit.Framework;
using System;
@@ -90,6 +89,7 @@ namespace MonoTests.System.Security.Cryptography {
Assert.AreEqual (384, algo.HashSize, "HMACSHA384.HashSize");
Assert.AreEqual (1, algo.InputBlockSize, "HMACSHA384.InputBlockSize");
Assert.AreEqual (1, algo.OutputBlockSize, "HMACSHA384.OutputBlockSize");
Assert.AreEqual (128, algo.Key.Length, "HMACSHA384.Key.Length");
Assert.AreEqual ("System.Security.Cryptography.HMACSHA384", algo.ToString (), "HMACSHA384.ToString()");
}
@@ -380,4 +380,3 @@ namespace MonoTests.System.Security.Cryptography {
}
}
#endif

View File

@@ -88,6 +88,7 @@ namespace MonoTests.System.Security.Cryptography {
Assert.AreEqual (512, algo.HashSize, "HMACSHA512.HashSize");
Assert.AreEqual (1, algo.InputBlockSize, "HMACSHA512.InputBlockSize");
Assert.AreEqual (1, algo.OutputBlockSize, "HMACSHA512.OutputBlockSize");
Assert.AreEqual (128, algo.Key.Length, "HMACSHA512.Key.Length");
Assert.AreEqual ("System.Security.Cryptography.HMACSHA512", algo.ToString (), "HMACSHA512.ToString()");
}

View File

@@ -268,9 +268,6 @@ public class HashAlgorithmTest {
}
[Test]
#if ONLY_1_1
[Category ("NotDotNet")] // System.ExecutionEngineException on MS runtime (1.1)
#endif
public void TransformBlock_OutputBuffer_Null ()
{
byte[] input = new byte [8];
@@ -278,11 +275,7 @@ public class HashAlgorithmTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentOutOfRangeException))]
#else
[ExpectedException (typeof (IndexOutOfRangeException))]
#endif
public void TransformBlock_OutputOffset_Negative ()
{
byte[] input = new byte [8];
@@ -291,11 +284,7 @@ public class HashAlgorithmTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#else
[ExpectedException (typeof (IndexOutOfRangeException))]
#endif
public void TransformBlock_OutputOffset_Overflow ()
{
byte[] input = new byte [8];

View File

@@ -105,9 +105,6 @@ namespace MonoTests.System.Security.Cryptography {
// This test will FAIL with MS framework 1.0 and 1.1 as their MGF1 implementation is buggy
// see ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1-vec.zip for RSA tests vector
[Test]
#if ! NET_2_0
[Category ("NotDotNet")] // Known to fail under MS runtime - both 1.0 and 1.1
#endif
public void PKCS1v21TestVector ()
{
pkcs1.HashName = "SHA1";

View File

@@ -362,10 +362,8 @@ namespace MonoTests.System.Security.Cryptography {
[Test]
public void PaddingModeEnum ()
{
#if NET_2_0
Assert.AreEqual (4, (int)PaddingMode.ANSIX923, "ANSIX923");
Assert.AreEqual (5, (int)PaddingMode.ISO10126, "ISO10126");
#endif
Assert.AreEqual (1, (int)PaddingMode.None, "None");
Assert.AreEqual (2, (int)PaddingMode.PKCS7, "PKCS7");
Assert.AreEqual (3, (int)PaddingMode.Zeros, "Zeros");
@@ -405,7 +403,6 @@ namespace MonoTests.System.Security.Cryptography {
// a. encrypt data larger than one block with a padding mode "X"
// b. decrypt the data with padding mode "None"
// c. compare the last (padding) bytes with the expected padding
#if NET_2_0
private void ANSIX923_Full (SymmetricAlgorithm sa)
{
int bs = (sa.BlockSize >> 3);
@@ -485,7 +482,6 @@ namespace MonoTests.System.Security.Cryptography {
// now validate padding - ISO10126 is all random except last byte (length)
Assert.AreEqual (pd, decdata [decdata.Length - 1], "last byte");
}
#endif
private void PKCS7_Full (SymmetricAlgorithm sa)
{
int bs = (sa.BlockSize >> 3);
@@ -569,7 +565,6 @@ namespace MonoTests.System.Security.Cryptography {
for (int i = 0; i < pd; i++)
Assert.AreEqual (0x00, decdata [decdata.Length - pd + i], i.ToString ());
}
#if NET_2_0
// ANSI X.923
[Test]
@@ -669,7 +664,6 @@ namespace MonoTests.System.Security.Cryptography {
{
ISO10126_Partial (TripleDES.Create ());
}
#endif
// PKCS #7
[Test]
@@ -810,7 +804,6 @@ namespace MonoTests.System.Security.Cryptography {
}
return result;
}
#if NET_2_0
[Test]
public void ANSIX923_ISO10126 ()
{
@@ -870,15 +863,10 @@ namespace MonoTests.System.Security.Cryptography {
{
Assert.AreEqual (4, Mismatch (PaddingMode.None, PaddingMode.ISO10126));
}
#endif
[Test]
public void None_PKCS7 ()
{
#if NET_2_0
Assert.AreEqual (4, Mismatch (PaddingMode.None, PaddingMode.PKCS7));
#else
Assert.AreEqual (0, Mismatch (PaddingMode.None, PaddingMode.PKCS7));
#endif
}
[Test]
@@ -886,7 +874,6 @@ namespace MonoTests.System.Security.Cryptography {
{
Assert.AreEqual (0, Mismatch (PaddingMode.None, PaddingMode.Zeros));
}
#if NET_2_0
[Test]
public void PKCS7_ANSIX923 ()
{
@@ -898,7 +885,6 @@ namespace MonoTests.System.Security.Cryptography {
{
Assert.AreEqual (0, Mismatch (PaddingMode.PKCS7, PaddingMode.ISO10126));
}
#endif
[Test]
public void PKCS7_None ()
{
@@ -910,7 +896,6 @@ namespace MonoTests.System.Security.Cryptography {
{
Assert.AreEqual (1, Mismatch (PaddingMode.PKCS7, PaddingMode.Zeros));
}
#if NET_2_0
[Test]
public void Zeros_ANSIX923 ()
{
@@ -922,7 +907,6 @@ namespace MonoTests.System.Security.Cryptography {
{
Assert.AreEqual (4, Mismatch (PaddingMode.Zeros, PaddingMode.ISO10126));
}
#endif
[Test]
public void Zeros_None ()
{
@@ -932,15 +916,10 @@ namespace MonoTests.System.Security.Cryptography {
[Test]
public void Zeros_PKCS7 ()
{
#if NET_2_0
Assert.AreEqual (4, Mismatch (PaddingMode.Zeros, PaddingMode.PKCS7));
#else
Assert.AreEqual (0, Mismatch (PaddingMode.Zeros, PaddingMode.PKCS7));
#endif
}
// MACTripleDES tests
#if NET_2_0
private string MAC (PaddingMode padding, int length)
{
byte[] key = new byte [24] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
@@ -1015,6 +994,5 @@ namespace MonoTests.System.Security.Cryptography {
byte[] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
Assert.AreEqual (data, decdata);
}
#endif
}
}

View File

@@ -46,9 +46,7 @@ public class PasswordDeriveBytesTest {
// Constructors
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void Ctor_PasswordNullSalt ()
{
string pwd = null;
@@ -74,11 +72,7 @@ public class PasswordDeriveBytesTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[Category ("NotWorking")] // CspParameters aren't supported by Mono (requires CryptoAPI)
#endif
public void Ctor_PasswordNullSaltCspParameters ()
{
string pwd = null;
@@ -119,9 +113,7 @@ public class PasswordDeriveBytesTest {
#endif
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void Ctor_PasswordNullSaltHashIteration ()
{
string pwd = null;
@@ -177,11 +169,7 @@ public class PasswordDeriveBytesTest {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[Category ("NotWorking")] // CspParameters aren't supported by Mono (requires CryptoAPI)
#endif
public void Ctor_PasswordNullSaltHashIterationCspParameters ()
{
string pwd = null;
@@ -266,10 +254,6 @@ public class PasswordDeriveBytesTest {
}
[Test]
#if !NET_2_0
// Fixed in 2.0 beta 1
[ExpectedException (typeof (NullReferenceException))]
#endif
public void Property_Salt ()
{
PasswordDeriveBytes pdb = new PasswordDeriveBytes ("s3kr3t", salt);
@@ -290,19 +274,6 @@ public class PasswordDeriveBytesTest {
// 1.0/1.1 compatibility
#if !NET_2_0
// 1.0/1.1 accepted a null password as valid - but throw the
// ArgumentNullException when GetBytes is called
// byte stream from the null input. Check that we can do the same...
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetBytes_PasswordNull ()
{
string pwd = null;
PasswordDeriveBytes pdb = new PasswordDeriveBytes (pwd, salt);
pdb.GetBytes (24);
}
#endif
// Old tests
@@ -674,51 +645,14 @@ public class PasswordDeriveBytesTest {
}
pd.Reset ();
#if NET_2_0
// finally a useful reset :)
pd.HashName = "SHA256";
pd.Salt = expectedKey;
pd.IterationCount = 10;
#else
// same thing after Reset
try {
pd.HashName = "SHA256";
Assert.Fail ("PKCS#5 can't set HashName after Reset - expected CryptographicException but got none");
}
catch (CryptographicException) {
// do nothing, this is what we expect
}
catch (Exception e) {
Assert.Fail ("PKCS#5 can't set HashName after Reset - expected CryptographicException but got " + e.ToString ());
}
try {
pd.Salt = expectedKey;
Assert.Fail ("PKCS#5 can't set Salt after Reset - expected CryptographicException but got none");
}
catch (CryptographicException) {
// do nothing, this is what we expect
}
catch (Exception e) {
Assert.Fail ("PKCS#5 can't set Salt after Reset - expected CryptographicException but got " + e.ToString ());
}
try {
pd.IterationCount = 10;
Assert.Fail ("PKCS#5 can't set IterationCount after Reset - expected CryptographicException but got none");
}
catch (CryptographicException) {
// do nothing, this is what we expect
}
catch (Exception e) {
Assert.Fail ("PKCS#5 can't set IterationCount after Reset - expected CryptographicException but got " + e.ToString ());
}
#endif
}
// FIXME: should we treat this as a bug or as a feature ?
[Test]
#if ! NET_2_0
[ExpectedException (typeof (NullReferenceException))]
#endif
public void StrangeBehaviour ()
{
// create object with a salt...

View File

@@ -46,11 +46,7 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#else
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void CreateEncryptor_KeyNull ()
{
ICryptoTransform encryptor = rc2.CreateEncryptor (null, rc2.IV);
@@ -100,11 +96,7 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#else
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void CreateDecryptor_KeyNull ()
{
ICryptoTransform encryptor = rc2.CreateEncryptor (rc2.Key, rc2.IV);
@@ -170,9 +162,7 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateEncryptor_IV_Zero ()
{
int size = (rc2.BlockSize >> 3) - 1;
@@ -180,9 +170,7 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateEncryptor_IV_TooSmall ()
{
int size = (rc2.BlockSize >> 3) - 1;
@@ -217,9 +205,7 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateDecryptor_IV_Zero ()
{
int size = (rc2.BlockSize >> 3) - 1;
@@ -227,9 +213,7 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CreateDecryptor_IV_TooSmall ()
{
int size = (rc2.BlockSize >> 3) - 1;

Some files were not shown because too many files have changed in this diff Show More