@lapo/asn1js
Advanced tools
Comparing version 1.1.0 to 1.2.0
44
asn1.js
// ASN.1 JavaScript decoder | ||
// Copyright (c) 2008-2019 Lapo Luchini <lapo@lapo.it> | ||
// Copyright (c) 2008-2020 Lapo Luchini <lapo@lapo.it> | ||
@@ -16,7 +16,10 @@ // Permission to use, copy, modify, and/or distribute this software for any | ||
(function (undefined) { | ||
(typeof define != 'undefined' ? define : function (factory) { 'use strict'; | ||
if (typeof module == 'object') module.exports = factory(function (name) { return require('./' + name); }); | ||
else window.asn1 = factory(function (name) { return window[name]; }); | ||
})(function (require) { | ||
"use strict"; | ||
var Int10 = (typeof module !== 'undefined') ? require('./int10.js') : window.Int10, | ||
oids = (typeof module !== 'undefined') ? require('./oids.js') : window.oids, | ||
var Int10 = require('int10'), | ||
oids = require('oids'), | ||
ellipsis = "\u2026", | ||
@@ -201,4 +204,6 @@ reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/, | ||
Stream.prototype.parseBitString = function (start, end, maxLength) { | ||
var unusedBit = this.get(start), | ||
lenBit = ((end - start - 1) << 3) - unusedBit, | ||
var unusedBits = this.get(start); | ||
if (unusedBits > 7) | ||
throw 'Invalid BitString with unusedBits=' + unusedBits; | ||
var lenBit = ((end - start - 1) << 3) - unusedBits, | ||
intro = "(" + lenBit + " bit)\n", | ||
@@ -208,3 +213,3 @@ s = ""; | ||
var b = this.get(i), | ||
skip = (i == end - 1) ? unusedBit : 0; | ||
skip = (i == end - 1) ? unusedBits : 0; | ||
for (var j = 7; j >= skip; --j) | ||
@@ -270,3 +275,3 @@ s += (b >> j) & 1 ? "1" : "0"; | ||
function ASN1(stream, header, length, tag, sub) { | ||
function ASN1(stream, header, length, tag, tagLen, sub) { | ||
if (!(tag instanceof ASN1Tag)) throw 'Invalid tag value.'; | ||
@@ -277,2 +282,3 @@ this.stream = stream; | ||
this.tag = tag; | ||
this.tagLen = tagLen; | ||
this.sub = sub; | ||
@@ -347,3 +353,4 @@ } | ||
//case 0x09: // REAL | ||
//case 0x0A: // ENUMERATED | ||
case 0x0A: // ENUMERATED | ||
return this.stream.parseInteger(content, content + len); | ||
//case 0x0B: // EMBEDDED_PDV | ||
@@ -365,3 +372,3 @@ case 0x10: // SEQUENCE | ||
case 0x1A: // VisibleString | ||
//case 0x1B: // GeneralString | ||
case 0x1B: // GeneralString | ||
//case 0x1C: // UniversalString | ||
@@ -410,2 +417,6 @@ return stringCut(this.stream.parseStringISO(content, content + len), maxLength); | ||
}; | ||
/** Position of the length. */ | ||
ASN1.prototype.posLen = function() { | ||
return this.stream.pos + this.tagLen; | ||
}; | ||
ASN1.prototype.toHexString = function () { | ||
@@ -451,7 +462,8 @@ return this.stream.hexDump(this.posStart(), this.posEnd(), true); | ||
}; | ||
ASN1.decode = function (stream) { | ||
ASN1.decode = function (stream, offset) { | ||
if (!(stream instanceof Stream)) | ||
stream = new Stream(stream, 0); | ||
stream = new Stream(stream, offset || 0); | ||
var streamStart = new Stream(stream), | ||
tag = new ASN1Tag(stream), | ||
tagLen = stream.pos - streamStart.pos, | ||
len = ASN1.decodeLength(stream), | ||
@@ -511,7 +523,7 @@ start = stream.pos, | ||
} | ||
return new ASN1(streamStart, header, len, tag, sub); | ||
return new ASN1(streamStart, header, len, tag, tagLen, sub); | ||
}; | ||
// export globals | ||
if (typeof module !== 'undefined') { module.exports = ASN1; } else { window.ASN1 = ASN1; } | ||
})(); | ||
return ASN1; | ||
}); |
// Base64 JavaScript decoder | ||
// Copyright (c) 2008-2019 Lapo Luchini <lapo@lapo.it> | ||
// Copyright (c) 2008-2020 Lapo Luchini <lapo@lapo.it> | ||
@@ -16,3 +16,6 @@ // Permission to use, copy, modify, and/or distribute this software for any | ||
(function (undefined) { | ||
(typeof define != 'undefined' ? define : function (factory) { 'use strict'; | ||
if (typeof module == 'object') module.exports = factory(); | ||
else window.base64 = factory(); | ||
})(function () { | ||
"use strict"; | ||
@@ -22,5 +25,6 @@ | ||
decoder, // populated on first usage | ||
haveU8 = ('Uint8Array' in (typeof window == 'object' ? window : global)); | ||
haveU8 = (typeof Uint8Array == 'function'); | ||
Base64.decode = function (a) { | ||
var isString = (typeof a == 'string'); | ||
var i; | ||
@@ -32,8 +36,8 @@ if (decoder === undefined) { | ||
for (i = 0; i < 64; ++i) | ||
decoder[b64.charAt(i)] = i; | ||
decoder[b64.charCodeAt(i)] = i; | ||
for (i = 0; i < ignore.length; ++i) | ||
decoder[ignore.charAt(i)] = -1; | ||
decoder[ignore.charCodeAt(i)] = -1; | ||
// RFC 3548 URL & file safe encoding | ||
decoder['-'] = decoder['+']; | ||
decoder['_'] = decoder['/']; | ||
decoder['-'.charCodeAt(0)] = decoder['+'.charCodeAt(0)]; | ||
decoder['_'.charCodeAt(0)] = decoder['/'.charCodeAt(0)]; | ||
} | ||
@@ -43,4 +47,4 @@ var out = haveU8 ? new Uint8Array(a.length * 3 >> 2) : []; | ||
for (i = 0; i < a.length; ++i) { | ||
var c = a.charAt(i); | ||
if (c == '=') | ||
var c = isString ? a.charCodeAt(i) : a[i]; | ||
if (c == 61) // '='.charCodeAt(0) | ||
break; | ||
@@ -103,4 +107,4 @@ c = decoder[c]; | ||
// export globals | ||
if (typeof module !== 'undefined') { module.exports = Base64; } else { window.Base64 = Base64; } | ||
})(); | ||
return Base64; | ||
}); |
26
hex.js
// Hex JavaScript decoder | ||
// Copyright (c) 2008-2019 Lapo Luchini <lapo@lapo.it> | ||
// Copyright (c) 2008-2020 Lapo Luchini <lapo@lapo.it> | ||
@@ -16,3 +16,6 @@ // Permission to use, copy, modify, and/or distribute this software for any | ||
(function (undefined) { | ||
(typeof define != 'undefined' ? define : function (factory) { 'use strict'; | ||
if (typeof module == 'object') module.exports = factory(); | ||
else window.hex = factory(); | ||
})(function () { | ||
"use strict"; | ||
@@ -22,5 +25,6 @@ | ||
decoder, // populated on first usage | ||
haveU8 = ('Uint8Array' in (typeof window == 'object' ? window : global)); | ||
haveU8 = (typeof Uint8Array == 'function'); | ||
Hex.decode = function(a) { | ||
var isString = (typeof a == 'string'); | ||
var i; | ||
@@ -32,8 +36,8 @@ if (decoder === undefined) { | ||
for (i = 0; i < 16; ++i) | ||
decoder[hex.charAt(i)] = i; | ||
decoder[hex.charCodeAt(i)] = i; | ||
hex = hex.toLowerCase(); | ||
for (i = 10; i < 16; ++i) | ||
decoder[hex.charAt(i)] = i; | ||
decoder[hex.charCodeAt(i)] = i; | ||
for (i = 0; i < ignore.length; ++i) | ||
decoder[ignore.charAt(i)] = -1; | ||
decoder[ignore.charCodeAt(i)] = -1; | ||
} | ||
@@ -45,5 +49,3 @@ var out = haveU8 ? new Uint8Array(a.length >> 1) : [], | ||
for (i = 0; i < a.length; ++i) { | ||
var c = a.charAt(i); | ||
if (c == '=') | ||
break; | ||
var c = isString ? a.charCodeAt(i) : a[i]; | ||
c = decoder[c]; | ||
@@ -70,4 +72,4 @@ if (c == -1) | ||
// export globals | ||
if (typeof module !== 'undefined') { module.exports = Hex; } else { window.Hex = Hex; } | ||
})(); | ||
return Hex; | ||
}); |
13
int10.js
// Big integer base-10 printing library | ||
// Copyright (c) 2008-2019 Lapo Luchini <lapo@lapo.it> | ||
// Copyright (c) 2008-2020 Lapo Luchini <lapo@lapo.it> | ||
@@ -16,3 +16,6 @@ // Permission to use, copy, modify, and/or distribute this software for any | ||
(function () { | ||
(typeof define != 'undefined' ? define : function (factory) { 'use strict'; | ||
if (typeof module == 'object') module.exports = factory(); | ||
else window.int10 = factory(); | ||
})(function () { | ||
"use strict"; | ||
@@ -86,4 +89,4 @@ | ||
// export globals | ||
if (typeof module !== 'undefined') { module.exports = Int10; } else { window.Int10 = Int10; } | ||
})(); | ||
return Int10; | ||
}); |
{ | ||
"name": "@lapo/asn1js", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Generic ASN.1 parser/decoder that can decode any valid ASN.1 DER or BER structures.", | ||
@@ -18,2 +18,3 @@ "main": "asn1.js", | ||
"env": { | ||
"amd": true, | ||
"browser": true, | ||
@@ -25,3 +26,3 @@ "node": true | ||
"strict": [ "error", "function" ], | ||
"indent": [ "error", 4, { "outerIIFEBody": 0 } ], | ||
"indent": [ "error", 4, { "ignoredNodes": [ "Program > ExpressionStatement > CallExpression > FunctionExpression > BlockStatement > ExpressionStatement[directive='use strict']:first-child" ] } ], | ||
"linebreak-style": [ "error", "unix" ], | ||
@@ -33,6 +34,11 @@ "semi": [ "warn", "always" ], | ||
{ | ||
"files": [ "index.js", "test.js" ], | ||
"files": [ "test.js" ], | ||
"rules": { | ||
"strict": [ "error", "global" ] | ||
} | ||
}, { | ||
"files": [ "oids.js" ], | ||
"rules": { | ||
"indent": "off" | ||
} | ||
} | ||
@@ -39,0 +45,0 @@ ] |
@@ -8,6 +8,33 @@ asn1js | ||
Usage with `npm` / `yarn` | ||
------------------------- | ||
This package can be installed with either npm or yarn via the following commands: | ||
``` | ||
npm install @lapo/asn1js | ||
# or with yarn | ||
yarn add @lapo/asn1js | ||
``` | ||
Assuming a standard javascript bundler is setup you can import it like so: | ||
```js | ||
const ASN1 = require('@lapo/asn1js'); | ||
// or with ES modules | ||
import ASN1 from '@lapo/asn1js'; | ||
``` | ||
A submodule of this package can also be imported: | ||
```js | ||
const ASN1 = require('@lapo/asn1js/hex'); | ||
// or with ES modules | ||
import Hex from '@lapo/asn1js/hex'; | ||
``` | ||
ISC license | ||
----------- | ||
ASN.1 JavaScript decoder Copyright (c) 2008-2019 Lapo Luchini <lapo@lapo.it> | ||
ASN.1 JavaScript decoder Copyright (c) 2008-2020 Lapo Luchini <lapo@lapo.it> | ||
@@ -32,2 +59,2 @@ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
- [GitHub mirror](https://github.com/lapo-luchini/asn1js) | ||
- [Ohloh code stats](https://www.ohloh.net/p/asn1js) | ||
- [Ohloh code stats](https://www.openhub.net/p/asn1js) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
238359
3214
59
1