ca groundwork

This commit is contained in:
DecDuck
2024-10-07 22:35:54 +11:00
parent 1bd19ad917
commit bfafd2a044
44 changed files with 628 additions and 130 deletions

View File

@ -0,0 +1,23 @@
import path from "path";
import fs from "fs";
import { CertificateBundle } from "./ca";
export type CertificateStore = {
store(name: string, data: CertificateBundle): Promise<void>;
fetch(name: string): Promise<CertificateBundle | undefined>;
};
export const fsCertificateStore = (base: string) => {
const store: CertificateStore = {
async store(name: string, data: CertificateBundle) {
const filepath = path.join(base, name);
fs.writeFileSync(filepath, JSON.stringify(data));
},
async fetch(name: string) {
const filepath = path.join(base, name);
if (!fs.existsSync(filepath)) return undefined;
return JSON.parse(fs.readFileSync(filepath, "utf-8"));
},
};
return store;
};