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
disco_app-0.18.0 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.18.2 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.16.1 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.15.2 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.18.4 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.18.1 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.14.0 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
enju_library-0.3.8 spec/dummy/node_modules/asn1.js/lib/asn1/decoders/pem.js
ilog-0.4.1 node_modules/asn1.js/lib/asn1/decoders/pem.js
ilog-0.4.0 node_modules/asn1.js/lib/asn1/decoders/pem.js
ilog-0.3.3 node_modules/asn1.js/lib/asn1/decoders/pem.js
jester-data-8.0.0 node_modules/asn1.js/lib/asn1/decoders/pem.js
ezii-os-5.2.1 node_modules/asn1.js/lib/asn1/decoders/pem.js
ezii-os-2.0.1 node_modules/asn1.js/lib/asn1/decoders/pem.js
ezii-os-1.1.0 node_modules/asn1.js/lib/asn1/decoders/pem.js
ezii-os-1.0.0 node_modules/asn1.js/lib/asn1/decoders/pem.js
ezii-os-0.0.0.1.0 node_modules/asn1.js/lib/asn1/decoders/pem.js
ezii-os-0.0.0.0.1 node_modules/asn1.js/lib/asn1/decoders/pem.js