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