perf: openapi返回证书时挑选匹配范围最小的那一个;增加format参数,增加返回值p7b格式,增加detail返回

This commit is contained in:
xiaojunnuo
2025-08-28 22:39:11 +08:00
parent c09c962cb6
commit 2085bcceb6
6 changed files with 70 additions and 18 deletions

View File

@@ -21,6 +21,15 @@ export type CertReaderHandleContext = {
};
export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise<void>;
export type HandleOpts = { logger: ILogger; handle: CertReaderHandle };
const formats = {
pem: ["crt", "key", "ic"],
one: ["one"],
pfx: ["pfx"],
der: ["der"],
jks: ["jks"],
p7b: ["p7b", "key"],
};
export class CertReader {
cert: CertInfo;
@@ -74,8 +83,17 @@ export class CertReader {
return arr[0] + endStr;
}
toCertInfo(): CertInfo {
return this.cert;
toCertInfo(format?: string): CertInfo {
if (!format) {
return this.cert;
}
const formatArr = formats[format];
const res: any = {};
formatArr.forEach((key: string) => {
res[key] = this.cert[key];
});
return res;
}
getCrtDetail(crt: string = this.cert.crt) {