{"version":3,"sources":["security/certificate/x509.ts"],"names":["forge","SecurityCertificate","SecurityCertificateX509","constructor","reset","_forgeCertificate","readForgeCertificate","certificate","encodePem","forgeCertificate","Error","pki","certificateToPem","encodePemData","base64","split","map","s","trim","filter","startsWith","join","Buffer","from","encodeCertchain"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,YAAlB;AAEA,SAAQC,mBAAR,QAAkC,oBAAlC;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,uBAAN,SAAsCD,mBAAtC,CAA0D;AAChE;AACD;AACA;AAGCE,EAAAA,WAAW,GAAG;AACb;;AADa,+CAFwD,IAExD;AAEb;AAED;AACD;AACA;;;AACQC,EAAAA,KAAK,GAAG;AACd,SAAKC,iBAAL,GAAyB,IAAzB;AACA;AAED;AACD;AACA;AACA;AACA;;;AACQC,EAAAA,oBAAoB,CAACC,WAAD,EAA+C;AACzE,SAAKH,KAAL;AAEA,SAAKC,iBAAL,GAAyBE,WAAzB;AACA;AAED;AACD;AACA;AACA;AACA;;;AACQC,EAAAA,SAAS,GAAG;AAClB,UAAMC,gBAAgB,GAAG,KAAKJ,iBAA9B;;AACA,QAAI,CAACI,gBAAL,EAAuB;AACtB,YAAM,IAAIC,KAAJ,CAAU,6BAAV,CAAN;AACA;;AACD,WAAOV,KAAK,CAACW,GAAN,CAAUC,gBAAV,CAA2BH,gBAA3B,CAAP;AACA;AAED;AACD;AACA;AACA;AACA;;;AACQI,EAAAA,aAAa,GAAG;AACtB;AACA,UAAMC,MAAM,GAAG,KAAKN,SAAL,GACbO,KADa,CACP,SADO,EAEbC,GAFa,CAETC,CAAC,IAAIA,CAAC,CAACC,IAAF,EAFI,EAGbC,MAHa,CAGNF,CAAC,IAAI,CAACA,CAAC,CAACG,UAAF,CAAa,GAAb,CAHA,EAIbC,IAJa,CAIR,EAJQ,CAAf;AAKA,WAAOC,MAAM,CAACC,IAAP,CAAYT,MAAZ,EAAoB,QAApB,CAAP;AACA;AAED;AACD;AACA;AACA;AACA;;;AACQU,EAAAA,eAAe,GAAG;AACxB,WAAO,KAAKX,aAAL,EAAP;AACA;;AA/D+D","sourcesContent":["import forge from 'node-forge';\n\nimport {SecurityCertificate} from '../certificate';\n\n/**\n * SecurityCertificateX509 constructor.\n */\nexport class SecurityCertificateX509 extends SecurityCertificate {\n\t/**\n\t * Forge certificate.\n\t */\n\tprotected _forgeCertificate: Readonly<forge.pki.Certificate> | null = null;\n\n\tconstructor() {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Reset the internal state.\n\t */\n\tpublic reset() {\n\t\tthis._forgeCertificate = null;\n\t}\n\n\t/**\n\t * Read a forge certificate.\n\t *\n\t * @param certificate Forge certificate.\n\t */\n\tpublic readForgeCertificate(certificate: Readonly<forge.pki.Certificate>) {\n\t\tthis.reset();\n\n\t\tthis._forgeCertificate = certificate;\n\t}\n\n\t/**\n\t * Encode as PEM string.\n\t *\n\t * @returns PEM string.\n\t */\n\tpublic encodePem() {\n\t\tconst forgeCertificate = this._forgeCertificate;\n\t\tif (!forgeCertificate) {\n\t\t\tthrow new Error('Certificate not initialized');\n\t\t}\n\t\treturn forge.pki.certificateToPem(forgeCertificate);\n\t}\n\n\t/**\n\t * Encode as PEM data.\n\t *\n\t * @returns The binary PEM data.\n\t */\n\tpublic encodePemData() {\n\t\t// Remove all the non-base64 lines, then decode.\n\t\tconst base64 = this.encodePem()\n\t\t\t.split(/[\\r\\n]+/)\n\t\t\t.map(s => s.trim())\n\t\t\t.filter(s => !s.startsWith('-'))\n\t\t\t.join('');\n\t\treturn Buffer.from(base64, 'base64');\n\t}\n\n\t/**\n\t * Encode for certchain data.\n\t *\n\t * @returns Certchain data.\n\t */\n\tpublic encodeCertchain() {\n\t\treturn this.encodePemData();\n\t}\n}\n"],"file":"x509.mjs","sourceRoot":"../../../src"}