Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asn1.js

Package Overview
Dependencies
Maintainers
2
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asn1.js - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

test/der-decode-test.js

16

lib/asn1/api.js

@@ -31,14 +31,22 @@ var asn1 = require('../asn1');

Entity.prototype.decode = function decode(data, enc, options) {
Entity.prototype._getDecoder = function _getDecoder(enc) {
// Lazily create decoder
if (!this.decoders.hasOwnProperty(enc))
this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
return this.decoders[enc].decode(data, options);
return this.decoders[enc];
};
Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
Entity.prototype.decode = function decode(data, enc, options) {
return this._getDecoder(enc).decode(data, options);
};
Entity.prototype._getEncoder = function _getEncoder(enc) {
// Lazily create encoder
if (!this.encoders.hasOwnProperty(enc))
this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
return this.encoders[enc].encode(data, reporter);
return this.encoders[enc];
};
Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
return this._getEncoder(enc).encode(data, reporter);
};

@@ -45,2 +45,3 @@ var assert = require('assert');

state.use = null;
state.useDecoder = null;
state.key = null;

@@ -59,2 +60,19 @@ state['default'] = null;

var stateProps = [
'enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice',
'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit',
'implicit'
];
Node.prototype.clone = function clone() {
var state = this._baseState;
var cstate = {};
stateProps.forEach(function(prop) {
cstate[prop] = state[prop];
});
var res = new this.constructor(cstate.parent);
res._baseState = cstate;
return res;
};
Node.prototype._wrap = function wrap() {

@@ -356,3 +374,3 @@ var state = this._baseState;

else if (state.use !== null)
return this._use(input, state.use);
return this._getUse(state.use)._decode(input);
else

@@ -364,2 +382,17 @@ return input.error('unknown tag: ' + tag);

Node.prototype._getUse = function _getUse(entity) {
var state = this._baseState;
if (!state.useDecoder) {
// Create altered use decoder if implicit is set
state.useDecoder = this._use(entity);
assert(state.useDecoder._baseState.parent === null);
state.useDecoder = state.useDecoder._baseState.children[0];
if (state.implicit !== null) {
state.useDecoder = state.useDecoder.clone();
state.useDecoder._baseState.implicit = state.implicit;
}
}
return state.useDecoder;
};
Node.prototype._decodeChoice = function decodeChoice(input) {

@@ -460,6 +493,6 @@ var state = this._baseState;

content = this._createEncoderBuffer(data.map(function(item) {
return this._use(state.args[0], item);
return this._getUse(state.args[0])._encode(item, reporter);
}, this));
} else if (state.use !== null) {
result = this._use(state.use, data);
result = this._getUse(state.use)._encode(data, reporter);
} else {

@@ -466,0 +499,0 @@ content = this._encodePrimitive(state.tag, data);

@@ -230,4 +230,4 @@ var util = require('util');

DERNode.prototype._use = function use(buffer, decoder) {
return decoder.decode(buffer, 'der');
DERNode.prototype._use = function use(entity) {
return entity._getDecoder('der').tree;
};

@@ -234,0 +234,0 @@

@@ -203,4 +203,4 @@ var util = require('util');

DERNode.prototype._use = function use(encoder, data) {
return encoder.encode(data, 'der', this.reporter);
DERNode.prototype._use = function use(entity) {
return entity._getEncoder('der').tree;
};

@@ -207,0 +207,0 @@

{
"name": "asn1.js",
"version": "0.3.1",
"version": "0.3.2",
"description": "ASN.1 encoder and decoder",

@@ -5,0 +5,0 @@ "main": "lib/asn1.js",

@@ -124,3 +124,3 @@ var assert = require('assert');

test('setof', function() {
test('seqof', function() {
var S = asn1.define('S', function() {

@@ -127,0 +127,0 @@ this.seq().obj(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc