summaryrefslogtreecommitdiff
path: root/Util.cs
blob: 9f261ee5fceca232df283f1609870236ea183f6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System.Runtime.InteropServices;
using System.Security;

namespace HyperBooru.PowerShell;

internal static class Util {
    internal static string ToInsecureString(this SecureString x) {
        IntPtr rawString = IntPtr.Zero;
        try {
            rawString = Marshal.SecureStringToBSTR(x);
            return Marshal.PtrToStringBSTR(rawString);
        } finally {
            if(rawString != IntPtr.Zero)
                Marshal.FreeBSTR(rawString);
        }
    }
}