mocksaml/utils/certificate.ts

24 lines
636 B
TypeScript
Raw Normal View History

2022-02-21 14:31:47 +00:00
import { promises as fs } from 'fs';
import path from 'path';
2022-02-21 15:36:25 +00:00
const fetchPublicKey = async (): Promise<string> => {
return await fs.readFile(path.join('data', 'idp-public.key'), 'ascii');
2022-02-21 14:31:47 +00:00
};
2022-02-21 15:36:25 +00:00
const fetchPrivateKey = async (): Promise<string> => {
return await fs.readFile(path.join('data', 'idp-private.key'), 'ascii');
2022-02-21 14:31:47 +00:00
}
2022-02-21 15:36:25 +00:00
const stripCertHeaderAndFooter = (cert: string): string => {
cert = cert.replace(/-+BEGIN CERTIFICATE-+\r?\n?/, '');
cert = cert.replace(/-+END CERTIFICATE-+\r?\n?/, '');
cert = cert.replace(/\r\n/g, '\n');
return cert;
2022-02-21 14:31:47 +00:00
};
export {
fetchPublicKey,
fetchPrivateKey,
2022-02-21 15:36:25 +00:00
stripCertHeaderAndFooter,
2022-02-21 14:31:47 +00:00
}