@ciandt-flow/cli 1.4.1-beta.172 → 1.4.1-beta.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +29 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8,26 +8,26 @@ using System.Runtime.InteropServices;
8
8
  using System.Text;
9
9
 
10
10
  public class FlowCredManager {
11
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
11
+ [StructLayout(LayoutKind.Sequential)]
12
12
  private struct CREDENTIAL {
13
13
  public int Flags;
14
14
  public int Type;
15
- public string TargetName;
16
- public string Comment;
15
+ public IntPtr TargetName;
16
+ public IntPtr Comment;
17
17
  public long LastWritten;
18
18
  public int CredentialBlobSize;
19
19
  public IntPtr CredentialBlob;
20
20
  public int Persist;
21
21
  public int AttributeCount;
22
22
  public IntPtr Attributes;
23
- public string TargetAlias;
24
- public string UserName;
23
+ public IntPtr TargetAlias;
24
+ public IntPtr UserName;
25
25
  }
26
26
 
27
27
  [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
28
28
  private static extern bool CredRead(string target, int type, int flags, out IntPtr credential);
29
29
 
30
- [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
30
+ [DllImport("advapi32.dll", SetLastError = true)]
31
31
  private static extern bool CredWrite(ref CREDENTIAL credential, int flags);
32
32
 
33
33
  [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
@@ -48,22 +48,31 @@ public class FlowCredManager {
48
48
 
49
49
  public static string Write(string target, string secret, string userName) {
50
50
  byte[] bytes = Encoding.Unicode.GetBytes(secret);
51
+ IntPtr targetPtr = Marshal.StringToHGlobalUni(target);
52
+ IntPtr userPtr = Marshal.StringToHGlobalUni(userName);
51
53
  int[] persistLevels = new int[] { ${Rl}, ${Ml}, ${Ll} };
52
- foreach (int persist in persistLevels) {
53
- var cred = new CREDENTIAL();
54
- cred.Type = ${kn};
55
- cred.TargetName = target;
56
- cred.CredentialBlobSize = bytes.Length;
57
- cred.CredentialBlob = Marshal.AllocHGlobal(bytes.Length);
58
- cred.Persist = persist;
59
- cred.UserName = userName;
60
- try {
61
- Marshal.Copy(bytes, 0, cred.CredentialBlob, bytes.Length);
62
- if (CredWrite(ref cred, 0)) return "OK:" + persist;
63
- } finally { Marshal.FreeHGlobal(cred.CredentialBlob); }
54
+ int lastErr = 0;
55
+ try {
56
+ foreach (int persist in persistLevels) {
57
+ IntPtr blobPtr = Marshal.AllocHGlobal(bytes.Length);
58
+ try {
59
+ Marshal.Copy(bytes, 0, blobPtr, bytes.Length);
60
+ var cred = new CREDENTIAL();
61
+ cred.Type = ${kn};
62
+ cred.TargetName = targetPtr;
63
+ cred.CredentialBlobSize = bytes.Length;
64
+ cred.CredentialBlob = blobPtr;
65
+ cred.Persist = persist;
66
+ cred.UserName = userPtr;
67
+ if (CredWrite(ref cred, 0)) return "OK:" + persist;
68
+ lastErr = Marshal.GetLastWin32Error();
69
+ } finally { Marshal.FreeHGlobal(blobPtr); }
70
+ }
71
+ return "ERR:" + lastErr;
72
+ } finally {
73
+ Marshal.FreeHGlobal(targetPtr);
74
+ Marshal.FreeHGlobal(userPtr);
64
75
  }
65
- int err = Marshal.GetLastWin32Error();
66
- return "ERR:" + err;
67
76
  }
68
77
 
69
78
  public static bool Delete(string target) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciandt-flow/cli",
3
- "version": "1.4.1-beta.172",
3
+ "version": "1.4.1-beta.176",
4
4
  "description": "TUI for browsing and installing Claude Code plugins from the Flow ecosystem",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",