src/crypto/forge.js
function forgeObjectFromPem(input) {
    const msg = forge.pem.decode(input)[0];
    let key;

    switch (msg.type) {
        case 'PRIVATE KEY':
        case 'RSA PRIVATE KEY':
            key = forge.pki.privateKeyFromPem(input);
            break;

        case 'PUBLIC KEY':
        case 'RSA PUBLIC KEY':
            key = forge.pki.publicKeyFromPem(input);
            break;

        case 'CERTIFICATE':
        case 'X509 CERTIFICATE':
        case 'TRUSTED CERTIFICATE':
            key = forge.pki.certificateFromPem(input).publicKey;
            break;

        case 'CERTIFICATE REQUEST':
            key = forge.pki.certificationRequestFromPem(input).publicKey;
            break;

        default:
            throw new Error('Unable to detect forge message type');
    }

    return key;
}
function forgeObjectFromPem(input) {
    const msg = forge.pem.decode(input)[0];
    let key;

    switch (msg.type) {
        case 'PRIVATE KEY':
        case 'RSA PRIVATE KEY':
            key = forge.pki.privateKeyFromPem(input);
            break;

        case 'PUBLIC KEY':
        case 'RSA PUBLIC KEY':
            key = forge.pki.publicKeyFromPem(input);
            break;

        case 'CERTIFICATE':
        case 'X509 CERTIFICATE':
        case 'TRUSTED CERTIFICATE':
            key = forge.pki.certificateFromPem(input).publicKey;
            break;

        case 'CERTIFICATE REQUEST':
            key = forge.pki.certificationRequestFromPem(input).publicKey;
            break;

        default:
            throw new Error('Unable to detect forge message type');
    }

    return key;
}
function forgeObjectFromPem ( input ) { const msg = forge . pem . decode ( input ) [ 0 ] ; let key ; switch ( msg . type ) { case 'PRIVATE KEY' : case 'RSA PRIVATE KEY' : key = forge . pki . privateKeyFromPem ( input ) ; break ; case 'PUBLIC KEY' : case 'RSA PUBLIC KEY' : key = forge . pki . publicKeyFromPem ( input ) ; break ; case 'CERTIFICATE' : case 'X509 CERTIFICATE' : case 'TRUSTED CERTIFICATE' : key = forge . pki . certificateFromPem ( input ) . publicKey ; break ; case 'CERTIFICATE REQUEST' : key = forge . pki . certificationRequestFromPem ( input ) . publicKey ; break ; default : throw new Error ( 'Unable to detect forge message type' ) ; } return key ; }
Attempt to parse forge object from PEM encoded string

@private
@param {string} input PEM string
@return {object}
Attempt to parse forge object from PEM encoded string