(input: string)
| 6 | * Extracts content from either a file path or data URI |
| 7 | */ |
| 8 | export function getCertificateContent(input: string): string { |
| 9 | if (input.startsWith("data:")) { |
| 10 | // Parse data URI: data:[<mediatype>][;base64],<data> |
| 11 | const [header, data] = input.split(","); |
| 12 | if (header.includes("base64")) { |
| 13 | return Buffer.from(data, "base64").toString("utf8"); |
| 14 | } else { |
| 15 | return decodeURIComponent(data); |
| 16 | } |
| 17 | } else { |
| 18 | // Assume it's a file path |
| 19 | return fs.readFileSync(input, "utf8"); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | export class CertsCache { |
| 24 | private static instance: CertsCache; |
no test coverage detected