pixel-react 1.15.17 → 1.15.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_virtual/index10.js +2 -2
- package/lib/_virtual/index11.js +2 -2
- package/lib/_virtual/index9.js +2 -2
- package/lib/index.cjs +5568 -20
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/node_modules/js-beautify/js/src/css/beautifier.js +1 -1
- package/lib/node_modules/js-beautify/js/src/css/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/css/options.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/options.js +1 -1
- package/lib/node_modules/js-beautify/js/src/javascript/beautifier.js +1 -1
- package/lib/node_modules/js-beautify/js/src/javascript/index.js +1 -1
- package/lib/node_modules/jsencrypt/lib/JSEncrypt.js +246 -0
- package/lib/node_modules/jsencrypt/lib/JSEncrypt.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/JSEncryptRSAKey.js +325 -0
- package/lib/node_modules/jsencrypt/lib/JSEncryptRSAKey.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/index.js +6 -0
- package/lib/node_modules/jsencrypt/lib/index.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/asn1.js +570 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/asn1.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/base64.js +88 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/base64.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/hex.js +66 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/hex.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/int10.js +87 -0
- package/lib/node_modules/jsencrypt/lib/lib/asn1js/int10.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/base64.js +65 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/base64.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/jsbn.js +1700 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/jsbn.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/prng4.js +48 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/prng4.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/rng.js +77 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/rng.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/rsa.js +415 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/rsa.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/sha256.js +307 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/sha256.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/util.js +61 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsbn/util.js.map +1 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsrsasign/asn1-1.0.js +1559 -0
- package/lib/node_modules/jsencrypt/lib/lib/jsrsasign/asn1-1.0.js.map +1 -0
- package/lib/utils/getEncryptedData/getEncryptedData.d.ts +1 -1
- package/lib/utils/getEncryptedData/getEncryptedData.js +8 -17
- package/lib/utils/getEncryptedData/getEncryptedData.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSEncryptRSAKey.js","sources":["../../../../node_modules/jsencrypt/lib/JSEncryptRSAKey.js"],"sourcesContent":["var __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nimport { hex2b64 } from \"./lib/jsbn/base64\";\nimport { Hex } from \"./lib/asn1js/hex\";\nimport { Base64 } from \"./lib/asn1js/base64\";\nimport { ASN1 } from \"./lib/asn1js/asn1\";\nimport { RSAKey } from \"./lib/jsbn/rsa\";\nimport { parseBigInt } from \"./lib/jsbn/jsbn\";\nimport { KJUR } from \"./lib/jsrsasign/asn1-1.0\";\n/**\n * Create a new JSEncryptRSAKey that extends Tom Wu's RSA key object.\n * This object is just a decorator for parsing the key parameter\n * @param {string|Object} key - The key in string format, or an object containing\n * the parameters needed to build a RSAKey object.\n * @constructor\n */\nvar JSEncryptRSAKey = /** @class */ (function (_super) {\n __extends(JSEncryptRSAKey, _super);\n function JSEncryptRSAKey(key) {\n var _this = _super.call(this) || this;\n // Call the super constructor.\n // RSAKey.call(this);\n // If a key key was provided.\n if (key) {\n // If this is a string...\n if (typeof key === \"string\") {\n _this.parseKey(key);\n }\n else if (JSEncryptRSAKey.hasPrivateKeyProperty(key) ||\n JSEncryptRSAKey.hasPublicKeyProperty(key)) {\n // Set the values for the key.\n _this.parsePropertiesFrom(key);\n }\n }\n return _this;\n }\n /**\n * Method to parse a pem encoded string containing both a public or private key.\n * The method will translate the pem encoded string in a der encoded string and\n * will parse private key and public key parameters. This method accepts public key\n * in the rsaencryption pkcs #1 format (oid: 1.2.840.113549.1.1.1).\n *\n * @todo Check how many rsa formats use the same format of pkcs #1.\n *\n * The format is defined as:\n * PublicKeyInfo ::= SEQUENCE {\n * algorithm AlgorithmIdentifier,\n * PublicKey BIT STRING\n * }\n * Where AlgorithmIdentifier is:\n * AlgorithmIdentifier ::= SEQUENCE {\n * algorithm OBJECT IDENTIFIER, the OID of the enc algorithm\n * parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)\n * }\n * and PublicKey is a SEQUENCE encapsulated in a BIT STRING\n * RSAPublicKey ::= SEQUENCE {\n * modulus INTEGER, -- n\n * publicExponent INTEGER -- e\n * }\n * it's possible to examine the structure of the keys obtained from openssl using\n * an asn.1 dumper as the one used here to parse the components: http://lapo.it/asn1js/\n * @argument {string} pem the pem encoded string, can include the BEGIN/END header/footer\n * @private\n */\n JSEncryptRSAKey.prototype.parseKey = function (pem) {\n try {\n var modulus = 0;\n var public_exponent = 0;\n var reHex = /^\\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\\s*)+$/;\n var der = reHex.test(pem) ? Hex.decode(pem) : Base64.unarmor(pem);\n var asn1 = ASN1.decode(der);\n // Fixes a bug with OpenSSL 1.0+ private keys\n if (asn1.sub.length === 3) {\n asn1 = asn1.sub[2].sub[0];\n }\n if (asn1.sub.length === 9) {\n // Parse the private key.\n modulus = asn1.sub[1].getHexStringValue(); // bigint\n this.n = parseBigInt(modulus, 16);\n public_exponent = asn1.sub[2].getHexStringValue(); // int\n this.e = parseInt(public_exponent, 16);\n var private_exponent = asn1.sub[3].getHexStringValue(); // bigint\n this.d = parseBigInt(private_exponent, 16);\n var prime1 = asn1.sub[4].getHexStringValue(); // bigint\n this.p = parseBigInt(prime1, 16);\n var prime2 = asn1.sub[5].getHexStringValue(); // bigint\n this.q = parseBigInt(prime2, 16);\n var exponent1 = asn1.sub[6].getHexStringValue(); // bigint\n this.dmp1 = parseBigInt(exponent1, 16);\n var exponent2 = asn1.sub[7].getHexStringValue(); // bigint\n this.dmq1 = parseBigInt(exponent2, 16);\n var coefficient = asn1.sub[8].getHexStringValue(); // bigint\n this.coeff = parseBigInt(coefficient, 16);\n }\n else if (asn1.sub.length === 2) {\n if (asn1.sub[0].sub) {\n // Parse ASN.1 SubjectPublicKeyInfo type as defined by X.509\n var bit_string = asn1.sub[1];\n var sequence = bit_string.sub[0];\n modulus = sequence.sub[0].getHexStringValue();\n this.n = parseBigInt(modulus, 16);\n public_exponent = sequence.sub[1].getHexStringValue();\n this.e = parseInt(public_exponent, 16);\n }\n else {\n // Parse ASN.1 RSAPublicKey type as defined by PKCS #1\n modulus = asn1.sub[0].getHexStringValue();\n this.n = parseBigInt(modulus, 16);\n public_exponent = asn1.sub[1].getHexStringValue();\n this.e = parseInt(public_exponent, 16);\n }\n }\n else {\n return false;\n }\n return true;\n }\n catch (ex) {\n return false;\n }\n };\n /**\n * Translate rsa parameters in a hex encoded string representing the rsa key.\n *\n * The translation follow the ASN.1 notation :\n * RSAPrivateKey ::= SEQUENCE {\n * version Version,\n * modulus INTEGER, -- n\n * publicExponent INTEGER, -- e\n * privateExponent INTEGER, -- d\n * prime1 INTEGER, -- p\n * prime2 INTEGER, -- q\n * exponent1 INTEGER, -- d mod (p1)\n * exponent2 INTEGER, -- d mod (q-1)\n * coefficient INTEGER, -- (inverse of q) mod p\n * }\n * @returns {string} DER Encoded String representing the rsa private key\n * @private\n */\n JSEncryptRSAKey.prototype.getPrivateBaseKey = function () {\n var options = {\n array: [\n new KJUR.asn1.DERInteger({ int: 0 }),\n new KJUR.asn1.DERInteger({ bigint: this.n }),\n new KJUR.asn1.DERInteger({ int: this.e }),\n new KJUR.asn1.DERInteger({ bigint: this.d }),\n new KJUR.asn1.DERInteger({ bigint: this.p }),\n new KJUR.asn1.DERInteger({ bigint: this.q }),\n new KJUR.asn1.DERInteger({ bigint: this.dmp1 }),\n new KJUR.asn1.DERInteger({ bigint: this.dmq1 }),\n new KJUR.asn1.DERInteger({ bigint: this.coeff }),\n ],\n };\n var seq = new KJUR.asn1.DERSequence(options);\n return seq.getEncodedHex();\n };\n /**\n * base64 (pem) encoded version of the DER encoded representation\n * @returns {string} pem encoded representation without header and footer\n * @public\n */\n JSEncryptRSAKey.prototype.getPrivateBaseKeyB64 = function () {\n return hex2b64(this.getPrivateBaseKey());\n };\n /**\n * Translate rsa parameters in a hex encoded string representing the rsa public key.\n * The representation follow the ASN.1 notation :\n * PublicKeyInfo ::= SEQUENCE {\n * algorithm AlgorithmIdentifier,\n * PublicKey BIT STRING\n * }\n * Where AlgorithmIdentifier is:\n * AlgorithmIdentifier ::= SEQUENCE {\n * algorithm OBJECT IDENTIFIER, the OID of the enc algorithm\n * parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)\n * }\n * and PublicKey is a SEQUENCE encapsulated in a BIT STRING\n * RSAPublicKey ::= SEQUENCE {\n * modulus INTEGER, -- n\n * publicExponent INTEGER -- e\n * }\n * @returns {string} DER Encoded String representing the rsa public key\n * @private\n */\n JSEncryptRSAKey.prototype.getPublicBaseKey = function () {\n var first_sequence = new KJUR.asn1.DERSequence({\n array: [\n new KJUR.asn1.DERObjectIdentifier({ oid: \"1.2.840.113549.1.1.1\" }), // RSA Encryption pkcs #1 oid\n new KJUR.asn1.DERNull(),\n ],\n });\n var second_sequence = new KJUR.asn1.DERSequence({\n array: [\n new KJUR.asn1.DERInteger({ bigint: this.n }),\n new KJUR.asn1.DERInteger({ int: this.e }),\n ],\n });\n var bit_string = new KJUR.asn1.DERBitString({\n hex: \"00\" + second_sequence.getEncodedHex(),\n });\n var seq = new KJUR.asn1.DERSequence({\n array: [first_sequence, bit_string],\n });\n return seq.getEncodedHex();\n };\n /**\n * base64 (pem) encoded version of the DER encoded representation\n * @returns {string} pem encoded representation without header and footer\n * @public\n */\n JSEncryptRSAKey.prototype.getPublicBaseKeyB64 = function () {\n return hex2b64(this.getPublicBaseKey());\n };\n /**\n * wrap the string in block of width chars. The default value for rsa keys is 64\n * characters.\n * @param {string} str the pem encoded string without header and footer\n * @param {Number} [width=64] - the length the string has to be wrapped at\n * @returns {string}\n * @private\n */\n JSEncryptRSAKey.wordwrap = function (str, width) {\n width = width || 64;\n if (!str) {\n return str;\n }\n var regex = \"(.{1,\" + width + \"})( +|$\\n?)|(.{1,\" + width + \"})\";\n return str.match(RegExp(regex, \"g\")).join(\"\\n\");\n };\n /**\n * Retrieve the pem encoded private key\n * @returns {string} the pem encoded private key with header/footer\n * @public\n */\n JSEncryptRSAKey.prototype.getPrivateKey = function () {\n var key = \"-----BEGIN RSA PRIVATE KEY-----\\n\";\n key += JSEncryptRSAKey.wordwrap(this.getPrivateBaseKeyB64()) + \"\\n\";\n key += \"-----END RSA PRIVATE KEY-----\";\n return key;\n };\n /**\n * Retrieve the pem encoded public key\n * @returns {string} the pem encoded public key with header/footer\n * @public\n */\n JSEncryptRSAKey.prototype.getPublicKey = function () {\n var key = \"-----BEGIN PUBLIC KEY-----\\n\";\n key += JSEncryptRSAKey.wordwrap(this.getPublicBaseKeyB64()) + \"\\n\";\n key += \"-----END PUBLIC KEY-----\";\n return key;\n };\n /**\n * Check if the object contains the necessary parameters to populate the rsa modulus\n * and public exponent parameters.\n * @param {Object} [obj={}] - An object that may contain the two public key\n * parameters\n * @returns {boolean} true if the object contains both the modulus and the public exponent\n * properties (n and e)\n * @todo check for types of n and e. N should be a parseable bigInt object, E should\n * be a parseable integer number\n * @private\n */\n JSEncryptRSAKey.hasPublicKeyProperty = function (obj) {\n obj = obj || {};\n return obj.hasOwnProperty(\"n\") && obj.hasOwnProperty(\"e\");\n };\n /**\n * Check if the object contains ALL the parameters of an RSA key.\n * @param {Object} [obj={}] - An object that may contain nine rsa key\n * parameters\n * @returns {boolean} true if the object contains all the parameters needed\n * @todo check for types of the parameters all the parameters but the public exponent\n * should be parseable bigint objects, the public exponent should be a parseable integer number\n * @private\n */\n JSEncryptRSAKey.hasPrivateKeyProperty = function (obj) {\n obj = obj || {};\n return (obj.hasOwnProperty(\"n\") &&\n obj.hasOwnProperty(\"e\") &&\n obj.hasOwnProperty(\"d\") &&\n obj.hasOwnProperty(\"p\") &&\n obj.hasOwnProperty(\"q\") &&\n obj.hasOwnProperty(\"dmp1\") &&\n obj.hasOwnProperty(\"dmq1\") &&\n obj.hasOwnProperty(\"coeff\"));\n };\n /**\n * Parse the properties of obj in the current rsa object. Obj should AT LEAST\n * include the modulus and public exponent (n, e) parameters.\n * @param {Object} obj - the object containing rsa parameters\n * @private\n */\n JSEncryptRSAKey.prototype.parsePropertiesFrom = function (obj) {\n this.n = obj.n;\n this.e = obj.e;\n if (obj.hasOwnProperty(\"d\")) {\n this.d = obj.d;\n this.p = obj.p;\n this.q = obj.q;\n this.dmp1 = obj.dmp1;\n this.dmq1 = obj.dmq1;\n this.coeff = obj.coeff;\n }\n };\n return JSEncryptRSAKey;\n}(RSAKey));\nexport { JSEncryptRSAKey };\n"],"names":["__extends","this","extendStatics","d","b","Object","setPrototypeOf","__proto__","Array","p","prototype","hasOwnProperty","call","TypeError","String","__","constructor","create","JSEncryptRSAKey","_super","key","_this","parseKey","hasPrivateKeyProperty","hasPublicKeyProperty","parsePropertiesFrom","pem","modulus","public_exponent","reHex","der","test","Hex","decode","Base64","unarmor","asn1","ASN1","sub","length","getHexStringValue","n","parseBigInt","e","parseInt","private_exponent","prime1","prime2","q","exponent1","dmp1","exponent2","dmq1","coefficient","coeff","bit_string","sequence","ex","getPrivateBaseKey","options","array","KJUR","DERInteger","int","bigint","seq","DERSequence","getEncodedHex","getPrivateBaseKeyB64","hex2b64","getPublicBaseKey","first_sequence","DERObjectIdentifier","oid","DERNull","second_sequence","DERBitString","hex","getPublicBaseKeyB64","wordwrap","str","width","regex","match","RegExp","join","getPrivateKey","getPublicKey","obj","RSAKey"],"mappings":";;;;;;;;AAAA,IAAIA,SAAS,GAAIC,MAAI,IAAIA,MAAI,CAACD,SAAS,IAAM,YAAY;AACrD,EAAA,IAAIE,aAAa,GAAG,UAAUC,CAAC,EAAEC,CAAC,EAAE;AAChCF,IAAAA,aAAa,GAAGG,MAAM,CAACC,cAAc,IAChC;AAAEC,MAAAA,SAAS,EAAE;AAAG,KAAC,YAAYC,KAAK,IAAI,UAAUL,CAAC,EAAEC,CAAC,EAAE;MAAED,CAAC,CAACI,SAAS,GAAGH,CAAC;AAAE,IAAA,CAAE,IAC5E,UAAUD,CAAC,EAAEC,CAAC,EAAE;MAAE,KAAK,IAAIK,CAAC,IAAIL,CAAC,EAAE,IAAIC,MAAM,C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":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
import { Int10 } from './int10.js';
|
|
2
|
+
|
|
3
|
+
// ASN.1 JavaScript decoder
|
|
4
|
+
// Copyright (c) 2008-2014 Lapo Luchini <lapo@lapo.it>
|
|
5
|
+
// Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
// purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
// copyright notice and this permission notice appear in all copies.
|
|
8
|
+
//
|
|
9
|
+
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
/*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
|
|
17
|
+
/*global oids */
|
|
18
|
+
var ellipsis = "\u2026";
|
|
19
|
+
var 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)?)?$/;
|
|
20
|
+
var reTimeL = /^(\d\d\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)?)?$/;
|
|
21
|
+
function stringCut(str, len) {
|
|
22
|
+
if (str.length > len) {
|
|
23
|
+
str = str.substring(0, len) + ellipsis;
|
|
24
|
+
}
|
|
25
|
+
return str;
|
|
26
|
+
}
|
|
27
|
+
var Stream = /** @class */function () {
|
|
28
|
+
function Stream(enc, pos) {
|
|
29
|
+
this.hexDigits = "0123456789ABCDEF";
|
|
30
|
+
if (enc instanceof Stream) {
|
|
31
|
+
this.enc = enc.enc;
|
|
32
|
+
this.pos = enc.pos;
|
|
33
|
+
} else {
|
|
34
|
+
// enc should be an array or a binary string
|
|
35
|
+
this.enc = enc;
|
|
36
|
+
this.pos = pos;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
Stream.prototype.get = function (pos) {
|
|
40
|
+
if (pos === undefined) {
|
|
41
|
+
pos = this.pos++;
|
|
42
|
+
}
|
|
43
|
+
if (pos >= this.enc.length) {
|
|
44
|
+
throw new Error("Requesting byte offset ".concat(pos, " on a stream of length ").concat(this.enc.length));
|
|
45
|
+
}
|
|
46
|
+
return "string" === typeof this.enc ? this.enc.charCodeAt(pos) : this.enc[pos];
|
|
47
|
+
};
|
|
48
|
+
Stream.prototype.hexByte = function (b) {
|
|
49
|
+
return this.hexDigits.charAt(b >> 4 & 0xF) + this.hexDigits.charAt(b & 0xF);
|
|
50
|
+
};
|
|
51
|
+
Stream.prototype.hexDump = function (start, end, raw) {
|
|
52
|
+
var s = "";
|
|
53
|
+
for (var i = start; i < end; ++i) {
|
|
54
|
+
s += this.hexByte(this.get(i));
|
|
55
|
+
if (raw !== true) {
|
|
56
|
+
switch (i & 0xF) {
|
|
57
|
+
case 0x7:
|
|
58
|
+
s += " ";
|
|
59
|
+
break;
|
|
60
|
+
case 0xF:
|
|
61
|
+
s += "\n";
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
s += " ";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return s;
|
|
69
|
+
};
|
|
70
|
+
Stream.prototype.isASCII = function (start, end) {
|
|
71
|
+
for (var i = start; i < end; ++i) {
|
|
72
|
+
var c = this.get(i);
|
|
73
|
+
if (c < 32 || c > 176) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
Stream.prototype.parseStringISO = function (start, end) {
|
|
80
|
+
var s = "";
|
|
81
|
+
for (var i = start; i < end; ++i) {
|
|
82
|
+
s += String.fromCharCode(this.get(i));
|
|
83
|
+
}
|
|
84
|
+
return s;
|
|
85
|
+
};
|
|
86
|
+
Stream.prototype.parseStringUTF = function (start, end) {
|
|
87
|
+
var s = "";
|
|
88
|
+
for (var i = start; i < end;) {
|
|
89
|
+
var c = this.get(i++);
|
|
90
|
+
if (c < 128) {
|
|
91
|
+
s += String.fromCharCode(c);
|
|
92
|
+
} else if (c > 191 && c < 224) {
|
|
93
|
+
s += String.fromCharCode((c & 0x1F) << 6 | this.get(i++) & 0x3F);
|
|
94
|
+
} else {
|
|
95
|
+
s += String.fromCharCode((c & 0x0F) << 12 | (this.get(i++) & 0x3F) << 6 | this.get(i++) & 0x3F);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return s;
|
|
99
|
+
};
|
|
100
|
+
Stream.prototype.parseStringBMP = function (start, end) {
|
|
101
|
+
var str = "";
|
|
102
|
+
var hi;
|
|
103
|
+
var lo;
|
|
104
|
+
for (var i = start; i < end;) {
|
|
105
|
+
hi = this.get(i++);
|
|
106
|
+
lo = this.get(i++);
|
|
107
|
+
str += String.fromCharCode(hi << 8 | lo);
|
|
108
|
+
}
|
|
109
|
+
return str;
|
|
110
|
+
};
|
|
111
|
+
Stream.prototype.parseTime = function (start, end, shortYear) {
|
|
112
|
+
var s = this.parseStringISO(start, end);
|
|
113
|
+
var m = (shortYear ? reTimeS : reTimeL).exec(s);
|
|
114
|
+
if (!m) {
|
|
115
|
+
return "Unrecognized time: " + s;
|
|
116
|
+
}
|
|
117
|
+
if (shortYear) {
|
|
118
|
+
// to avoid querying the timer, use the fixed range [1970, 2069]
|
|
119
|
+
// it will conform with ITU X.400 [-10, +40] sliding window until 2030
|
|
120
|
+
m[1] = +m[1];
|
|
121
|
+
m[1] += +m[1] < 70 ? 2000 : 1900;
|
|
122
|
+
}
|
|
123
|
+
s = m[1] + "-" + m[2] + "-" + m[3] + " " + m[4];
|
|
124
|
+
if (m[5]) {
|
|
125
|
+
s += ":" + m[5];
|
|
126
|
+
if (m[6]) {
|
|
127
|
+
s += ":" + m[6];
|
|
128
|
+
if (m[7]) {
|
|
129
|
+
s += "." + m[7];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (m[8]) {
|
|
134
|
+
s += " UTC";
|
|
135
|
+
if (m[8] != "Z") {
|
|
136
|
+
s += m[8];
|
|
137
|
+
if (m[9]) {
|
|
138
|
+
s += ":" + m[9];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return s;
|
|
143
|
+
};
|
|
144
|
+
Stream.prototype.parseInteger = function (start, end) {
|
|
145
|
+
var v = this.get(start);
|
|
146
|
+
var neg = v > 127;
|
|
147
|
+
var pad = neg ? 255 : 0;
|
|
148
|
+
var len;
|
|
149
|
+
var s = "";
|
|
150
|
+
// skip unuseful bits (not allowed in DER)
|
|
151
|
+
while (v == pad && ++start < end) {
|
|
152
|
+
v = this.get(start);
|
|
153
|
+
}
|
|
154
|
+
len = end - start;
|
|
155
|
+
if (len === 0) {
|
|
156
|
+
return neg ? -1 : 0;
|
|
157
|
+
}
|
|
158
|
+
// show bit length of huge integers
|
|
159
|
+
if (len > 4) {
|
|
160
|
+
s = v;
|
|
161
|
+
len <<= 3;
|
|
162
|
+
while (((+s ^ pad) & 0x80) == 0) {
|
|
163
|
+
s = +s << 1;
|
|
164
|
+
--len;
|
|
165
|
+
}
|
|
166
|
+
s = "(" + len + " bit)\n";
|
|
167
|
+
}
|
|
168
|
+
// decode the integer
|
|
169
|
+
if (neg) {
|
|
170
|
+
v = v - 256;
|
|
171
|
+
}
|
|
172
|
+
var n = new Int10(v);
|
|
173
|
+
for (var i = start + 1; i < end; ++i) {
|
|
174
|
+
n.mulAdd(256, this.get(i));
|
|
175
|
+
}
|
|
176
|
+
return s + n.toString();
|
|
177
|
+
};
|
|
178
|
+
Stream.prototype.parseBitString = function (start, end, maxLength) {
|
|
179
|
+
var unusedBit = this.get(start);
|
|
180
|
+
var lenBit = (end - start - 1 << 3) - unusedBit;
|
|
181
|
+
var intro = "(" + lenBit + " bit)\n";
|
|
182
|
+
var s = "";
|
|
183
|
+
for (var i = start + 1; i < end; ++i) {
|
|
184
|
+
var b = this.get(i);
|
|
185
|
+
var skip = i == end - 1 ? unusedBit : 0;
|
|
186
|
+
for (var j = 7; j >= skip; --j) {
|
|
187
|
+
s += b >> j & 1 ? "1" : "0";
|
|
188
|
+
}
|
|
189
|
+
if (s.length > maxLength) {
|
|
190
|
+
return intro + stringCut(s, maxLength);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return intro + s;
|
|
194
|
+
};
|
|
195
|
+
Stream.prototype.parseOctetString = function (start, end, maxLength) {
|
|
196
|
+
if (this.isASCII(start, end)) {
|
|
197
|
+
return stringCut(this.parseStringISO(start, end), maxLength);
|
|
198
|
+
}
|
|
199
|
+
var len = end - start;
|
|
200
|
+
var s = "(" + len + " byte)\n";
|
|
201
|
+
maxLength /= 2; // we work in bytes
|
|
202
|
+
if (len > maxLength) {
|
|
203
|
+
end = start + maxLength;
|
|
204
|
+
}
|
|
205
|
+
for (var i = start; i < end; ++i) {
|
|
206
|
+
s += this.hexByte(this.get(i));
|
|
207
|
+
}
|
|
208
|
+
if (len > maxLength) {
|
|
209
|
+
s += ellipsis;
|
|
210
|
+
}
|
|
211
|
+
return s;
|
|
212
|
+
};
|
|
213
|
+
Stream.prototype.parseOID = function (start, end, maxLength) {
|
|
214
|
+
var s = "";
|
|
215
|
+
var n = new Int10();
|
|
216
|
+
var bits = 0;
|
|
217
|
+
for (var i = start; i < end; ++i) {
|
|
218
|
+
var v = this.get(i);
|
|
219
|
+
n.mulAdd(128, v & 0x7F);
|
|
220
|
+
bits += 7;
|
|
221
|
+
if (!(v & 0x80)) {
|
|
222
|
+
// finished
|
|
223
|
+
if (s === "") {
|
|
224
|
+
n = n.simplify();
|
|
225
|
+
if (n instanceof Int10) {
|
|
226
|
+
n.sub(80);
|
|
227
|
+
s = "2." + n.toString();
|
|
228
|
+
} else {
|
|
229
|
+
var m = n < 80 ? n < 40 ? 0 : 1 : 2;
|
|
230
|
+
s = m + "." + (n - m * 40);
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
s += "." + n.toString();
|
|
234
|
+
}
|
|
235
|
+
if (s.length > maxLength) {
|
|
236
|
+
return stringCut(s, maxLength);
|
|
237
|
+
}
|
|
238
|
+
n = new Int10();
|
|
239
|
+
bits = 0;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (bits > 0) {
|
|
243
|
+
s += ".incomplete";
|
|
244
|
+
}
|
|
245
|
+
return s;
|
|
246
|
+
};
|
|
247
|
+
return Stream;
|
|
248
|
+
}();
|
|
249
|
+
var ASN1 = /** @class */function () {
|
|
250
|
+
function ASN1(stream, header, length, tag, sub) {
|
|
251
|
+
if (!(tag instanceof ASN1Tag)) {
|
|
252
|
+
throw new Error("Invalid tag value.");
|
|
253
|
+
}
|
|
254
|
+
this.stream = stream;
|
|
255
|
+
this.header = header;
|
|
256
|
+
this.length = length;
|
|
257
|
+
this.tag = tag;
|
|
258
|
+
this.sub = sub;
|
|
259
|
+
}
|
|
260
|
+
ASN1.prototype.typeName = function () {
|
|
261
|
+
switch (this.tag.tagClass) {
|
|
262
|
+
case 0:
|
|
263
|
+
// universal
|
|
264
|
+
switch (this.tag.tagNumber) {
|
|
265
|
+
case 0x00:
|
|
266
|
+
return "EOC";
|
|
267
|
+
case 0x01:
|
|
268
|
+
return "BOOLEAN";
|
|
269
|
+
case 0x02:
|
|
270
|
+
return "INTEGER";
|
|
271
|
+
case 0x03:
|
|
272
|
+
return "BIT_STRING";
|
|
273
|
+
case 0x04:
|
|
274
|
+
return "OCTET_STRING";
|
|
275
|
+
case 0x05:
|
|
276
|
+
return "NULL";
|
|
277
|
+
case 0x06:
|
|
278
|
+
return "OBJECT_IDENTIFIER";
|
|
279
|
+
case 0x07:
|
|
280
|
+
return "ObjectDescriptor";
|
|
281
|
+
case 0x08:
|
|
282
|
+
return "EXTERNAL";
|
|
283
|
+
case 0x09:
|
|
284
|
+
return "REAL";
|
|
285
|
+
case 0x0A:
|
|
286
|
+
return "ENUMERATED";
|
|
287
|
+
case 0x0B:
|
|
288
|
+
return "EMBEDDED_PDV";
|
|
289
|
+
case 0x0C:
|
|
290
|
+
return "UTF8String";
|
|
291
|
+
case 0x10:
|
|
292
|
+
return "SEQUENCE";
|
|
293
|
+
case 0x11:
|
|
294
|
+
return "SET";
|
|
295
|
+
case 0x12:
|
|
296
|
+
return "NumericString";
|
|
297
|
+
case 0x13:
|
|
298
|
+
return "PrintableString";
|
|
299
|
+
// ASCII subset
|
|
300
|
+
case 0x14:
|
|
301
|
+
return "TeletexString";
|
|
302
|
+
// aka T61String
|
|
303
|
+
case 0x15:
|
|
304
|
+
return "VideotexString";
|
|
305
|
+
case 0x16:
|
|
306
|
+
return "IA5String";
|
|
307
|
+
// ASCII
|
|
308
|
+
case 0x17:
|
|
309
|
+
return "UTCTime";
|
|
310
|
+
case 0x18:
|
|
311
|
+
return "GeneralizedTime";
|
|
312
|
+
case 0x19:
|
|
313
|
+
return "GraphicString";
|
|
314
|
+
case 0x1A:
|
|
315
|
+
return "VisibleString";
|
|
316
|
+
// ASCII subset
|
|
317
|
+
case 0x1B:
|
|
318
|
+
return "GeneralString";
|
|
319
|
+
case 0x1C:
|
|
320
|
+
return "UniversalString";
|
|
321
|
+
case 0x1E:
|
|
322
|
+
return "BMPString";
|
|
323
|
+
}
|
|
324
|
+
return "Universal_" + this.tag.tagNumber.toString();
|
|
325
|
+
case 1:
|
|
326
|
+
return "Application_" + this.tag.tagNumber.toString();
|
|
327
|
+
case 2:
|
|
328
|
+
return "[" + this.tag.tagNumber.toString() + "]";
|
|
329
|
+
// Context
|
|
330
|
+
case 3:
|
|
331
|
+
return "Private_" + this.tag.tagNumber.toString();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
ASN1.prototype.content = function (maxLength) {
|
|
335
|
+
if (this.tag === undefined) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
if (maxLength === undefined) {
|
|
339
|
+
maxLength = Infinity;
|
|
340
|
+
}
|
|
341
|
+
var content = this.posContent();
|
|
342
|
+
var len = Math.abs(this.length);
|
|
343
|
+
if (!this.tag.isUniversal()) {
|
|
344
|
+
if (this.sub !== null) {
|
|
345
|
+
return "(" + this.sub.length + " elem)";
|
|
346
|
+
}
|
|
347
|
+
return this.stream.parseOctetString(content, content + len, maxLength);
|
|
348
|
+
}
|
|
349
|
+
switch (this.tag.tagNumber) {
|
|
350
|
+
case 0x01:
|
|
351
|
+
// BOOLEAN
|
|
352
|
+
return this.stream.get(content) === 0 ? "false" : "true";
|
|
353
|
+
case 0x02:
|
|
354
|
+
// INTEGER
|
|
355
|
+
return this.stream.parseInteger(content, content + len);
|
|
356
|
+
case 0x03:
|
|
357
|
+
// BIT_STRING
|
|
358
|
+
return this.sub ? "(" + this.sub.length + " elem)" : this.stream.parseBitString(content, content + len, maxLength);
|
|
359
|
+
case 0x04:
|
|
360
|
+
// OCTET_STRING
|
|
361
|
+
return this.sub ? "(" + this.sub.length + " elem)" : this.stream.parseOctetString(content, content + len, maxLength);
|
|
362
|
+
// case 0x05: // NULL
|
|
363
|
+
case 0x06:
|
|
364
|
+
// OBJECT_IDENTIFIER
|
|
365
|
+
return this.stream.parseOID(content, content + len, maxLength);
|
|
366
|
+
// case 0x07: // ObjectDescriptor
|
|
367
|
+
// case 0x08: // EXTERNAL
|
|
368
|
+
// case 0x09: // REAL
|
|
369
|
+
// case 0x0A: // ENUMERATED
|
|
370
|
+
// case 0x0B: // EMBEDDED_PDV
|
|
371
|
+
case 0x10: // SEQUENCE
|
|
372
|
+
case 0x11:
|
|
373
|
+
// SET
|
|
374
|
+
if (this.sub !== null) {
|
|
375
|
+
return "(" + this.sub.length + " elem)";
|
|
376
|
+
} else {
|
|
377
|
+
return "(no elem)";
|
|
378
|
+
}
|
|
379
|
+
case 0x0C:
|
|
380
|
+
// UTF8String
|
|
381
|
+
return stringCut(this.stream.parseStringUTF(content, content + len), maxLength);
|
|
382
|
+
case 0x12: // NumericString
|
|
383
|
+
case 0x13: // PrintableString
|
|
384
|
+
case 0x14: // TeletexString
|
|
385
|
+
case 0x15: // VideotexString
|
|
386
|
+
case 0x16: // IA5String
|
|
387
|
+
// case 0x19: // GraphicString
|
|
388
|
+
case 0x1A:
|
|
389
|
+
// VisibleString
|
|
390
|
+
// case 0x1B: // GeneralString
|
|
391
|
+
// case 0x1C: // UniversalString
|
|
392
|
+
return stringCut(this.stream.parseStringISO(content, content + len), maxLength);
|
|
393
|
+
case 0x1E:
|
|
394
|
+
// BMPString
|
|
395
|
+
return stringCut(this.stream.parseStringBMP(content, content + len), maxLength);
|
|
396
|
+
case 0x17: // UTCTime
|
|
397
|
+
case 0x18:
|
|
398
|
+
// GeneralizedTime
|
|
399
|
+
return this.stream.parseTime(content, content + len, this.tag.tagNumber == 0x17);
|
|
400
|
+
}
|
|
401
|
+
return null;
|
|
402
|
+
};
|
|
403
|
+
ASN1.prototype.toString = function () {
|
|
404
|
+
return this.typeName() + "@" + this.stream.pos + "[header:" + this.header + ",length:" + this.length + ",sub:" + (this.sub === null ? "null" : this.sub.length) + "]";
|
|
405
|
+
};
|
|
406
|
+
ASN1.prototype.toPrettyString = function (indent) {
|
|
407
|
+
if (indent === undefined) {
|
|
408
|
+
indent = "";
|
|
409
|
+
}
|
|
410
|
+
var s = indent + this.typeName() + " @" + this.stream.pos;
|
|
411
|
+
if (this.length >= 0) {
|
|
412
|
+
s += "+";
|
|
413
|
+
}
|
|
414
|
+
s += this.length;
|
|
415
|
+
if (this.tag.tagConstructed) {
|
|
416
|
+
s += " (constructed)";
|
|
417
|
+
} else if (this.tag.isUniversal() && (this.tag.tagNumber == 0x03 || this.tag.tagNumber == 0x04) && this.sub !== null) {
|
|
418
|
+
s += " (encapsulates)";
|
|
419
|
+
}
|
|
420
|
+
s += "\n";
|
|
421
|
+
if (this.sub !== null) {
|
|
422
|
+
indent += " ";
|
|
423
|
+
for (var i = 0, max = this.sub.length; i < max; ++i) {
|
|
424
|
+
s += this.sub[i].toPrettyString(indent);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return s;
|
|
428
|
+
};
|
|
429
|
+
ASN1.prototype.posStart = function () {
|
|
430
|
+
return this.stream.pos;
|
|
431
|
+
};
|
|
432
|
+
ASN1.prototype.posContent = function () {
|
|
433
|
+
return this.stream.pos + this.header;
|
|
434
|
+
};
|
|
435
|
+
ASN1.prototype.posEnd = function () {
|
|
436
|
+
return this.stream.pos + this.header + Math.abs(this.length);
|
|
437
|
+
};
|
|
438
|
+
ASN1.prototype.toHexString = function () {
|
|
439
|
+
return this.stream.hexDump(this.posStart(), this.posEnd(), true);
|
|
440
|
+
};
|
|
441
|
+
ASN1.decodeLength = function (stream) {
|
|
442
|
+
var buf = stream.get();
|
|
443
|
+
var len = buf & 0x7F;
|
|
444
|
+
if (len == buf) {
|
|
445
|
+
return len;
|
|
446
|
+
}
|
|
447
|
+
// no reason to use Int10, as it would be a huge buffer anyways
|
|
448
|
+
if (len > 6) {
|
|
449
|
+
throw new Error("Length over 48 bits not supported at position " + (stream.pos - 1));
|
|
450
|
+
}
|
|
451
|
+
if (len === 0) {
|
|
452
|
+
return null;
|
|
453
|
+
} // undefined
|
|
454
|
+
buf = 0;
|
|
455
|
+
for (var i = 0; i < len; ++i) {
|
|
456
|
+
buf = buf * 256 + stream.get();
|
|
457
|
+
}
|
|
458
|
+
return buf;
|
|
459
|
+
};
|
|
460
|
+
/**
|
|
461
|
+
* Retrieve the hexadecimal value (as a string) of the current ASN.1 element
|
|
462
|
+
* @returns {string}
|
|
463
|
+
* @public
|
|
464
|
+
*/
|
|
465
|
+
ASN1.prototype.getHexStringValue = function () {
|
|
466
|
+
var hexString = this.toHexString();
|
|
467
|
+
var offset = this.header * 2;
|
|
468
|
+
var length = this.length * 2;
|
|
469
|
+
return hexString.substring(offset, offset + length);
|
|
470
|
+
};
|
|
471
|
+
ASN1.decode = function (str) {
|
|
472
|
+
var stream;
|
|
473
|
+
if (!(str instanceof Stream)) {
|
|
474
|
+
stream = new Stream(str, 0);
|
|
475
|
+
} else {
|
|
476
|
+
stream = str;
|
|
477
|
+
}
|
|
478
|
+
var streamStart = new Stream(stream);
|
|
479
|
+
var tag = new ASN1Tag(stream);
|
|
480
|
+
var len = ASN1.decodeLength(stream);
|
|
481
|
+
var start = stream.pos;
|
|
482
|
+
var header = start - streamStart.pos;
|
|
483
|
+
var sub = null;
|
|
484
|
+
var getSub = function () {
|
|
485
|
+
var ret = [];
|
|
486
|
+
if (len !== null) {
|
|
487
|
+
// definite length
|
|
488
|
+
var end = start + len;
|
|
489
|
+
while (stream.pos < end) {
|
|
490
|
+
ret[ret.length] = ASN1.decode(stream);
|
|
491
|
+
}
|
|
492
|
+
if (stream.pos != end) {
|
|
493
|
+
throw new Error("Content size is not correct for container starting at offset " + start);
|
|
494
|
+
}
|
|
495
|
+
} else {
|
|
496
|
+
// undefined length
|
|
497
|
+
try {
|
|
498
|
+
for (;;) {
|
|
499
|
+
var s = ASN1.decode(stream);
|
|
500
|
+
if (s.tag.isEOC()) {
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
ret[ret.length] = s;
|
|
504
|
+
}
|
|
505
|
+
len = start - stream.pos; // undefined lengths are represented as negative values
|
|
506
|
+
} catch (e) {
|
|
507
|
+
throw new Error("Exception while decoding undefined length content: " + e);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return ret;
|
|
511
|
+
};
|
|
512
|
+
if (tag.tagConstructed) {
|
|
513
|
+
// must have valid content
|
|
514
|
+
sub = getSub();
|
|
515
|
+
} else if (tag.isUniversal() && (tag.tagNumber == 0x03 || tag.tagNumber == 0x04)) {
|
|
516
|
+
// sometimes BitString and OctetString are used to encapsulate ASN.1
|
|
517
|
+
try {
|
|
518
|
+
if (tag.tagNumber == 0x03) {
|
|
519
|
+
if (stream.get() != 0) {
|
|
520
|
+
throw new Error("BIT STRINGs with unused bits cannot encapsulate.");
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
sub = getSub();
|
|
524
|
+
for (var i = 0; i < sub.length; ++i) {
|
|
525
|
+
if (sub[i].tag.isEOC()) {
|
|
526
|
+
throw new Error("EOC is not supposed to be actual content.");
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
} catch (e) {
|
|
530
|
+
// but silently ignore when they don't
|
|
531
|
+
sub = null;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (sub === null) {
|
|
535
|
+
if (len === null) {
|
|
536
|
+
throw new Error("We can't skip over an invalid tag with undefined length at offset " + start);
|
|
537
|
+
}
|
|
538
|
+
stream.pos = start + Math.abs(len);
|
|
539
|
+
}
|
|
540
|
+
return new ASN1(streamStart, header, len, tag, sub);
|
|
541
|
+
};
|
|
542
|
+
return ASN1;
|
|
543
|
+
}();
|
|
544
|
+
var ASN1Tag = /** @class */function () {
|
|
545
|
+
function ASN1Tag(stream) {
|
|
546
|
+
var buf = stream.get();
|
|
547
|
+
this.tagClass = buf >> 6;
|
|
548
|
+
this.tagConstructed = (buf & 0x20) !== 0;
|
|
549
|
+
this.tagNumber = buf & 0x1F;
|
|
550
|
+
if (this.tagNumber == 0x1F) {
|
|
551
|
+
// long tag
|
|
552
|
+
var n = new Int10();
|
|
553
|
+
do {
|
|
554
|
+
buf = stream.get();
|
|
555
|
+
n.mulAdd(128, buf & 0x7F);
|
|
556
|
+
} while (buf & 0x80);
|
|
557
|
+
this.tagNumber = n.simplify();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
ASN1Tag.prototype.isUniversal = function () {
|
|
561
|
+
return this.tagClass === 0x00;
|
|
562
|
+
};
|
|
563
|
+
ASN1Tag.prototype.isEOC = function () {
|
|
564
|
+
return this.tagClass === 0x00 && this.tagNumber === 0x00;
|
|
565
|
+
};
|
|
566
|
+
return ASN1Tag;
|
|
567
|
+
}();
|
|
568
|
+
|
|
569
|
+
export { ASN1, ASN1Tag, Stream };
|
|
570
|
+
//# sourceMappingURL=asn1.js.map
|