Merge pull request #2765 from akoeplinger/mcs-fix-test-windows-backslash
[mono.git] / mcs / class / corlib / System.Security / SecureString.cs
index 94f42ab1c1a3746e9b8001f92b478bfe796f167d..765f61981df9a2f11fbca50627965f35295e4174 100644 (file)
@@ -26,8 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
-
 using System.Globalization;
 using System.Reflection;
 using System.Runtime.CompilerServices;
@@ -35,11 +33,12 @@ using System.Runtime.InteropServices;
 using System.Runtime.ConstrainedExecution;
 using System.Security.Cryptography;
 using System.Security.Permissions;
+using System.Runtime.ExceptionServices;
 
 namespace System.Security {
 
        [MonoTODO ("work in progress - encryption is missing")]
-       public sealed class SecureString : CriticalFinalizerObject, IDisposable {
+       public sealed class SecureString : IDisposable {
 
                private const int BlockSize = 16;
                private const int MaxSize = 65536;
@@ -90,6 +89,7 @@ namespace System.Security {
                        }
                }
 
+               [HandleProcessCorruptedStateExceptions]
                public void AppendChar (char c)
                {
                        if (disposed)
@@ -146,6 +146,7 @@ namespace System.Security {
                        length = 0;
                }
 
+               [HandleProcessCorruptedStateExceptions]
                public void InsertAt (int index, char c)
                {
                        if (disposed)
@@ -187,6 +188,7 @@ namespace System.Security {
                        read_only = true;
                }
 
+               [HandleProcessCorruptedStateExceptions]
                public void RemoveAt (int index)
                {
                        if (disposed)
@@ -200,7 +202,7 @@ namespace System.Security {
 
                        try {
                                Decrypt ();
-                               Buffer.BlockCopy (data, index + 1, data, index, data.Length - index - 1);
+                               Buffer.BlockCopy (data, index * 2 + 2, data, index * 2, data.Length - index * 2 - 2);
                                Alloc (--length, true);
                        }
                        finally {
@@ -208,6 +210,7 @@ namespace System.Security {
                        }
                }
 
+               [HandleProcessCorruptedStateExceptions]
                public void SetAt (int index, char c)
                {
                        if (disposed)
@@ -232,15 +235,15 @@ namespace System.Security {
 
                // internal/private stuff
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern static void EncryptInternal (byte [] data, object scope);
+//             [MethodImplAttribute(MethodImplOptions.InternalCall)]
+//             extern static void EncryptInternal (byte [] data, object scope);
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern static void DecryptInternal (byte [] data, object scope);
+//             [MethodImplAttribute(MethodImplOptions.InternalCall)]
+//             extern static void DecryptInternal (byte [] data, object scope);
 
-               static readonly object scope = Enum.Parse (
-                       Assembly.Load (Consts.AssemblySystem_Security)
-                       .GetType ("System.Security.Cryptography.MemoryProtectionScope"), "SameProcess");
+//             static readonly object scope = Enum.Parse (
+//                     Assembly.Load (Consts.AssemblySystem_Security)
+//                     .GetType ("System.Security.Cryptography.MemoryProtectionScope"), "SameProcess");
 
                // Note that ProtectedMemory is not supported on non-Windows environment right now.
                private void Encrypt ()
@@ -304,5 +307,3 @@ namespace System.Security {
                }
        }
 }
-
-#endif