2 // ProtectedMemoryTest.cs - NUnit Test Cases for ProtectedMemory
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
12 using NUnit
.Framework
;
15 using System
.Security
.Cryptography
;
17 namespace MonoTests
.System
.Security
.Cryptography
{
23 public class ProtectedMemoryTest
: Assertion
{
25 private void ProtectUnprotect (MemoryProtectionScope scope
)
27 byte[] data
= new byte [16];
28 ProtectedMemory
.Protect (data
, scope
);
30 for (int i
=0; i
< 16; i
++)
32 Assert ("Protect", (total
!= 0));
34 ProtectedMemory
.Unprotect (data
, scope
);
36 for (int i
=0; i
< 16; i
++)
38 Assert ("Unprotect", (total
== 0));
42 public void ProtectSameProcess ()
45 // we're testing the MemoryProtectionScope definition but
46 // not if it's really limited to the scope specified
47 ProtectUnprotect (MemoryProtectionScope
.SameProcess
);
49 catch (PlatformNotSupportedException
) {
50 Console
.WriteLine ("Only supported under Windows XP and later");
55 public void ProtectSameLogon ()
58 // we're testing the MemoryProtectionScope definition but
59 // not if it's really limited to the scope specified
60 ProtectUnprotect (MemoryProtectionScope
.SameLogon
);
62 catch (PlatformNotSupportedException
) {
63 Console
.WriteLine ("Only supported under Windows XP and later");
68 public void ProtectCrossProcess ()
71 // we're testing the MemoryProtectionScope definition but
72 // not if it's really limited to the scope specified
73 ProtectUnprotect (MemoryProtectionScope
.CrossProcess
);
75 catch (PlatformNotSupportedException
) {
76 Console
.WriteLine ("Only supported under Windows XP and later");
81 [ExpectedException (typeof (CryptographicException
))]
82 public void ProtectBadDataLength ()
84 byte[] data
= new byte [15];
85 ProtectedMemory
.Protect (data
, MemoryProtectionScope
.SameProcess
);
89 [ExpectedException (typeof (ArgumentNullException
))]
90 public void ProtectNull ()
92 ProtectedMemory
.Protect (null, MemoryProtectionScope
.SameProcess
);
96 [ExpectedException (typeof (CryptographicException
))]
97 public void UnprotectBadDataLength ()
99 byte[] data
= new byte [15];
100 ProtectedMemory
.Unprotect (data
, MemoryProtectionScope
.SameProcess
);
104 [ExpectedException (typeof (ArgumentNullException
))]
105 public void UnprotectNull ()
107 ProtectedMemory
.Unprotect (null, MemoryProtectionScope
.SameProcess
);