From 3d2d46f62fc01e2653d0251ad9703090574e7c41 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 6 Mar 2024 14:48:10 -0800 Subject: Better .nupkg names --- .../StrUtil.cs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/api/burn/WixToolset.BootstrapperApplicationApi/StrUtil.cs (limited to 'src/api/burn/WixToolset.BootstrapperApplicationApi/StrUtil.cs') diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/StrUtil.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/StrUtil.cs new file mode 100644 index 00000000..aeeaac47 --- /dev/null +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/StrUtil.cs @@ -0,0 +1,54 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.BootstrapperApplicationApi +{ + using System; + using System.Runtime.InteropServices; + using System.Security; + using System.Text; + + internal static class StrUtil + { + [DllImport("mbanative.dll", ExactSpelling = true)] + internal static extern void StrFree( + IntPtr scz + ); + + internal sealed class StrHandle : SafeHandleZeroIsDefaultAndInvalid + { + protected override bool ReleaseHandle() + { + StrFree(this.handle); + return true; + } + + public string ToUniString() + { + return Marshal.PtrToStringUni(this.handle); + } + + public SecureString ToSecureString() + { + if (this.handle == IntPtr.Zero) + { + return null; + } + + SecureString value = new SecureString(); + char c; + for (int charIndex = 0; ; charIndex++) + { + c = (char)Marshal.ReadInt16(this.handle, charIndex * UnicodeEncoding.CharSize); + if (c == '\0') + { + break; + } + + value.AppendChar(c); + } + + return value; + } + } + } +} -- cgit v1.2.3-55-g6feb