-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.cs
More file actions
39 lines (38 loc) · 1.15 KB
/
Copy pathHelper.cs
File metadata and controls
39 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Runtime.InteropServices;
using System.Security;
namespace Quras
{
internal static class Helper
{
public static bool CompareTo(this SecureString s1, SecureString s2)
{
if (s1.Length != s2.Length)
return false;
IntPtr p1 = IntPtr.Zero;
IntPtr p2 = IntPtr.Zero;
try
{
p1 = SecureStringMarshal.SecureStringToGlobalAllocAnsi(s1);
p2 = SecureStringMarshal.SecureStringToGlobalAllocAnsi(s2);
int i = 0;
while (true)
{
byte b1 = Marshal.ReadByte(p1, i);
byte b2 = Marshal.ReadByte(p2, i++);
if (b1 == 0 && b2 == 0)
return true;
if (b1 != b2)
return false;
if (b1 == 0 || b2 == 0)
return false;
}
}
finally
{
Marshal.ZeroFreeGlobalAllocAnsi(p1);
Marshal.ZeroFreeGlobalAllocAnsi(p2);
}
}
}
}