Files
Netcatty/domain/vaultImport/csvCredentialFields.ts
T
陈大猫 495a852b77 Support key authentication in host CSV import/export (#2354)
* Support key auth in host CSV files

* Harden CSV key credential imports

* Resolve CSV credential review findings

* Keep CSV credential previews non-destructive

* Align CSV credential preview and import

* Preserve CSV credential conflicts across aliases

* Deduplicate CSV import warnings

* Export referenced key file paths in host CSV

* Protect imported key passphrases

* Preserve aliased CSV key conflicts

* fix CSV key credential safety

* preserve legacy saved key passphrases

* export matching saved key passphrases safely
2026-07-21 17:32:14 +08:00

35 lines
1016 B
TypeScript

const FORMULA_PREFIX = /^[=+\-@\t\r]/u;
const KEY_PATH_MARKER = "__netcatty_csv_keypath_v1__:";
const PASSPHRASE_MARKER = "__netcatty_csv_passphrase_v1__:";
const encodeMarkedField = (value: string, marker: string): string => (
FORMULA_PREFIX.test(value) || value.startsWith(marker)
? `${marker}${encodeURIComponent(value)}`
: value
);
const decodeMarkedField = (value: string, marker: string): string => {
if (!value.startsWith(marker)) return value;
try {
return decodeURIComponent(value.slice(marker.length));
} catch {
return value;
}
};
export const encodeCsvKeyPath = (value: string): string => (
encodeMarkedField(value, KEY_PATH_MARKER)
);
export const decodeCsvKeyPath = (value: string): string => (
decodeMarkedField(value, KEY_PATH_MARKER)
);
export const encodeCsvPassphrase = (value: string): string => (
encodeMarkedField(value, PASSPHRASE_MARKER)
);
export const decodeCsvPassphrase = (value: string): string => (
decodeMarkedField(value, PASSPHRASE_MARKER)
);