import { createHmac } from "node:crypto";
import { resolve } from "node:path";

export function redactPath(inputPath: string): string {
  return inputPath.length > 0 ? "[redacted]" : "";
}

export function normalizePathForHashForPlatform(inputPath: string, platform: string): string {
  const normalized = resolve(inputPath).replace(/\\/g, "/");
  return platform === "win32" ? normalized.toLowerCase() : normalized;
}

export function normalizePathForHash(inputPath: string): string {
  return normalizePathForHashForPlatform(inputPath, process.platform);
}

export function hashPath(inputPath: string, hmacSalt: string): string {
  const normalized = normalizePathForHash(inputPath);
  return createHmac("sha256", hmacSalt).update(normalized, "utf8").digest("hex");
}

export function hmacHex(value: string, hmacSalt: string): string {
  return createHmac("sha256", hmacSalt).update(value, "utf8").digest("hex");
}
