Sha256: 74c9a6b98c8954510909dcb18cea56cdb988e404d32c0aafb3b7f519c0390dd9

Contents?: true

Size: 1.48 KB

Versions: 28

Compression:

Stored size: 1.48 KB

Contents

var asn1 = require('../asn1');
var inherits = require('inherits');

var api = exports;

api.define = function define(name, body) {
  return new Entity(name, body);
};

function Entity(name, body) {
  this.name = name;
  this.body = body;

  this.decoders = {};
  this.encoders = {};
};

Entity.prototype._createNamed = function createNamed(base) {
  var named;
  try {
    named = require('vm').runInThisContext(
      '(function ' + this.name + '(entity) {\n' +
      '  this._initNamed(entity);\n' +
      '})'
    );
  } catch (e) {
    named = function (entity) {
      this._initNamed(entity);
    };
  }
  inherits(named, base);
  named.prototype._initNamed = function initnamed(entity) {
    base.call(this, entity);
  };

  return new named(this);
};

Entity.prototype._getDecoder = function _getDecoder(enc) {
  enc = enc || 'der';
  // Lazily create decoder
  if (!this.decoders.hasOwnProperty(enc))
    this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
  return this.decoders[enc];
};

Entity.prototype.decode = function decode(data, enc, options) {
  return this._getDecoder(enc).decode(data, options);
};

Entity.prototype._getEncoder = function _getEncoder(enc) {
  enc = enc || 'der';
  // Lazily create encoder
  if (!this.encoders.hasOwnProperty(enc))
    this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
  return this.encoders[enc];
};

Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
  return this._getEncoder(enc).encode(data, reporter);
};

Version data entries

28 entries across 28 versions & 11 rubygems

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