73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import type {
|
|
IServerOrderStore,
|
|
IServerOrder,
|
|
IServerAuthorization,
|
|
IServerChallenge,
|
|
} from './server.interfaces.js';
|
|
|
|
/**
|
|
* In-memory order/authorization/challenge/certificate storage for the ACME server.
|
|
*/
|
|
export class MemoryOrderStore implements IServerOrderStore {
|
|
private orders = new Map<string, IServerOrder>();
|
|
private authorizations = new Map<string, IServerAuthorization>();
|
|
private challenges = new Map<string, IServerChallenge>();
|
|
private certPems = new Map<string, string>();
|
|
|
|
async createOrder(order: IServerOrder): Promise<IServerOrder> {
|
|
this.orders.set(order.id, order);
|
|
return order;
|
|
}
|
|
|
|
async getOrder(id: string): Promise<IServerOrder | null> {
|
|
return this.orders.get(id) || null;
|
|
}
|
|
|
|
async updateOrder(id: string, updates: Partial<IServerOrder>): Promise<void> {
|
|
const order = this.orders.get(id);
|
|
if (order) {
|
|
Object.assign(order, updates);
|
|
}
|
|
}
|
|
|
|
async createAuthorization(authz: IServerAuthorization): Promise<IServerAuthorization> {
|
|
this.authorizations.set(authz.id, authz);
|
|
return authz;
|
|
}
|
|
|
|
async getAuthorization(id: string): Promise<IServerAuthorization | null> {
|
|
return this.authorizations.get(id) || null;
|
|
}
|
|
|
|
async updateAuthorization(id: string, updates: Partial<IServerAuthorization>): Promise<void> {
|
|
const authz = this.authorizations.get(id);
|
|
if (authz) {
|
|
Object.assign(authz, updates);
|
|
}
|
|
}
|
|
|
|
async createChallenge(challenge: IServerChallenge): Promise<IServerChallenge> {
|
|
this.challenges.set(challenge.id, challenge);
|
|
return challenge;
|
|
}
|
|
|
|
async getChallenge(id: string): Promise<IServerChallenge | null> {
|
|
return this.challenges.get(id) || null;
|
|
}
|
|
|
|
async updateChallenge(id: string, updates: Partial<IServerChallenge>): Promise<void> {
|
|
const challenge = this.challenges.get(id);
|
|
if (challenge) {
|
|
Object.assign(challenge, updates);
|
|
}
|
|
}
|
|
|
|
async storeCertPem(orderId: string, pem: string): Promise<void> {
|
|
this.certPems.set(orderId, pem);
|
|
}
|
|
|
|
async getCertPem(orderId: string): Promise<string | null> {
|
|
return this.certPems.get(orderId) || null;
|
|
}
|
|
}
|