Sha256: 1eb6cb79689b2b13bf5bb11531d4166dac501ac7ce763ffee08d3bf6325203cf

Contents?: true

Size: 1.15 KB

Versions: 28

Compression:

Stored size: 1.15 KB

Contents

var inherits = require('inherits');
var Buffer = require('buffer').Buffer;

var DERDecoder = require('./der');

function PEMDecoder(entity) {
  DERDecoder.call(this, entity);
  this.enc = 'pem';
};
inherits(PEMDecoder, DERDecoder);
module.exports = PEMDecoder;

PEMDecoder.prototype.decode = function decode(data, options) {
  var lines = data.toString().split(/[\r\n]+/g);

  var label = options.label.toUpperCase();

  var re = /^-----(BEGIN|END) ([^-]+)-----$/;
  var start = -1;
  var end = -1;
  for (var i = 0; i < lines.length; i++) {
    var match = lines[i].match(re);
    if (match === null)
      continue;

    if (match[2] !== label)
      continue;

    if (start === -1) {
      if (match[1] !== 'BEGIN')
        break;
      start = i;
    } else {
      if (match[1] !== 'END')
        break;
      end = i;
      break;
    }
  }
  if (start === -1 || end === -1)
    throw new Error('PEM section not found for: ' + label);

  var base64 = lines.slice(start + 1, end).join('');
  // Remove excessive symbols
  base64.replace(/[^a-z0-9\+\/=]+/gi, '');

  var input = new Buffer(base64, 'base64');
  return DERDecoder.prototype.decode.call(this, input, options);
};

Version data entries

28 entries across 28 versions & 11 rubygems

Version Path
optimacms-0.4.3 spec/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
optimacms-0.4.2 spec/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/asn1.js/lib/asn1/decoders/pem.js
locomotivecms-3.4.0 app/javascript/node_modules/asn1.js/lib/asn1/decoders/pem.js
cortex-0.1.3 spec/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
dragonfly_puppeteer-0.1.0 node_modules/asn1.js/lib/asn1/decoders/pem.js
lanes-0.8.0 node_modules/asn1.js/lib/asn1/decoders/pem.js
minimum_viable_product-0.0.11 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js