@waku/enr 0.0.28-e3aa837.0 → 0.0.28
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/CHANGELOG.md +11 -0
- package/bundle/index.js +739 -3315
- package/dist/.tsbuildinfo +1 -1
- package/package.json +98 -1
package/bundle/index.js
CHANGED
@@ -1218,6 +1218,9 @@ const bases = { ...identityBase, ...base2$1, ...base8$1, ...base10$1, ...base16$
|
|
1218
1218
|
* Returns a `Uint8Array` of the requested size. Referenced memory will
|
1219
1219
|
* be initialized to 0.
|
1220
1220
|
*/
|
1221
|
+
function alloc$1(size = 0) {
|
1222
|
+
return new Uint8Array(size);
|
1223
|
+
}
|
1221
1224
|
/**
|
1222
1225
|
* Where possible returns a Uint8Array of the requested size that references
|
1223
1226
|
* uninitialized memory. Only use if you are certain you will immediately
|
@@ -1331,7 +1334,7 @@ const utf8ToBytes$2 = (s) => fromString(s, "utf8");
|
|
1331
1334
|
/**
|
1332
1335
|
* Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
|
1333
1336
|
*/
|
1334
|
-
function concat$
|
1337
|
+
function concat$1(byteArrays, totalLength) {
|
1335
1338
|
const len = totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);
|
1336
1339
|
const res = new Uint8Array(len);
|
1337
1340
|
let offset = 0;
|
@@ -3067,14 +3070,14 @@ async function sign$1(message, privateKey) {
|
|
3067
3070
|
recovered: true,
|
3068
3071
|
der: false
|
3069
3072
|
});
|
3070
|
-
return concat$
|
3073
|
+
return concat$1([signature, new Uint8Array([recoveryId])], signature.length + 1);
|
3071
3074
|
}
|
3072
3075
|
function keccak256(input) {
|
3073
3076
|
return new Uint8Array(sha3.keccak256.arrayBuffer(input));
|
3074
3077
|
}
|
3075
3078
|
function compressPublicKey(publicKey) {
|
3076
3079
|
if (publicKey.length === 64) {
|
3077
|
-
publicKey = concat$
|
3080
|
+
publicKey = concat$1([new Uint8Array([4]), publicKey], 65);
|
3078
3081
|
}
|
3079
3082
|
const point = Point.fromHex(publicKey);
|
3080
3083
|
return point.toRawBytes(true);
|
@@ -4381,24 +4384,6 @@ let Logger$1 = class Logger {
|
|
4381
4384
|
}
|
4382
4385
|
};
|
4383
4386
|
|
4384
|
-
/**
|
4385
|
-
* Returns true if the two passed Uint8Arrays have the same content
|
4386
|
-
*/
|
4387
|
-
function equals(a, b) {
|
4388
|
-
if (a === b) {
|
4389
|
-
return true;
|
4390
|
-
}
|
4391
|
-
if (a.byteLength !== b.byteLength) {
|
4392
|
-
return false;
|
4393
|
-
}
|
4394
|
-
for (let i = 0; i < a.byteLength; i++) {
|
4395
|
-
if (a[i] !== b[i]) {
|
4396
|
-
return false;
|
4397
|
-
}
|
4398
|
-
}
|
4399
|
-
return true;
|
4400
|
-
}
|
4401
|
-
|
4402
4387
|
/* eslint-disable no-fallthrough */
|
4403
4388
|
const N1 = Math.pow(2, 7);
|
4404
4389
|
const N2 = Math.pow(2, 14);
|
@@ -4635,7 +4620,7 @@ function asUint8Array(buf) {
|
|
4635
4620
|
/**
|
4636
4621
|
* Returns a new Uint8Array created by concatenating the passed Uint8Arrays
|
4637
4622
|
*/
|
4638
|
-
function concat
|
4623
|
+
function concat(arrays, length) {
|
4639
4624
|
if (length == null) {
|
4640
4625
|
length = arrays.reduce((acc, curr) => acc + curr.length, 0);
|
4641
4626
|
}
|
@@ -5158,10 +5143,10 @@ function convertToBytes(proto, str) {
|
|
5158
5143
|
return fromString(str, 'base16'); // no clue. convert from hex
|
5159
5144
|
}
|
5160
5145
|
}
|
5161
|
-
const decoders = Object.values(bases).map((c) => c.decoder);
|
5146
|
+
const decoders$1 = Object.values(bases).map((c) => c.decoder);
|
5162
5147
|
const anybaseDecoder = (function () {
|
5163
|
-
let acc = decoders[0].or(decoders[1]);
|
5164
|
-
decoders.slice(2).forEach((d) => (acc = acc.or(d)));
|
5148
|
+
let acc = decoders$1[0].or(decoders$1[1]);
|
5149
|
+
decoders$1.slice(2).forEach((d) => (acc = acc.or(d)));
|
5165
5150
|
return acc;
|
5166
5151
|
})();
|
5167
5152
|
function ip2bytes(ipString) {
|
@@ -5193,7 +5178,7 @@ function bytes2port(buf) {
|
|
5193
5178
|
function str2bytes(str) {
|
5194
5179
|
const buf = fromString(str);
|
5195
5180
|
const size = Uint8Array.from(encode$1(buf.length));
|
5196
|
-
return concat
|
5181
|
+
return concat([size, buf], size.length + buf.length);
|
5197
5182
|
}
|
5198
5183
|
function bytes2str(buf) {
|
5199
5184
|
const size = decode$1(buf);
|
@@ -5213,12 +5198,12 @@ function mh2bytes(hash) {
|
|
5213
5198
|
}
|
5214
5199
|
// the address is a varint prefixed multihash string representation
|
5215
5200
|
const size = Uint8Array.from(encode$1(mh.length));
|
5216
|
-
return concat
|
5201
|
+
return concat([size, mh], size.length + mh.length);
|
5217
5202
|
}
|
5218
5203
|
function mb2bytes(mbstr) {
|
5219
5204
|
const mb = anybaseDecoder.decode(mbstr);
|
5220
5205
|
const size = Uint8Array.from(encode$1(mb.length));
|
5221
|
-
return concat
|
5206
|
+
return concat([size, mb], size.length + mb.length);
|
5222
5207
|
}
|
5223
5208
|
function bytes2mb(buf) {
|
5224
5209
|
const size = decode$1(buf);
|
@@ -5255,7 +5240,7 @@ function onion2bytes(str) {
|
|
5255
5240
|
throw new Error('Port number is not in range(1, 65536)');
|
5256
5241
|
}
|
5257
5242
|
const portBuf = port2bytes(port);
|
5258
|
-
return concat
|
5243
|
+
return concat([buf, portBuf], buf.length + portBuf.length);
|
5259
5244
|
}
|
5260
5245
|
function onion32bytes(str) {
|
5261
5246
|
const addr = str.split(':');
|
@@ -5273,7 +5258,7 @@ function onion32bytes(str) {
|
|
5273
5258
|
throw new Error('Port number is not in range(1, 65536)');
|
5274
5259
|
}
|
5275
5260
|
const portBuf = port2bytes(port);
|
5276
|
-
return concat
|
5261
|
+
return concat([buf, portBuf], buf.length + portBuf.length);
|
5277
5262
|
}
|
5278
5263
|
function bytes2onion(buf) {
|
5279
5264
|
const addrBytes = buf.slice(0, buf.length - 2);
|
@@ -5309,7 +5294,7 @@ function stringToMultiaddrParts(str) {
|
|
5309
5294
|
}
|
5310
5295
|
p++; // advance addr part
|
5311
5296
|
if (p >= parts.length) {
|
5312
|
-
throw ParseError('invalid address: ' + str);
|
5297
|
+
throw new ParseError('invalid address: ' + str);
|
5313
5298
|
}
|
5314
5299
|
// if it's a path proto, take the rest
|
5315
5300
|
if (proto.path === true) {
|
@@ -5353,7 +5338,7 @@ function bytesToMultiaddrParts(bytes) {
|
|
5353
5338
|
const addr = bytes.slice(i + n, i + n + size);
|
5354
5339
|
i += (size + n);
|
5355
5340
|
if (i > bytes.length) { // did not end _exactly_ at buffer.length
|
5356
|
-
throw ParseError('Invalid address Uint8Array: ' + toString$1(bytes, 'base16'));
|
5341
|
+
throw new ParseError('Invalid address Uint8Array: ' + toString$1(bytes, 'base16'));
|
5357
5342
|
}
|
5358
5343
|
// ok, tuple seems good.
|
5359
5344
|
tuples.push([code, addr]);
|
@@ -5376,7 +5361,7 @@ function bytesToMultiaddrParts(bytes) {
|
|
5376
5361
|
};
|
5377
5362
|
}
|
5378
5363
|
/**
|
5379
|
-
* [[
|
5364
|
+
* [[num code, str value?]... ] -> string
|
5380
5365
|
*/
|
5381
5366
|
function stringTuplesToString(tuples) {
|
5382
5367
|
const parts = [];
|
@@ -5394,11 +5379,11 @@ function stringTuplesToString(tuples) {
|
|
5394
5379
|
* [[int code, Uint8Array ]... ] -> Uint8Array
|
5395
5380
|
*/
|
5396
5381
|
function tuplesToBytes(tuples) {
|
5397
|
-
return concat
|
5382
|
+
return concat(tuples.map((tup) => {
|
5398
5383
|
const proto = getProtocol(tup[0]);
|
5399
5384
|
let buf = Uint8Array.from(encode$1(proto.code));
|
5400
5385
|
if (tup.length > 1 && tup[1] != null) {
|
5401
|
-
buf = concat
|
5386
|
+
buf = concat([buf, tup[1]]); // add address buffer
|
5402
5387
|
}
|
5403
5388
|
return buf;
|
5404
5389
|
}));
|
@@ -5421,12 +5406,35 @@ function sizeForAddr(p, addr) {
|
|
5421
5406
|
function cleanPath(str) {
|
5422
5407
|
return '/' + str.trim().split('/').filter((a) => a).join('/');
|
5423
5408
|
}
|
5424
|
-
|
5425
|
-
|
5409
|
+
class ParseError extends Error {
|
5410
|
+
static name = 'ParseError';
|
5411
|
+
name = 'ParseError';
|
5412
|
+
constructor(str) {
|
5413
|
+
super(`Error parsing address: ${str}`);
|
5414
|
+
}
|
5415
|
+
}
|
5416
|
+
|
5417
|
+
/**
|
5418
|
+
* Returns true if the two passed Uint8Arrays have the same content
|
5419
|
+
*/
|
5420
|
+
function equals(a, b) {
|
5421
|
+
if (a === b) {
|
5422
|
+
return true;
|
5423
|
+
}
|
5424
|
+
if (a.byteLength !== b.byteLength) {
|
5425
|
+
return false;
|
5426
|
+
}
|
5427
|
+
for (let i = 0; i < a.byteLength; i++) {
|
5428
|
+
if (a[i] !== b[i]) {
|
5429
|
+
return false;
|
5430
|
+
}
|
5431
|
+
}
|
5432
|
+
return true;
|
5426
5433
|
}
|
5427
5434
|
|
5435
|
+
/* eslint-disable complexity */
|
5428
5436
|
const inspect$1 = Symbol.for('nodejs.util.inspect.custom');
|
5429
|
-
const symbol = Symbol.for('@multiformats/js-multiaddr/multiaddr');
|
5437
|
+
const symbol$1 = Symbol.for('@multiformats/js-multiaddr/multiaddr');
|
5430
5438
|
const DNS_CODES = [
|
5431
5439
|
getProtocol('dns').code,
|
5432
5440
|
getProtocol('dns4').code,
|
@@ -5448,7 +5456,7 @@ class Multiaddr {
|
|
5448
5456
|
#tuples;
|
5449
5457
|
#stringTuples;
|
5450
5458
|
#path;
|
5451
|
-
[symbol] = true;
|
5459
|
+
[symbol$1] = true;
|
5452
5460
|
constructor(addr) {
|
5453
5461
|
// default
|
5454
5462
|
if (addr == null) {
|
@@ -5500,17 +5508,17 @@ class Multiaddr {
|
|
5500
5508
|
}
|
5501
5509
|
// default to https when protocol & port are omitted from DNS addrs
|
5502
5510
|
if (DNS_CODES.includes(code)) {
|
5503
|
-
transport = tcp.name;
|
5511
|
+
transport = tcp.name === 'tcp' ? 'tcp' : 'udp';
|
5504
5512
|
port = 443;
|
5505
5513
|
host = `${value ?? ''}${zone}`;
|
5506
5514
|
family = code === dns6.code ? 6 : 4;
|
5507
5515
|
}
|
5508
5516
|
if (code === tcp.code || code === udp.code) {
|
5509
|
-
transport = getProtocol(code).name;
|
5517
|
+
transport = getProtocol(code).name === 'tcp' ? 'tcp' : 'udp';
|
5510
5518
|
port = parseInt(value ?? '');
|
5511
5519
|
}
|
5512
5520
|
if (code === ip4.code || code === ip6.code) {
|
5513
|
-
transport = getProtocol(code).name;
|
5521
|
+
transport = getProtocol(code).name === 'tcp' ? 'tcp' : 'udp';
|
5514
5522
|
host = `${value ?? ''}${zone}`;
|
5515
5523
|
family = code === ip6.code ? 6 : 4;
|
5516
5524
|
}
|
@@ -5777,7 +5785,7 @@ const resolvers = new Map();
|
|
5777
5785
|
* ```
|
5778
5786
|
*/
|
5779
5787
|
function isMultiaddr(value) {
|
5780
|
-
return Boolean(value?.[symbol]);
|
5788
|
+
return Boolean(value?.[symbol$1]);
|
5781
5789
|
}
|
5782
5790
|
/**
|
5783
5791
|
* A function that takes a {@link MultiaddrInput} and returns a {@link Multiaddr}
|
@@ -9058,3255 +9066,711 @@ var PrivateKey;
|
|
9058
9066
|
};
|
9059
9067
|
})(PrivateKey || (PrivateKey = {}));
|
9060
9068
|
|
9061
|
-
|
9062
|
-
*
|
9063
|
-
*
|
9064
|
-
*
|
9065
|
-
*
|
9066
|
-
*
|
9067
|
-
*
|
9068
|
-
*
|
9069
|
-
*
|
9070
|
-
*
|
9071
|
-
*
|
9072
|
-
*
|
9073
|
-
*
|
9074
|
-
*
|
9075
|
-
*
|
9076
|
-
*
|
9077
|
-
*
|
9078
|
-
*
|
9079
|
-
*
|
9080
|
-
*
|
9081
|
-
*
|
9082
|
-
*
|
9083
|
-
*
|
9069
|
+
/**
|
9070
|
+
* @packageDocumentation
|
9071
|
+
*
|
9072
|
+
* A class that lets you do operations over a list of Uint8Arrays without
|
9073
|
+
* copying them.
|
9074
|
+
*
|
9075
|
+
* ```js
|
9076
|
+
* import { Uint8ArrayList } from 'uint8arraylist'
|
9077
|
+
*
|
9078
|
+
* const list = new Uint8ArrayList()
|
9079
|
+
* list.append(Uint8Array.from([0, 1, 2]))
|
9080
|
+
* list.append(Uint8Array.from([3, 4, 5]))
|
9081
|
+
*
|
9082
|
+
* list.subarray()
|
9083
|
+
* // -> Uint8Array([0, 1, 2, 3, 4, 5])
|
9084
|
+
*
|
9085
|
+
* list.consume(3)
|
9086
|
+
* list.subarray()
|
9087
|
+
* // -> Uint8Array([3, 4, 5])
|
9088
|
+
*
|
9089
|
+
* // you can also iterate over the list
|
9090
|
+
* for (const buf of list) {
|
9091
|
+
* // ..do something with `buf`
|
9092
|
+
* }
|
9093
|
+
*
|
9094
|
+
* list.subarray(0, 1)
|
9095
|
+
* // -> Uint8Array([0])
|
9096
|
+
* ```
|
9097
|
+
*
|
9098
|
+
* ## Converting Uint8ArrayLists to Uint8Arrays
|
9099
|
+
*
|
9100
|
+
* There are two ways to turn a `Uint8ArrayList` into a `Uint8Array` - `.slice` and `.subarray` and one way to turn a `Uint8ArrayList` into a `Uint8ArrayList` with different contents - `.sublist`.
|
9101
|
+
*
|
9102
|
+
* ### slice
|
9103
|
+
*
|
9104
|
+
* Slice follows the same semantics as [Uint8Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice) in that it creates a new `Uint8Array` and copies bytes into it using an optional offset & length.
|
9105
|
+
*
|
9106
|
+
* ```js
|
9107
|
+
* const list = new Uint8ArrayList()
|
9108
|
+
* list.append(Uint8Array.from([0, 1, 2]))
|
9109
|
+
* list.append(Uint8Array.from([3, 4, 5]))
|
9110
|
+
*
|
9111
|
+
* list.slice(0, 1)
|
9112
|
+
* // -> Uint8Array([0])
|
9113
|
+
* ```
|
9114
|
+
*
|
9115
|
+
* ### subarray
|
9116
|
+
*
|
9117
|
+
* Subarray attempts to follow the same semantics as [Uint8Array.subarray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray) with one important different - this is a no-copy operation, unless the requested bytes span two internal buffers in which case it is a copy operation.
|
9118
|
+
*
|
9119
|
+
* ```js
|
9120
|
+
* const list = new Uint8ArrayList()
|
9121
|
+
* list.append(Uint8Array.from([0, 1, 2]))
|
9122
|
+
* list.append(Uint8Array.from([3, 4, 5]))
|
9123
|
+
*
|
9124
|
+
* list.subarray(0, 1)
|
9125
|
+
* // -> Uint8Array([0]) - no-copy
|
9126
|
+
*
|
9127
|
+
* list.subarray(2, 5)
|
9128
|
+
* // -> Uint8Array([2, 3, 4]) - copy
|
9129
|
+
* ```
|
9130
|
+
*
|
9131
|
+
* ### sublist
|
9132
|
+
*
|
9133
|
+
* Sublist creates and returns a new `Uint8ArrayList` that shares the underlying buffers with the original so is always a no-copy operation.
|
9134
|
+
*
|
9135
|
+
* ```js
|
9136
|
+
* const list = new Uint8ArrayList()
|
9137
|
+
* list.append(Uint8Array.from([0, 1, 2]))
|
9138
|
+
* list.append(Uint8Array.from([3, 4, 5]))
|
9139
|
+
*
|
9140
|
+
* list.sublist(0, 1)
|
9141
|
+
* // -> Uint8ArrayList([0]) - no-copy
|
9142
|
+
*
|
9143
|
+
* list.sublist(2, 5)
|
9144
|
+
* // -> Uint8ArrayList([2], [3, 4]) - no-copy
|
9145
|
+
* ```
|
9146
|
+
*
|
9147
|
+
* ## Inspiration
|
9148
|
+
*
|
9149
|
+
* Borrows liberally from [bl](https://www.npmjs.com/package/bl) but only uses native JS types.
|
9084
9150
|
*/
|
9085
|
-
|
9086
|
-
|
9087
|
-
|
9088
|
-
|
9089
|
-
return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
|
9151
|
+
const symbol = Symbol.for('@achingbrain/uint8arraylist');
|
9152
|
+
function findBufAndOffset(bufs, index) {
|
9153
|
+
if (index == null || index < 0) {
|
9154
|
+
throw new RangeError('index is out of bounds');
|
9090
9155
|
}
|
9091
|
-
|
9092
|
-
|
9093
|
-
|
9094
|
-
|
9095
|
-
|
9096
|
-
|
9156
|
+
let offset = 0;
|
9157
|
+
for (const buf of bufs) {
|
9158
|
+
const bufEnd = offset + buf.byteLength;
|
9159
|
+
if (index < bufEnd) {
|
9160
|
+
return {
|
9161
|
+
buf,
|
9162
|
+
index: index - offset
|
9163
|
+
};
|
9097
9164
|
}
|
9098
|
-
|
9099
|
-
|
9165
|
+
offset = bufEnd;
|
9166
|
+
}
|
9167
|
+
throw new RangeError('index is out of bounds');
|
9168
|
+
}
|
9169
|
+
/**
|
9170
|
+
* Check if object is a CID instance
|
9171
|
+
*
|
9172
|
+
* @example
|
9173
|
+
*
|
9174
|
+
* ```js
|
9175
|
+
* import { isUint8ArrayList, Uint8ArrayList } from 'uint8arraylist'
|
9176
|
+
*
|
9177
|
+
* isUint8ArrayList(true) // false
|
9178
|
+
* isUint8ArrayList([]) // false
|
9179
|
+
* isUint8ArrayList(new Uint8ArrayList()) // true
|
9180
|
+
* ```
|
9181
|
+
*/
|
9182
|
+
function isUint8ArrayList(value) {
|
9183
|
+
return Boolean(value?.[symbol]);
|
9184
|
+
}
|
9185
|
+
class Uint8ArrayList {
|
9186
|
+
bufs;
|
9187
|
+
length;
|
9188
|
+
[symbol] = true;
|
9189
|
+
constructor(...data) {
|
9190
|
+
this.bufs = [];
|
9191
|
+
this.length = 0;
|
9192
|
+
if (data.length > 0) {
|
9193
|
+
this.appendAll(data);
|
9100
9194
|
}
|
9101
|
-
return this.toUint8Array(data.buffer)
|
9102
|
-
.slice(data.byteOffset, data.byteOffset + data.byteLength)
|
9103
|
-
.buffer;
|
9104
9195
|
}
|
9105
|
-
|
9106
|
-
|
9196
|
+
*[Symbol.iterator]() {
|
9197
|
+
yield* this.bufs;
|
9107
9198
|
}
|
9108
|
-
|
9109
|
-
|
9110
|
-
|
9111
|
-
|
9112
|
-
|
9113
|
-
|
9199
|
+
get byteLength() {
|
9200
|
+
return this.length;
|
9201
|
+
}
|
9202
|
+
/**
|
9203
|
+
* Add one or more `bufs` to the end of this Uint8ArrayList
|
9204
|
+
*/
|
9205
|
+
append(...bufs) {
|
9206
|
+
this.appendAll(bufs);
|
9207
|
+
}
|
9208
|
+
/**
|
9209
|
+
* Add all `bufs` to the end of this Uint8ArrayList
|
9210
|
+
*/
|
9211
|
+
appendAll(bufs) {
|
9212
|
+
let length = 0;
|
9213
|
+
for (const buf of bufs) {
|
9214
|
+
if (buf instanceof Uint8Array) {
|
9215
|
+
length += buf.byteLength;
|
9216
|
+
this.bufs.push(buf);
|
9217
|
+
}
|
9218
|
+
else if (isUint8ArrayList(buf)) {
|
9219
|
+
length += buf.byteLength;
|
9220
|
+
this.bufs.push(...buf.bufs);
|
9221
|
+
}
|
9222
|
+
else {
|
9223
|
+
throw new Error('Could not append value, must be an Uint8Array or a Uint8ArrayList');
|
9224
|
+
}
|
9114
9225
|
}
|
9115
|
-
|
9116
|
-
|
9226
|
+
this.length += length;
|
9227
|
+
}
|
9228
|
+
/**
|
9229
|
+
* Add one or more `bufs` to the start of this Uint8ArrayList
|
9230
|
+
*/
|
9231
|
+
prepend(...bufs) {
|
9232
|
+
this.prependAll(bufs);
|
9233
|
+
}
|
9234
|
+
/**
|
9235
|
+
* Add all `bufs` to the start of this Uint8ArrayList
|
9236
|
+
*/
|
9237
|
+
prependAll(bufs) {
|
9238
|
+
let length = 0;
|
9239
|
+
for (const buf of bufs.reverse()) {
|
9240
|
+
if (buf instanceof Uint8Array) {
|
9241
|
+
length += buf.byteLength;
|
9242
|
+
this.bufs.unshift(buf);
|
9243
|
+
}
|
9244
|
+
else if (isUint8ArrayList(buf)) {
|
9245
|
+
length += buf.byteLength;
|
9246
|
+
this.bufs.unshift(...buf.bufs);
|
9247
|
+
}
|
9248
|
+
else {
|
9249
|
+
throw new Error('Could not prepend value, must be an Uint8Array or a Uint8ArrayList');
|
9250
|
+
}
|
9117
9251
|
}
|
9118
|
-
|
9252
|
+
this.length += length;
|
9119
9253
|
}
|
9120
|
-
|
9121
|
-
|
9122
|
-
|
9254
|
+
/**
|
9255
|
+
* Read the value at `index`
|
9256
|
+
*/
|
9257
|
+
get(index) {
|
9258
|
+
const res = findBufAndOffset(this.bufs, index);
|
9259
|
+
return res.buf[res.index];
|
9123
9260
|
}
|
9124
|
-
|
9125
|
-
|
9126
|
-
|
9261
|
+
/**
|
9262
|
+
* Set the value at `index` to `value`
|
9263
|
+
*/
|
9264
|
+
set(index, value) {
|
9265
|
+
const res = findBufAndOffset(this.bufs, index);
|
9266
|
+
res.buf[res.index] = value;
|
9127
9267
|
}
|
9128
|
-
|
9129
|
-
|
9130
|
-
|
9131
|
-
|
9132
|
-
|
9268
|
+
/**
|
9269
|
+
* Copy bytes from `buf` to the index specified by `offset`
|
9270
|
+
*/
|
9271
|
+
write(buf, offset = 0) {
|
9272
|
+
if (buf instanceof Uint8Array) {
|
9273
|
+
for (let i = 0; i < buf.length; i++) {
|
9274
|
+
this.set(offset + i, buf[i]);
|
9275
|
+
}
|
9133
9276
|
}
|
9134
|
-
|
9135
|
-
|
9136
|
-
|
9277
|
+
else if (isUint8ArrayList(buf)) {
|
9278
|
+
for (let i = 0; i < buf.length; i++) {
|
9279
|
+
this.set(offset + i, buf.get(i));
|
9137
9280
|
}
|
9138
9281
|
}
|
9139
|
-
|
9282
|
+
else {
|
9283
|
+
throw new Error('Could not write value, must be an Uint8Array or a Uint8ArrayList');
|
9284
|
+
}
|
9140
9285
|
}
|
9141
|
-
|
9142
|
-
|
9143
|
-
|
9144
|
-
|
9286
|
+
/**
|
9287
|
+
* Remove bytes from the front of the pool
|
9288
|
+
*/
|
9289
|
+
consume(bytes) {
|
9290
|
+
// first, normalize the argument, in accordance with how Buffer does it
|
9291
|
+
bytes = Math.trunc(bytes);
|
9292
|
+
// do nothing if not a positive number
|
9293
|
+
if (Number.isNaN(bytes) || bytes <= 0) {
|
9294
|
+
return;
|
9145
9295
|
}
|
9146
|
-
|
9147
|
-
|
9296
|
+
// if consuming all bytes, skip iterating
|
9297
|
+
if (bytes === this.byteLength) {
|
9298
|
+
this.bufs = [];
|
9299
|
+
this.length = 0;
|
9300
|
+
return;
|
9148
9301
|
}
|
9149
|
-
|
9150
|
-
if (
|
9151
|
-
|
9302
|
+
while (this.bufs.length > 0) {
|
9303
|
+
if (bytes >= this.bufs[0].byteLength) {
|
9304
|
+
bytes -= this.bufs[0].byteLength;
|
9305
|
+
this.length -= this.bufs[0].byteLength;
|
9306
|
+
this.bufs.shift();
|
9152
9307
|
}
|
9153
9308
|
else {
|
9154
|
-
|
9309
|
+
this.bufs[0] = this.bufs[0].subarray(bytes);
|
9310
|
+
this.length -= bytes;
|
9311
|
+
break;
|
9155
9312
|
}
|
9156
9313
|
}
|
9157
|
-
let size = 0;
|
9158
|
-
for (const buffer of buffers) {
|
9159
|
-
size += buffer.byteLength;
|
9160
|
-
}
|
9161
|
-
const res = new Uint8Array(size);
|
9162
|
-
let offset = 0;
|
9163
|
-
for (const buffer of buffers) {
|
9164
|
-
const view = this.toUint8Array(buffer);
|
9165
|
-
res.set(view, offset);
|
9166
|
-
offset += view.length;
|
9167
|
-
}
|
9168
|
-
if (args[args.length - 1] instanceof Function) {
|
9169
|
-
return this.toView(res, args[args.length - 1]);
|
9170
|
-
}
|
9171
|
-
return res.buffer;
|
9172
9314
|
}
|
9173
|
-
|
9174
|
-
|
9175
|
-
|
9176
|
-
|
9177
|
-
|
9178
|
-
|
9179
|
-
|
9180
|
-
|
9181
|
-
|
9182
|
-
const uintArray = new Uint8Array(s.length);
|
9183
|
-
for (let i = 0; i < s.length; i++) {
|
9184
|
-
uintArray[i] = s.charCodeAt(i);
|
9185
|
-
}
|
9186
|
-
return uintArray.buffer;
|
9315
|
+
/**
|
9316
|
+
* Extracts a section of an array and returns a new array.
|
9317
|
+
*
|
9318
|
+
* This is a copy operation as it is with Uint8Arrays and Arrays
|
9319
|
+
* - note this is different to the behaviour of Node Buffers.
|
9320
|
+
*/
|
9321
|
+
slice(beginInclusive, endExclusive) {
|
9322
|
+
const { bufs, length } = this._subList(beginInclusive, endExclusive);
|
9323
|
+
return concat(bufs, length);
|
9187
9324
|
}
|
9188
|
-
|
9189
|
-
|
9190
|
-
|
9191
|
-
|
9192
|
-
|
9325
|
+
/**
|
9326
|
+
* Returns a alloc from the given start and end element index.
|
9327
|
+
*
|
9328
|
+
* In the best case where the data extracted comes from a single Uint8Array
|
9329
|
+
* internally this is a no-copy operation otherwise it is a copy operation.
|
9330
|
+
*/
|
9331
|
+
subarray(beginInclusive, endExclusive) {
|
9332
|
+
const { bufs, length } = this._subList(beginInclusive, endExclusive);
|
9333
|
+
if (bufs.length === 1) {
|
9334
|
+
return bufs[0];
|
9193
9335
|
}
|
9194
|
-
|
9195
|
-
return decodedString;
|
9336
|
+
return concat(bufs, length);
|
9196
9337
|
}
|
9197
|
-
|
9198
|
-
|
9199
|
-
|
9200
|
-
|
9201
|
-
|
9202
|
-
|
9203
|
-
|
9204
|
-
|
9205
|
-
|
9206
|
-
|
9207
|
-
|
9338
|
+
/**
|
9339
|
+
* Returns a allocList from the given start and end element index.
|
9340
|
+
*
|
9341
|
+
* This is a no-copy operation.
|
9342
|
+
*/
|
9343
|
+
sublist(beginInclusive, endExclusive) {
|
9344
|
+
const { bufs, length } = this._subList(beginInclusive, endExclusive);
|
9345
|
+
const list = new Uint8ArrayList();
|
9346
|
+
list.length = length;
|
9347
|
+
// don't loop, just set the bufs
|
9348
|
+
list.bufs = [...bufs];
|
9349
|
+
return list;
|
9208
9350
|
}
|
9209
|
-
|
9210
|
-
|
9211
|
-
|
9212
|
-
|
9213
|
-
|
9351
|
+
_subList(beginInclusive, endExclusive) {
|
9352
|
+
beginInclusive = beginInclusive ?? 0;
|
9353
|
+
endExclusive = endExclusive ?? this.length;
|
9354
|
+
if (beginInclusive < 0) {
|
9355
|
+
beginInclusive = this.length + beginInclusive;
|
9214
9356
|
}
|
9215
|
-
|
9216
|
-
|
9217
|
-
}
|
9218
|
-
class Convert {
|
9219
|
-
static isHex(data) {
|
9220
|
-
return typeof data === STRING_TYPE
|
9221
|
-
&& HEX_REGEX.test(data);
|
9222
|
-
}
|
9223
|
-
static isBase64(data) {
|
9224
|
-
return typeof data === STRING_TYPE
|
9225
|
-
&& BASE64_REGEX.test(data);
|
9226
|
-
}
|
9227
|
-
static isBase64Url(data) {
|
9228
|
-
return typeof data === STRING_TYPE
|
9229
|
-
&& BASE64URL_REGEX.test(data);
|
9230
|
-
}
|
9231
|
-
static ToString(buffer, enc = "utf8") {
|
9232
|
-
const buf = BufferSourceConverter.toUint8Array(buffer);
|
9233
|
-
switch (enc.toLowerCase()) {
|
9234
|
-
case "utf8":
|
9235
|
-
return this.ToUtf8String(buf);
|
9236
|
-
case "binary":
|
9237
|
-
return this.ToBinary(buf);
|
9238
|
-
case "hex":
|
9239
|
-
return this.ToHex(buf);
|
9240
|
-
case "base64":
|
9241
|
-
return this.ToBase64(buf);
|
9242
|
-
case "base64url":
|
9243
|
-
return this.ToBase64Url(buf);
|
9244
|
-
case "utf16le":
|
9245
|
-
return Utf16Converter.toString(buf, true);
|
9246
|
-
case "utf16":
|
9247
|
-
case "utf16be":
|
9248
|
-
return Utf16Converter.toString(buf);
|
9249
|
-
default:
|
9250
|
-
throw new Error(`Unknown type of encoding '${enc}'`);
|
9251
|
-
}
|
9252
|
-
}
|
9253
|
-
static FromString(str, enc = "utf8") {
|
9254
|
-
if (!str) {
|
9255
|
-
return new ArrayBuffer(0);
|
9256
|
-
}
|
9257
|
-
switch (enc.toLowerCase()) {
|
9258
|
-
case "utf8":
|
9259
|
-
return this.FromUtf8String(str);
|
9260
|
-
case "binary":
|
9261
|
-
return this.FromBinary(str);
|
9262
|
-
case "hex":
|
9263
|
-
return this.FromHex(str);
|
9264
|
-
case "base64":
|
9265
|
-
return this.FromBase64(str);
|
9266
|
-
case "base64url":
|
9267
|
-
return this.FromBase64Url(str);
|
9268
|
-
case "utf16le":
|
9269
|
-
return Utf16Converter.fromString(str, true);
|
9270
|
-
case "utf16":
|
9271
|
-
case "utf16be":
|
9272
|
-
return Utf16Converter.fromString(str);
|
9273
|
-
default:
|
9274
|
-
throw new Error(`Unknown type of encoding '${enc}'`);
|
9357
|
+
if (endExclusive < 0) {
|
9358
|
+
endExclusive = this.length + endExclusive;
|
9275
9359
|
}
|
9276
|
-
|
9277
|
-
|
9278
|
-
const buf = BufferSourceConverter.toUint8Array(buffer);
|
9279
|
-
if (typeof btoa !== "undefined") {
|
9280
|
-
const binary = this.ToString(buf, "binary");
|
9281
|
-
return btoa(binary);
|
9360
|
+
if (beginInclusive < 0 || endExclusive > this.length) {
|
9361
|
+
throw new RangeError('index is out of bounds');
|
9282
9362
|
}
|
9283
|
-
|
9284
|
-
return
|
9363
|
+
if (beginInclusive === endExclusive) {
|
9364
|
+
return { bufs: [], length: 0 };
|
9285
9365
|
}
|
9286
|
-
|
9287
|
-
|
9288
|
-
const formatted = this.formatString(base64);
|
9289
|
-
if (!formatted) {
|
9290
|
-
return new ArrayBuffer(0);
|
9366
|
+
if (beginInclusive === 0 && endExclusive === this.length) {
|
9367
|
+
return { bufs: this.bufs, length: this.length };
|
9291
9368
|
}
|
9292
|
-
|
9293
|
-
|
9369
|
+
const bufs = [];
|
9370
|
+
let offset = 0;
|
9371
|
+
for (let i = 0; i < this.bufs.length; i++) {
|
9372
|
+
const buf = this.bufs[i];
|
9373
|
+
const bufStart = offset;
|
9374
|
+
const bufEnd = bufStart + buf.byteLength;
|
9375
|
+
// for next loop
|
9376
|
+
offset = bufEnd;
|
9377
|
+
if (beginInclusive >= bufEnd) {
|
9378
|
+
// start after this buf
|
9379
|
+
continue;
|
9380
|
+
}
|
9381
|
+
const sliceStartInBuf = beginInclusive >= bufStart && beginInclusive < bufEnd;
|
9382
|
+
const sliceEndsInBuf = endExclusive > bufStart && endExclusive <= bufEnd;
|
9383
|
+
if (sliceStartInBuf && sliceEndsInBuf) {
|
9384
|
+
// slice is wholly contained within this buffer
|
9385
|
+
if (beginInclusive === bufStart && endExclusive === bufEnd) {
|
9386
|
+
// requested whole buffer
|
9387
|
+
bufs.push(buf);
|
9388
|
+
break;
|
9389
|
+
}
|
9390
|
+
// requested part of buffer
|
9391
|
+
const start = beginInclusive - bufStart;
|
9392
|
+
bufs.push(buf.subarray(start, start + (endExclusive - beginInclusive)));
|
9393
|
+
break;
|
9394
|
+
}
|
9395
|
+
if (sliceStartInBuf) {
|
9396
|
+
// slice starts in this buffer
|
9397
|
+
if (beginInclusive === 0) {
|
9398
|
+
// requested whole buffer
|
9399
|
+
bufs.push(buf);
|
9400
|
+
continue;
|
9401
|
+
}
|
9402
|
+
// requested part of buffer
|
9403
|
+
bufs.push(buf.subarray(beginInclusive - bufStart));
|
9404
|
+
continue;
|
9405
|
+
}
|
9406
|
+
if (sliceEndsInBuf) {
|
9407
|
+
if (endExclusive === bufEnd) {
|
9408
|
+
// requested whole buffer
|
9409
|
+
bufs.push(buf);
|
9410
|
+
break;
|
9411
|
+
}
|
9412
|
+
// requested part of buffer
|
9413
|
+
bufs.push(buf.subarray(0, endExclusive - bufStart));
|
9414
|
+
break;
|
9415
|
+
}
|
9416
|
+
// slice started before this buffer and ends after it
|
9417
|
+
bufs.push(buf);
|
9294
9418
|
}
|
9295
|
-
|
9296
|
-
|
9419
|
+
return { bufs, length: endExclusive - beginInclusive };
|
9420
|
+
}
|
9421
|
+
indexOf(search, offset = 0) {
|
9422
|
+
if (!isUint8ArrayList(search) && !(search instanceof Uint8Array)) {
|
9423
|
+
throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');
|
9297
9424
|
}
|
9298
|
-
|
9299
|
-
|
9300
|
-
|
9301
|
-
|
9302
|
-
static FromBase64Url(base64url) {
|
9303
|
-
const formatted = this.formatString(base64url);
|
9304
|
-
if (!formatted) {
|
9305
|
-
return new ArrayBuffer(0);
|
9306
|
-
}
|
9307
|
-
if (!Convert.isBase64Url(formatted)) {
|
9308
|
-
throw new TypeError("Argument 'base64url' is not Base64Url encoded");
|
9309
|
-
}
|
9310
|
-
return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
|
9311
|
-
}
|
9312
|
-
static ToBase64Url(data) {
|
9313
|
-
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
|
9314
|
-
}
|
9315
|
-
static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
|
9316
|
-
switch (encoding) {
|
9317
|
-
case "ascii":
|
9318
|
-
return this.FromBinary(text);
|
9319
|
-
case "utf8":
|
9320
|
-
return Utf8Converter.fromString(text);
|
9321
|
-
case "utf16":
|
9322
|
-
case "utf16be":
|
9323
|
-
return Utf16Converter.fromString(text);
|
9324
|
-
case "utf16le":
|
9325
|
-
case "usc2":
|
9326
|
-
return Utf16Converter.fromString(text, true);
|
9327
|
-
default:
|
9328
|
-
throw new Error(`Unknown type of encoding '${encoding}'`);
|
9329
|
-
}
|
9330
|
-
}
|
9331
|
-
static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
|
9332
|
-
switch (encoding) {
|
9333
|
-
case "ascii":
|
9334
|
-
return this.ToBinary(buffer);
|
9335
|
-
case "utf8":
|
9336
|
-
return Utf8Converter.toString(buffer);
|
9337
|
-
case "utf16":
|
9338
|
-
case "utf16be":
|
9339
|
-
return Utf16Converter.toString(buffer);
|
9340
|
-
case "utf16le":
|
9341
|
-
case "usc2":
|
9342
|
-
return Utf16Converter.toString(buffer, true);
|
9343
|
-
default:
|
9344
|
-
throw new Error(`Unknown type of encoding '${encoding}'`);
|
9425
|
+
const needle = search instanceof Uint8Array ? search : search.subarray();
|
9426
|
+
offset = Number(offset ?? 0);
|
9427
|
+
if (isNaN(offset)) {
|
9428
|
+
offset = 0;
|
9345
9429
|
}
|
9346
|
-
|
9347
|
-
|
9348
|
-
const stringLength = text.length;
|
9349
|
-
const resultView = new Uint8Array(stringLength);
|
9350
|
-
for (let i = 0; i < stringLength; i++) {
|
9351
|
-
resultView[i] = text.charCodeAt(i);
|
9430
|
+
if (offset < 0) {
|
9431
|
+
offset = this.length + offset;
|
9352
9432
|
}
|
9353
|
-
|
9354
|
-
|
9355
|
-
static ToBinary(buffer) {
|
9356
|
-
const buf = BufferSourceConverter.toUint8Array(buffer);
|
9357
|
-
let res = "";
|
9358
|
-
for (let i = 0; i < buf.length; i++) {
|
9359
|
-
res += String.fromCharCode(buf[i]);
|
9433
|
+
if (offset < 0) {
|
9434
|
+
offset = 0;
|
9360
9435
|
}
|
9361
|
-
|
9362
|
-
|
9363
|
-
|
9364
|
-
|
9365
|
-
|
9366
|
-
|
9367
|
-
|
9368
|
-
|
9369
|
-
|
9370
|
-
|
9436
|
+
if (search.length === 0) {
|
9437
|
+
return offset > this.length ? this.length : offset;
|
9438
|
+
}
|
9439
|
+
// https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm
|
9440
|
+
const M = needle.byteLength;
|
9441
|
+
if (M === 0) {
|
9442
|
+
throw new TypeError('search must be at least 1 byte long');
|
9443
|
+
}
|
9444
|
+
// radix
|
9445
|
+
const radix = 256;
|
9446
|
+
const rightmostPositions = new Int32Array(radix);
|
9447
|
+
// position of the rightmost occurrence of the byte c in the pattern
|
9448
|
+
for (let c = 0; c < radix; c++) {
|
9449
|
+
// -1 for bytes not in pattern
|
9450
|
+
rightmostPositions[c] = -1;
|
9451
|
+
}
|
9452
|
+
for (let j = 0; j < M; j++) {
|
9453
|
+
// rightmost position for bytes in pattern
|
9454
|
+
rightmostPositions[needle[j]] = j;
|
9455
|
+
}
|
9456
|
+
// Return offset of first match, -1 if no match
|
9457
|
+
const right = rightmostPositions;
|
9458
|
+
const lastIndex = this.byteLength - needle.byteLength;
|
9459
|
+
const lastPatIndex = needle.byteLength - 1;
|
9460
|
+
let skip;
|
9461
|
+
for (let i = offset; i <= lastIndex; i += skip) {
|
9462
|
+
skip = 0;
|
9463
|
+
for (let j = lastPatIndex; j >= 0; j--) {
|
9464
|
+
const char = this.get(i + j);
|
9465
|
+
if (needle[j] !== char) {
|
9466
|
+
skip = Math.max(1, j - right[char]);
|
9467
|
+
break;
|
9468
|
+
}
|
9469
|
+
}
|
9470
|
+
if (skip === 0) {
|
9471
|
+
return i;
|
9371
9472
|
}
|
9372
|
-
result += byte.toString(16);
|
9373
9473
|
}
|
9374
|
-
return
|
9474
|
+
return -1;
|
9475
|
+
}
|
9476
|
+
getInt8(byteOffset) {
|
9477
|
+
const buf = this.subarray(byteOffset, byteOffset + 1);
|
9478
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9479
|
+
return view.getInt8(0);
|
9480
|
+
}
|
9481
|
+
setInt8(byteOffset, value) {
|
9482
|
+
const buf = allocUnsafe(1);
|
9483
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9484
|
+
view.setInt8(0, value);
|
9485
|
+
this.write(buf, byteOffset);
|
9486
|
+
}
|
9487
|
+
getInt16(byteOffset, littleEndian) {
|
9488
|
+
const buf = this.subarray(byteOffset, byteOffset + 2);
|
9489
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9490
|
+
return view.getInt16(0, littleEndian);
|
9491
|
+
}
|
9492
|
+
setInt16(byteOffset, value, littleEndian) {
|
9493
|
+
const buf = alloc$1(2);
|
9494
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9495
|
+
view.setInt16(0, value, littleEndian);
|
9496
|
+
this.write(buf, byteOffset);
|
9497
|
+
}
|
9498
|
+
getInt32(byteOffset, littleEndian) {
|
9499
|
+
const buf = this.subarray(byteOffset, byteOffset + 4);
|
9500
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9501
|
+
return view.getInt32(0, littleEndian);
|
9502
|
+
}
|
9503
|
+
setInt32(byteOffset, value, littleEndian) {
|
9504
|
+
const buf = alloc$1(4);
|
9505
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9506
|
+
view.setInt32(0, value, littleEndian);
|
9507
|
+
this.write(buf, byteOffset);
|
9508
|
+
}
|
9509
|
+
getBigInt64(byteOffset, littleEndian) {
|
9510
|
+
const buf = this.subarray(byteOffset, byteOffset + 8);
|
9511
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9512
|
+
return view.getBigInt64(0, littleEndian);
|
9513
|
+
}
|
9514
|
+
setBigInt64(byteOffset, value, littleEndian) {
|
9515
|
+
const buf = alloc$1(8);
|
9516
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9517
|
+
view.setBigInt64(0, value, littleEndian);
|
9518
|
+
this.write(buf, byteOffset);
|
9519
|
+
}
|
9520
|
+
getUint8(byteOffset) {
|
9521
|
+
const buf = this.subarray(byteOffset, byteOffset + 1);
|
9522
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9523
|
+
return view.getUint8(0);
|
9524
|
+
}
|
9525
|
+
setUint8(byteOffset, value) {
|
9526
|
+
const buf = allocUnsafe(1);
|
9527
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9528
|
+
view.setUint8(0, value);
|
9529
|
+
this.write(buf, byteOffset);
|
9530
|
+
}
|
9531
|
+
getUint16(byteOffset, littleEndian) {
|
9532
|
+
const buf = this.subarray(byteOffset, byteOffset + 2);
|
9533
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9534
|
+
return view.getUint16(0, littleEndian);
|
9535
|
+
}
|
9536
|
+
setUint16(byteOffset, value, littleEndian) {
|
9537
|
+
const buf = alloc$1(2);
|
9538
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9539
|
+
view.setUint16(0, value, littleEndian);
|
9540
|
+
this.write(buf, byteOffset);
|
9541
|
+
}
|
9542
|
+
getUint32(byteOffset, littleEndian) {
|
9543
|
+
const buf = this.subarray(byteOffset, byteOffset + 4);
|
9544
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9545
|
+
return view.getUint32(0, littleEndian);
|
9546
|
+
}
|
9547
|
+
setUint32(byteOffset, value, littleEndian) {
|
9548
|
+
const buf = alloc$1(4);
|
9549
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9550
|
+
view.setUint32(0, value, littleEndian);
|
9551
|
+
this.write(buf, byteOffset);
|
9552
|
+
}
|
9553
|
+
getBigUint64(byteOffset, littleEndian) {
|
9554
|
+
const buf = this.subarray(byteOffset, byteOffset + 8);
|
9555
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9556
|
+
return view.getBigUint64(0, littleEndian);
|
9557
|
+
}
|
9558
|
+
setBigUint64(byteOffset, value, littleEndian) {
|
9559
|
+
const buf = alloc$1(8);
|
9560
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9561
|
+
view.setBigUint64(0, value, littleEndian);
|
9562
|
+
this.write(buf, byteOffset);
|
9563
|
+
}
|
9564
|
+
getFloat32(byteOffset, littleEndian) {
|
9565
|
+
const buf = this.subarray(byteOffset, byteOffset + 4);
|
9566
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9567
|
+
return view.getFloat32(0, littleEndian);
|
9568
|
+
}
|
9569
|
+
setFloat32(byteOffset, value, littleEndian) {
|
9570
|
+
const buf = alloc$1(4);
|
9571
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9572
|
+
view.setFloat32(0, value, littleEndian);
|
9573
|
+
this.write(buf, byteOffset);
|
9574
|
+
}
|
9575
|
+
getFloat64(byteOffset, littleEndian) {
|
9576
|
+
const buf = this.subarray(byteOffset, byteOffset + 8);
|
9577
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9578
|
+
return view.getFloat64(0, littleEndian);
|
9579
|
+
}
|
9580
|
+
setFloat64(byteOffset, value, littleEndian) {
|
9581
|
+
const buf = alloc$1(8);
|
9582
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
9583
|
+
view.setFloat64(0, value, littleEndian);
|
9584
|
+
this.write(buf, byteOffset);
|
9375
9585
|
}
|
9376
|
-
|
9377
|
-
|
9378
|
-
|
9379
|
-
return new ArrayBuffer(0);
|
9380
|
-
}
|
9381
|
-
if (!Convert.isHex(formatted)) {
|
9382
|
-
throw new TypeError("Argument 'hexString' is not HEX encoded");
|
9586
|
+
equals(other) {
|
9587
|
+
if (other == null) {
|
9588
|
+
return false;
|
9383
9589
|
}
|
9384
|
-
if (
|
9385
|
-
|
9590
|
+
if (!(other instanceof Uint8ArrayList)) {
|
9591
|
+
return false;
|
9386
9592
|
}
|
9387
|
-
|
9388
|
-
|
9389
|
-
const c = formatted.slice(i, i + 2);
|
9390
|
-
res[i / 2] = parseInt(c, 16);
|
9593
|
+
if (other.bufs.length !== this.bufs.length) {
|
9594
|
+
return false;
|
9391
9595
|
}
|
9392
|
-
|
9393
|
-
|
9394
|
-
|
9395
|
-
return Utf16Converter.toString(buffer, littleEndian);
|
9396
|
-
}
|
9397
|
-
static FromUtf16String(text, littleEndian = false) {
|
9398
|
-
return Utf16Converter.fromString(text, littleEndian);
|
9399
|
-
}
|
9400
|
-
static Base64Padding(base64) {
|
9401
|
-
const padCount = 4 - (base64.length % 4);
|
9402
|
-
if (padCount < 4) {
|
9403
|
-
for (let i = 0; i < padCount; i++) {
|
9404
|
-
base64 += "=";
|
9596
|
+
for (let i = 0; i < this.bufs.length; i++) {
|
9597
|
+
if (!equals(this.bufs[i], other.bufs[i])) {
|
9598
|
+
return false;
|
9405
9599
|
}
|
9406
9600
|
}
|
9407
|
-
return
|
9601
|
+
return true;
|
9408
9602
|
}
|
9409
|
-
|
9410
|
-
|
9603
|
+
/**
|
9604
|
+
* Create a Uint8ArrayList from a pre-existing list of Uint8Arrays. Use this
|
9605
|
+
* method if you know the total size of all the Uint8Arrays ahead of time.
|
9606
|
+
*/
|
9607
|
+
static fromUint8Arrays(bufs, length) {
|
9608
|
+
const list = new Uint8ArrayList();
|
9609
|
+
list.bufs = bufs;
|
9610
|
+
if (length == null) {
|
9611
|
+
length = bufs.reduce((acc, curr) => acc + curr.byteLength, 0);
|
9612
|
+
}
|
9613
|
+
list.length = length;
|
9614
|
+
return list;
|
9411
9615
|
}
|
9412
9616
|
}
|
9413
|
-
|
9617
|
+
/*
|
9618
|
+
function indexOf (needle: Uint8Array, haystack: Uint8Array, offset = 0) {
|
9619
|
+
for (let i = offset; i < haystack.byteLength; i++) {
|
9620
|
+
for (let j = 0; j < needle.length; j++) {
|
9621
|
+
if (haystack[i + j] !== needle[j]) {
|
9622
|
+
break
|
9623
|
+
}
|
9414
9624
|
|
9415
|
-
|
9416
|
-
|
9417
|
-
|
9418
|
-
|
9419
|
-
Copyright (c) Peculiar Ventures, LLC
|
9420
|
-
*/
|
9421
|
-
|
9422
|
-
function utilFromBase(inputBuffer, inputBase) {
|
9423
|
-
let result = 0;
|
9424
|
-
if (inputBuffer.length === 1) {
|
9425
|
-
return inputBuffer[0];
|
9426
|
-
}
|
9427
|
-
for (let i = (inputBuffer.length - 1); i >= 0; i--) {
|
9428
|
-
result += inputBuffer[(inputBuffer.length - 1) - i] * Math.pow(2, inputBase * i);
|
9429
|
-
}
|
9430
|
-
return result;
|
9431
|
-
}
|
9432
|
-
function utilToBase(value, base, reserved = (-1)) {
|
9433
|
-
const internalReserved = reserved;
|
9434
|
-
let internalValue = value;
|
9435
|
-
let result = 0;
|
9436
|
-
let biggest = Math.pow(2, base);
|
9437
|
-
for (let i = 1; i < 8; i++) {
|
9438
|
-
if (value < biggest) {
|
9439
|
-
let retBuf;
|
9440
|
-
if (internalReserved < 0) {
|
9441
|
-
retBuf = new ArrayBuffer(i);
|
9442
|
-
result = i;
|
9443
|
-
}
|
9444
|
-
else {
|
9445
|
-
if (internalReserved < i) {
|
9446
|
-
return (new ArrayBuffer(0));
|
9447
|
-
}
|
9448
|
-
retBuf = new ArrayBuffer(internalReserved);
|
9449
|
-
result = internalReserved;
|
9450
|
-
}
|
9451
|
-
const retView = new Uint8Array(retBuf);
|
9452
|
-
for (let j = (i - 1); j >= 0; j--) {
|
9453
|
-
const basis = Math.pow(2, j * base);
|
9454
|
-
retView[result - j - 1] = Math.floor(internalValue / basis);
|
9455
|
-
internalValue -= (retView[result - j - 1]) * basis;
|
9456
|
-
}
|
9457
|
-
return retBuf;
|
9458
|
-
}
|
9459
|
-
biggest *= Math.pow(2, base);
|
9460
|
-
}
|
9461
|
-
return new ArrayBuffer(0);
|
9462
|
-
}
|
9463
|
-
function utilConcatView(...views) {
|
9464
|
-
let outputLength = 0;
|
9465
|
-
let prevLength = 0;
|
9466
|
-
for (const view of views) {
|
9467
|
-
outputLength += view.length;
|
9468
|
-
}
|
9469
|
-
const retBuf = new ArrayBuffer(outputLength);
|
9470
|
-
const retView = new Uint8Array(retBuf);
|
9471
|
-
for (const view of views) {
|
9472
|
-
retView.set(view, prevLength);
|
9473
|
-
prevLength += view.length;
|
9474
|
-
}
|
9475
|
-
return retView;
|
9476
|
-
}
|
9477
|
-
function utilDecodeTC() {
|
9478
|
-
const buf = new Uint8Array(this.valueHex);
|
9479
|
-
if (this.valueHex.byteLength >= 2) {
|
9480
|
-
const condition1 = (buf[0] === 0xFF) && (buf[1] & 0x80);
|
9481
|
-
const condition2 = (buf[0] === 0x00) && ((buf[1] & 0x80) === 0x00);
|
9482
|
-
if (condition1 || condition2) {
|
9483
|
-
this.warnings.push("Needlessly long format");
|
9484
|
-
}
|
9485
|
-
}
|
9486
|
-
const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
9487
|
-
const bigIntView = new Uint8Array(bigIntBuffer);
|
9488
|
-
for (let i = 0; i < this.valueHex.byteLength; i++) {
|
9489
|
-
bigIntView[i] = 0;
|
9490
|
-
}
|
9491
|
-
bigIntView[0] = (buf[0] & 0x80);
|
9492
|
-
const bigInt = utilFromBase(bigIntView, 8);
|
9493
|
-
const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
9494
|
-
const smallIntView = new Uint8Array(smallIntBuffer);
|
9495
|
-
for (let j = 0; j < this.valueHex.byteLength; j++) {
|
9496
|
-
smallIntView[j] = buf[j];
|
9497
|
-
}
|
9498
|
-
smallIntView[0] &= 0x7F;
|
9499
|
-
const smallInt = utilFromBase(smallIntView, 8);
|
9500
|
-
return (smallInt - bigInt);
|
9501
|
-
}
|
9502
|
-
function utilEncodeTC(value) {
|
9503
|
-
const modValue = (value < 0) ? (value * (-1)) : value;
|
9504
|
-
let bigInt = 128;
|
9505
|
-
for (let i = 1; i < 8; i++) {
|
9506
|
-
if (modValue <= bigInt) {
|
9507
|
-
if (value < 0) {
|
9508
|
-
const smallInt = bigInt - modValue;
|
9509
|
-
const retBuf = utilToBase(smallInt, 8, i);
|
9510
|
-
const retView = new Uint8Array(retBuf);
|
9511
|
-
retView[0] |= 0x80;
|
9512
|
-
return retBuf;
|
9513
|
-
}
|
9514
|
-
let retBuf = utilToBase(modValue, 8, i);
|
9515
|
-
let retView = new Uint8Array(retBuf);
|
9516
|
-
if (retView[0] & 0x80) {
|
9517
|
-
const tempBuf = retBuf.slice(0);
|
9518
|
-
const tempView = new Uint8Array(tempBuf);
|
9519
|
-
retBuf = new ArrayBuffer(retBuf.byteLength + 1);
|
9520
|
-
retView = new Uint8Array(retBuf);
|
9521
|
-
for (let k = 0; k < tempBuf.byteLength; k++) {
|
9522
|
-
retView[k + 1] = tempView[k];
|
9523
|
-
}
|
9524
|
-
retView[0] = 0x00;
|
9525
|
-
}
|
9526
|
-
return retBuf;
|
9527
|
-
}
|
9528
|
-
bigInt *= Math.pow(2, 8);
|
9529
|
-
}
|
9530
|
-
return (new ArrayBuffer(0));
|
9531
|
-
}
|
9532
|
-
function isEqualBuffer(inputBuffer1, inputBuffer2) {
|
9533
|
-
if (inputBuffer1.byteLength !== inputBuffer2.byteLength) {
|
9534
|
-
return false;
|
9535
|
-
}
|
9536
|
-
const view1 = new Uint8Array(inputBuffer1);
|
9537
|
-
const view2 = new Uint8Array(inputBuffer2);
|
9538
|
-
for (let i = 0; i < view1.length; i++) {
|
9539
|
-
if (view1[i] !== view2[i]) {
|
9540
|
-
return false;
|
9541
|
-
}
|
9542
|
-
}
|
9543
|
-
return true;
|
9544
|
-
}
|
9545
|
-
function padNumber(inputNumber, fullLength) {
|
9546
|
-
const str = inputNumber.toString(10);
|
9547
|
-
if (fullLength < str.length) {
|
9548
|
-
return "";
|
9549
|
-
}
|
9550
|
-
const dif = fullLength - str.length;
|
9551
|
-
const padding = new Array(dif);
|
9552
|
-
for (let i = 0; i < dif; i++) {
|
9553
|
-
padding[i] = "0";
|
9554
|
-
}
|
9555
|
-
const paddingString = padding.join("");
|
9556
|
-
return paddingString.concat(str);
|
9557
|
-
}
|
9558
|
-
|
9559
|
-
/*!
|
9560
|
-
* Copyright (c) 2014, GMO GlobalSign
|
9561
|
-
* Copyright (c) 2015-2022, Peculiar Ventures
|
9562
|
-
* All rights reserved.
|
9563
|
-
*
|
9564
|
-
* Author 2014-2019, Yury Strozhevsky
|
9565
|
-
*
|
9566
|
-
* Redistribution and use in source and binary forms, with or without modification,
|
9567
|
-
* are permitted provided that the following conditions are met:
|
9568
|
-
*
|
9569
|
-
* * Redistributions of source code must retain the above copyright notice, this
|
9570
|
-
* list of conditions and the following disclaimer.
|
9571
|
-
*
|
9572
|
-
* * Redistributions in binary form must reproduce the above copyright notice, this
|
9573
|
-
* list of conditions and the following disclaimer in the documentation and/or
|
9574
|
-
* other materials provided with the distribution.
|
9575
|
-
*
|
9576
|
-
* * Neither the name of the copyright holder nor the names of its
|
9577
|
-
* contributors may be used to endorse or promote products derived from
|
9578
|
-
* this software without specific prior written permission.
|
9579
|
-
*
|
9580
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
9581
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
9582
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
9583
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
9584
|
-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
9585
|
-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
9586
|
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
9587
|
-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
9588
|
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
9589
|
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
9590
|
-
*
|
9591
|
-
*/
|
9625
|
+
if (j === needle.byteLength -1) {
|
9626
|
+
return i
|
9627
|
+
}
|
9628
|
+
}
|
9592
9629
|
|
9630
|
+
if (haystack.byteLength - i < needle.byteLength) {
|
9631
|
+
break
|
9632
|
+
}
|
9633
|
+
}
|
9593
9634
|
|
9594
|
-
|
9595
|
-
|
9596
|
-
|
9597
|
-
}
|
9598
|
-
}
|
9599
|
-
function concat(buffers) {
|
9600
|
-
let outputLength = 0;
|
9601
|
-
let prevLength = 0;
|
9602
|
-
for (let i = 0; i < buffers.length; i++) {
|
9603
|
-
const buffer = buffers[i];
|
9604
|
-
outputLength += buffer.byteLength;
|
9605
|
-
}
|
9606
|
-
const retView = new Uint8Array(outputLength);
|
9607
|
-
for (let i = 0; i < buffers.length; i++) {
|
9608
|
-
const buffer = buffers[i];
|
9609
|
-
retView.set(new Uint8Array(buffer), prevLength);
|
9610
|
-
prevLength += buffer.byteLength;
|
9611
|
-
}
|
9612
|
-
return retView.buffer;
|
9613
|
-
}
|
9614
|
-
function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
|
9615
|
-
if (!(inputBuffer instanceof Uint8Array)) {
|
9616
|
-
baseBlock.error = "Wrong parameter: inputBuffer must be 'Uint8Array'";
|
9617
|
-
return false;
|
9618
|
-
}
|
9619
|
-
if (!inputBuffer.byteLength) {
|
9620
|
-
baseBlock.error = "Wrong parameter: inputBuffer has zero length";
|
9621
|
-
return false;
|
9622
|
-
}
|
9623
|
-
if (inputOffset < 0) {
|
9624
|
-
baseBlock.error = "Wrong parameter: inputOffset less than zero";
|
9625
|
-
return false;
|
9626
|
-
}
|
9627
|
-
if (inputLength < 0) {
|
9628
|
-
baseBlock.error = "Wrong parameter: inputLength less than zero";
|
9629
|
-
return false;
|
9630
|
-
}
|
9631
|
-
if ((inputBuffer.byteLength - inputOffset - inputLength) < 0) {
|
9632
|
-
baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
|
9633
|
-
return false;
|
9634
|
-
}
|
9635
|
-
return true;
|
9636
|
-
}
|
9637
|
-
|
9638
|
-
class ViewWriter {
|
9639
|
-
constructor() {
|
9640
|
-
this.items = [];
|
9641
|
-
}
|
9642
|
-
write(buf) {
|
9643
|
-
this.items.push(buf);
|
9644
|
-
}
|
9645
|
-
final() {
|
9646
|
-
return concat(this.items);
|
9647
|
-
}
|
9648
|
-
}
|
9649
|
-
|
9650
|
-
const powers2 = [new Uint8Array([1])];
|
9651
|
-
const digitsString = "0123456789";
|
9652
|
-
const EMPTY_STRING = "";
|
9653
|
-
const EMPTY_BUFFER = new ArrayBuffer(0);
|
9654
|
-
const EMPTY_VIEW = new Uint8Array(0);
|
9655
|
-
const END_OF_CONTENT_NAME = "EndOfContent";
|
9656
|
-
const OCTET_STRING_NAME = "OCTET STRING";
|
9657
|
-
const BIT_STRING_NAME = "BIT STRING";
|
9658
|
-
|
9659
|
-
function HexBlock(BaseClass) {
|
9660
|
-
var _a;
|
9661
|
-
return _a = class Some extends BaseClass {
|
9662
|
-
constructor(...args) {
|
9663
|
-
var _a;
|
9664
|
-
super(...args);
|
9665
|
-
const params = args[0] || {};
|
9666
|
-
this.isHexOnly = (_a = params.isHexOnly) !== null && _a !== undefined ? _a : false;
|
9667
|
-
this.valueHexView = params.valueHex ? BufferSourceConverter_1.toUint8Array(params.valueHex) : EMPTY_VIEW;
|
9668
|
-
}
|
9669
|
-
get valueHex() {
|
9670
|
-
return this.valueHexView.slice().buffer;
|
9671
|
-
}
|
9672
|
-
set valueHex(value) {
|
9673
|
-
this.valueHexView = new Uint8Array(value);
|
9674
|
-
}
|
9675
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
9676
|
-
const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
|
9677
|
-
if (!checkBufferParams(this, view, inputOffset, inputLength)) {
|
9678
|
-
return -1;
|
9679
|
-
}
|
9680
|
-
const endLength = inputOffset + inputLength;
|
9681
|
-
this.valueHexView = view.subarray(inputOffset, endLength);
|
9682
|
-
if (!this.valueHexView.length) {
|
9683
|
-
this.warnings.push("Zero buffer length");
|
9684
|
-
return inputOffset;
|
9685
|
-
}
|
9686
|
-
this.blockLength = inputLength;
|
9687
|
-
return endLength;
|
9688
|
-
}
|
9689
|
-
toBER(sizeOnly = false) {
|
9690
|
-
if (!this.isHexOnly) {
|
9691
|
-
this.error = "Flag 'isHexOnly' is not set, abort";
|
9692
|
-
return EMPTY_BUFFER;
|
9693
|
-
}
|
9694
|
-
if (sizeOnly) {
|
9695
|
-
return new ArrayBuffer(this.valueHexView.byteLength);
|
9696
|
-
}
|
9697
|
-
return (this.valueHexView.byteLength === this.valueHexView.buffer.byteLength)
|
9698
|
-
? this.valueHexView.buffer
|
9699
|
-
: this.valueHexView.slice().buffer;
|
9700
|
-
}
|
9701
|
-
toJSON() {
|
9702
|
-
return {
|
9703
|
-
...super.toJSON(),
|
9704
|
-
isHexOnly: this.isHexOnly,
|
9705
|
-
valueHex: Convert_1.ToHex(this.valueHexView),
|
9706
|
-
};
|
9707
|
-
}
|
9708
|
-
},
|
9709
|
-
_a.NAME = "hexBlock",
|
9710
|
-
_a;
|
9711
|
-
}
|
9712
|
-
|
9713
|
-
class LocalBaseBlock {
|
9714
|
-
constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW, } = {}) {
|
9715
|
-
this.blockLength = blockLength;
|
9716
|
-
this.error = error;
|
9717
|
-
this.warnings = warnings;
|
9718
|
-
this.valueBeforeDecodeView = BufferSourceConverter_1.toUint8Array(valueBeforeDecode);
|
9719
|
-
}
|
9720
|
-
static blockName() {
|
9721
|
-
return this.NAME;
|
9722
|
-
}
|
9723
|
-
get valueBeforeDecode() {
|
9724
|
-
return this.valueBeforeDecodeView.slice().buffer;
|
9725
|
-
}
|
9726
|
-
set valueBeforeDecode(value) {
|
9727
|
-
this.valueBeforeDecodeView = new Uint8Array(value);
|
9728
|
-
}
|
9729
|
-
toJSON() {
|
9730
|
-
return {
|
9731
|
-
blockName: this.constructor.NAME,
|
9732
|
-
blockLength: this.blockLength,
|
9733
|
-
error: this.error,
|
9734
|
-
warnings: this.warnings,
|
9735
|
-
valueBeforeDecode: Convert_1.ToHex(this.valueBeforeDecodeView),
|
9736
|
-
};
|
9737
|
-
}
|
9738
|
-
}
|
9739
|
-
LocalBaseBlock.NAME = "baseBlock";
|
9740
|
-
|
9741
|
-
class ValueBlock extends LocalBaseBlock {
|
9742
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
9743
|
-
throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
|
9744
|
-
}
|
9745
|
-
toBER(sizeOnly, writer) {
|
9746
|
-
throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
|
9747
|
-
}
|
9748
|
-
}
|
9749
|
-
ValueBlock.NAME = "valueBlock";
|
9750
|
-
|
9751
|
-
class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
|
9752
|
-
constructor({ idBlock = {}, } = {}) {
|
9753
|
-
var _a, _b, _c, _d;
|
9754
|
-
super();
|
9755
|
-
if (idBlock) {
|
9756
|
-
this.isHexOnly = (_a = idBlock.isHexOnly) !== null && _a !== undefined ? _a : false;
|
9757
|
-
this.valueHexView = idBlock.valueHex ? BufferSourceConverter_1.toUint8Array(idBlock.valueHex) : EMPTY_VIEW;
|
9758
|
-
this.tagClass = (_b = idBlock.tagClass) !== null && _b !== undefined ? _b : -1;
|
9759
|
-
this.tagNumber = (_c = idBlock.tagNumber) !== null && _c !== undefined ? _c : -1;
|
9760
|
-
this.isConstructed = (_d = idBlock.isConstructed) !== null && _d !== undefined ? _d : false;
|
9761
|
-
}
|
9762
|
-
else {
|
9763
|
-
this.tagClass = -1;
|
9764
|
-
this.tagNumber = -1;
|
9765
|
-
this.isConstructed = false;
|
9766
|
-
}
|
9767
|
-
}
|
9768
|
-
toBER(sizeOnly = false) {
|
9769
|
-
let firstOctet = 0;
|
9770
|
-
switch (this.tagClass) {
|
9771
|
-
case 1:
|
9772
|
-
firstOctet |= 0x00;
|
9773
|
-
break;
|
9774
|
-
case 2:
|
9775
|
-
firstOctet |= 0x40;
|
9776
|
-
break;
|
9777
|
-
case 3:
|
9778
|
-
firstOctet |= 0x80;
|
9779
|
-
break;
|
9780
|
-
case 4:
|
9781
|
-
firstOctet |= 0xC0;
|
9782
|
-
break;
|
9783
|
-
default:
|
9784
|
-
this.error = "Unknown tag class";
|
9785
|
-
return EMPTY_BUFFER;
|
9786
|
-
}
|
9787
|
-
if (this.isConstructed)
|
9788
|
-
firstOctet |= 0x20;
|
9789
|
-
if (this.tagNumber < 31 && !this.isHexOnly) {
|
9790
|
-
const retView = new Uint8Array(1);
|
9791
|
-
if (!sizeOnly) {
|
9792
|
-
let number = this.tagNumber;
|
9793
|
-
number &= 0x1F;
|
9794
|
-
firstOctet |= number;
|
9795
|
-
retView[0] = firstOctet;
|
9796
|
-
}
|
9797
|
-
return retView.buffer;
|
9798
|
-
}
|
9799
|
-
if (!this.isHexOnly) {
|
9800
|
-
const encodedBuf = utilToBase(this.tagNumber, 7);
|
9801
|
-
const encodedView = new Uint8Array(encodedBuf);
|
9802
|
-
const size = encodedBuf.byteLength;
|
9803
|
-
const retView = new Uint8Array(size + 1);
|
9804
|
-
retView[0] = (firstOctet | 0x1F);
|
9805
|
-
if (!sizeOnly) {
|
9806
|
-
for (let i = 0; i < (size - 1); i++)
|
9807
|
-
retView[i + 1] = encodedView[i] | 0x80;
|
9808
|
-
retView[size] = encodedView[size - 1];
|
9809
|
-
}
|
9810
|
-
return retView.buffer;
|
9811
|
-
}
|
9812
|
-
const retView = new Uint8Array(this.valueHexView.byteLength + 1);
|
9813
|
-
retView[0] = (firstOctet | 0x1F);
|
9814
|
-
if (!sizeOnly) {
|
9815
|
-
const curView = this.valueHexView;
|
9816
|
-
for (let i = 0; i < (curView.length - 1); i++)
|
9817
|
-
retView[i + 1] = curView[i] | 0x80;
|
9818
|
-
retView[this.valueHexView.byteLength] = curView[curView.length - 1];
|
9819
|
-
}
|
9820
|
-
return retView.buffer;
|
9821
|
-
}
|
9822
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
9823
|
-
const inputView = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
9824
|
-
if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
|
9825
|
-
return -1;
|
9826
|
-
}
|
9827
|
-
const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
|
9828
|
-
if (intBuffer.length === 0) {
|
9829
|
-
this.error = "Zero buffer length";
|
9830
|
-
return -1;
|
9831
|
-
}
|
9832
|
-
const tagClassMask = intBuffer[0] & 0xC0;
|
9833
|
-
switch (tagClassMask) {
|
9834
|
-
case 0x00:
|
9835
|
-
this.tagClass = (1);
|
9836
|
-
break;
|
9837
|
-
case 0x40:
|
9838
|
-
this.tagClass = (2);
|
9839
|
-
break;
|
9840
|
-
case 0x80:
|
9841
|
-
this.tagClass = (3);
|
9842
|
-
break;
|
9843
|
-
case 0xC0:
|
9844
|
-
this.tagClass = (4);
|
9845
|
-
break;
|
9846
|
-
default:
|
9847
|
-
this.error = "Unknown tag class";
|
9848
|
-
return -1;
|
9849
|
-
}
|
9850
|
-
this.isConstructed = (intBuffer[0] & 0x20) === 0x20;
|
9851
|
-
this.isHexOnly = false;
|
9852
|
-
const tagNumberMask = intBuffer[0] & 0x1F;
|
9853
|
-
if (tagNumberMask !== 0x1F) {
|
9854
|
-
this.tagNumber = (tagNumberMask);
|
9855
|
-
this.blockLength = 1;
|
9856
|
-
}
|
9857
|
-
else {
|
9858
|
-
let count = 1;
|
9859
|
-
let intTagNumberBuffer = this.valueHexView = new Uint8Array(255);
|
9860
|
-
let tagNumberBufferMaxLength = 255;
|
9861
|
-
while (intBuffer[count] & 0x80) {
|
9862
|
-
intTagNumberBuffer[count - 1] = intBuffer[count] & 0x7F;
|
9863
|
-
count++;
|
9864
|
-
if (count >= intBuffer.length) {
|
9865
|
-
this.error = "End of input reached before message was fully decoded";
|
9866
|
-
return -1;
|
9867
|
-
}
|
9868
|
-
if (count === tagNumberBufferMaxLength) {
|
9869
|
-
tagNumberBufferMaxLength += 255;
|
9870
|
-
const tempBufferView = new Uint8Array(tagNumberBufferMaxLength);
|
9871
|
-
for (let i = 0; i < intTagNumberBuffer.length; i++)
|
9872
|
-
tempBufferView[i] = intTagNumberBuffer[i];
|
9873
|
-
intTagNumberBuffer = this.valueHexView = new Uint8Array(tagNumberBufferMaxLength);
|
9874
|
-
}
|
9875
|
-
}
|
9876
|
-
this.blockLength = (count + 1);
|
9877
|
-
intTagNumberBuffer[count - 1] = intBuffer[count] & 0x7F;
|
9878
|
-
const tempBufferView = new Uint8Array(count);
|
9879
|
-
for (let i = 0; i < count; i++)
|
9880
|
-
tempBufferView[i] = intTagNumberBuffer[i];
|
9881
|
-
intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
|
9882
|
-
intTagNumberBuffer.set(tempBufferView);
|
9883
|
-
if (this.blockLength <= 9)
|
9884
|
-
this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
|
9885
|
-
else {
|
9886
|
-
this.isHexOnly = true;
|
9887
|
-
this.warnings.push("Tag too long, represented as hex-coded");
|
9888
|
-
}
|
9889
|
-
}
|
9890
|
-
if (((this.tagClass === 1)) &&
|
9891
|
-
(this.isConstructed)) {
|
9892
|
-
switch (this.tagNumber) {
|
9893
|
-
case 1:
|
9894
|
-
case 2:
|
9895
|
-
case 5:
|
9896
|
-
case 6:
|
9897
|
-
case 9:
|
9898
|
-
case 13:
|
9899
|
-
case 14:
|
9900
|
-
case 23:
|
9901
|
-
case 24:
|
9902
|
-
case 31:
|
9903
|
-
case 32:
|
9904
|
-
case 33:
|
9905
|
-
case 34:
|
9906
|
-
this.error = "Constructed encoding used for primitive type";
|
9907
|
-
return -1;
|
9908
|
-
}
|
9909
|
-
}
|
9910
|
-
return (inputOffset + this.blockLength);
|
9911
|
-
}
|
9912
|
-
toJSON() {
|
9913
|
-
return {
|
9914
|
-
...super.toJSON(),
|
9915
|
-
tagClass: this.tagClass,
|
9916
|
-
tagNumber: this.tagNumber,
|
9917
|
-
isConstructed: this.isConstructed,
|
9918
|
-
};
|
9919
|
-
}
|
9920
|
-
}
|
9921
|
-
LocalIdentificationBlock.NAME = "identificationBlock";
|
9922
|
-
|
9923
|
-
class LocalLengthBlock extends LocalBaseBlock {
|
9924
|
-
constructor({ lenBlock = {}, } = {}) {
|
9925
|
-
var _a, _b, _c;
|
9926
|
-
super();
|
9927
|
-
this.isIndefiniteForm = (_a = lenBlock.isIndefiniteForm) !== null && _a !== undefined ? _a : false;
|
9928
|
-
this.longFormUsed = (_b = lenBlock.longFormUsed) !== null && _b !== undefined ? _b : false;
|
9929
|
-
this.length = (_c = lenBlock.length) !== null && _c !== undefined ? _c : 0;
|
9930
|
-
}
|
9931
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
9932
|
-
const view = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
9933
|
-
if (!checkBufferParams(this, view, inputOffset, inputLength)) {
|
9934
|
-
return -1;
|
9935
|
-
}
|
9936
|
-
const intBuffer = view.subarray(inputOffset, inputOffset + inputLength);
|
9937
|
-
if (intBuffer.length === 0) {
|
9938
|
-
this.error = "Zero buffer length";
|
9939
|
-
return -1;
|
9940
|
-
}
|
9941
|
-
if (intBuffer[0] === 0xFF) {
|
9942
|
-
this.error = "Length block 0xFF is reserved by standard";
|
9943
|
-
return -1;
|
9944
|
-
}
|
9945
|
-
this.isIndefiniteForm = intBuffer[0] === 0x80;
|
9946
|
-
if (this.isIndefiniteForm) {
|
9947
|
-
this.blockLength = 1;
|
9948
|
-
return (inputOffset + this.blockLength);
|
9949
|
-
}
|
9950
|
-
this.longFormUsed = !!(intBuffer[0] & 0x80);
|
9951
|
-
if (this.longFormUsed === false) {
|
9952
|
-
this.length = (intBuffer[0]);
|
9953
|
-
this.blockLength = 1;
|
9954
|
-
return (inputOffset + this.blockLength);
|
9955
|
-
}
|
9956
|
-
const count = intBuffer[0] & 0x7F;
|
9957
|
-
if (count > 8) {
|
9958
|
-
this.error = "Too big integer";
|
9959
|
-
return -1;
|
9960
|
-
}
|
9961
|
-
if ((count + 1) > intBuffer.length) {
|
9962
|
-
this.error = "End of input reached before message was fully decoded";
|
9963
|
-
return -1;
|
9964
|
-
}
|
9965
|
-
const lenOffset = inputOffset + 1;
|
9966
|
-
const lengthBufferView = view.subarray(lenOffset, lenOffset + count);
|
9967
|
-
if (lengthBufferView[count - 1] === 0x00)
|
9968
|
-
this.warnings.push("Needlessly long encoded length");
|
9969
|
-
this.length = utilFromBase(lengthBufferView, 8);
|
9970
|
-
if (this.longFormUsed && (this.length <= 127))
|
9971
|
-
this.warnings.push("Unnecessary usage of long length form");
|
9972
|
-
this.blockLength = count + 1;
|
9973
|
-
return (inputOffset + this.blockLength);
|
9974
|
-
}
|
9975
|
-
toBER(sizeOnly = false) {
|
9976
|
-
let retBuf;
|
9977
|
-
let retView;
|
9978
|
-
if (this.length > 127)
|
9979
|
-
this.longFormUsed = true;
|
9980
|
-
if (this.isIndefiniteForm) {
|
9981
|
-
retBuf = new ArrayBuffer(1);
|
9982
|
-
if (sizeOnly === false) {
|
9983
|
-
retView = new Uint8Array(retBuf);
|
9984
|
-
retView[0] = 0x80;
|
9985
|
-
}
|
9986
|
-
return retBuf;
|
9987
|
-
}
|
9988
|
-
if (this.longFormUsed) {
|
9989
|
-
const encodedBuf = utilToBase(this.length, 8);
|
9990
|
-
if (encodedBuf.byteLength > 127) {
|
9991
|
-
this.error = "Too big length";
|
9992
|
-
return (EMPTY_BUFFER);
|
9993
|
-
}
|
9994
|
-
retBuf = new ArrayBuffer(encodedBuf.byteLength + 1);
|
9995
|
-
if (sizeOnly)
|
9996
|
-
return retBuf;
|
9997
|
-
const encodedView = new Uint8Array(encodedBuf);
|
9998
|
-
retView = new Uint8Array(retBuf);
|
9999
|
-
retView[0] = encodedBuf.byteLength | 0x80;
|
10000
|
-
for (let i = 0; i < encodedBuf.byteLength; i++)
|
10001
|
-
retView[i + 1] = encodedView[i];
|
10002
|
-
return retBuf;
|
10003
|
-
}
|
10004
|
-
retBuf = new ArrayBuffer(1);
|
10005
|
-
if (sizeOnly === false) {
|
10006
|
-
retView = new Uint8Array(retBuf);
|
10007
|
-
retView[0] = this.length;
|
10008
|
-
}
|
10009
|
-
return retBuf;
|
10010
|
-
}
|
10011
|
-
toJSON() {
|
10012
|
-
return {
|
10013
|
-
...super.toJSON(),
|
10014
|
-
isIndefiniteForm: this.isIndefiniteForm,
|
10015
|
-
longFormUsed: this.longFormUsed,
|
10016
|
-
length: this.length,
|
10017
|
-
};
|
10018
|
-
}
|
10019
|
-
}
|
10020
|
-
LocalLengthBlock.NAME = "lengthBlock";
|
10021
|
-
|
10022
|
-
const typeStore = {};
|
10023
|
-
|
10024
|
-
class BaseBlock extends LocalBaseBlock {
|
10025
|
-
constructor({ name = EMPTY_STRING, optional = false, primitiveSchema, ...parameters } = {}, valueBlockType) {
|
10026
|
-
super(parameters);
|
10027
|
-
this.name = name;
|
10028
|
-
this.optional = optional;
|
10029
|
-
if (primitiveSchema) {
|
10030
|
-
this.primitiveSchema = primitiveSchema;
|
10031
|
-
}
|
10032
|
-
this.idBlock = new LocalIdentificationBlock(parameters);
|
10033
|
-
this.lenBlock = new LocalLengthBlock(parameters);
|
10034
|
-
this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
|
10035
|
-
}
|
10036
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10037
|
-
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, (this.lenBlock.isIndefiniteForm) ? inputLength : this.lenBlock.length);
|
10038
|
-
if (resultOffset === -1) {
|
10039
|
-
this.error = this.valueBlock.error;
|
10040
|
-
return resultOffset;
|
10041
|
-
}
|
10042
|
-
if (!this.idBlock.error.length)
|
10043
|
-
this.blockLength += this.idBlock.blockLength;
|
10044
|
-
if (!this.lenBlock.error.length)
|
10045
|
-
this.blockLength += this.lenBlock.blockLength;
|
10046
|
-
if (!this.valueBlock.error.length)
|
10047
|
-
this.blockLength += this.valueBlock.blockLength;
|
10048
|
-
return resultOffset;
|
10049
|
-
}
|
10050
|
-
toBER(sizeOnly, writer) {
|
10051
|
-
const _writer = writer || new ViewWriter();
|
10052
|
-
if (!writer) {
|
10053
|
-
prepareIndefiniteForm(this);
|
10054
|
-
}
|
10055
|
-
const idBlockBuf = this.idBlock.toBER(sizeOnly);
|
10056
|
-
_writer.write(idBlockBuf);
|
10057
|
-
if (this.lenBlock.isIndefiniteForm) {
|
10058
|
-
_writer.write(new Uint8Array([0x80]).buffer);
|
10059
|
-
this.valueBlock.toBER(sizeOnly, _writer);
|
10060
|
-
_writer.write(new ArrayBuffer(2));
|
10061
|
-
}
|
10062
|
-
else {
|
10063
|
-
const valueBlockBuf = this.valueBlock.toBER(sizeOnly);
|
10064
|
-
this.lenBlock.length = valueBlockBuf.byteLength;
|
10065
|
-
const lenBlockBuf = this.lenBlock.toBER(sizeOnly);
|
10066
|
-
_writer.write(lenBlockBuf);
|
10067
|
-
_writer.write(valueBlockBuf);
|
10068
|
-
}
|
10069
|
-
if (!writer) {
|
10070
|
-
return _writer.final();
|
10071
|
-
}
|
10072
|
-
return EMPTY_BUFFER;
|
10073
|
-
}
|
10074
|
-
toJSON() {
|
10075
|
-
const object = {
|
10076
|
-
...super.toJSON(),
|
10077
|
-
idBlock: this.idBlock.toJSON(),
|
10078
|
-
lenBlock: this.lenBlock.toJSON(),
|
10079
|
-
valueBlock: this.valueBlock.toJSON(),
|
10080
|
-
name: this.name,
|
10081
|
-
optional: this.optional,
|
10082
|
-
};
|
10083
|
-
if (this.primitiveSchema)
|
10084
|
-
object.primitiveSchema = this.primitiveSchema.toJSON();
|
10085
|
-
return object;
|
10086
|
-
}
|
10087
|
-
toString(encoding = "ascii") {
|
10088
|
-
if (encoding === "ascii") {
|
10089
|
-
return this.onAsciiEncoding();
|
10090
|
-
}
|
10091
|
-
return Convert_1.ToHex(this.toBER());
|
10092
|
-
}
|
10093
|
-
onAsciiEncoding() {
|
10094
|
-
return `${this.constructor.NAME} : ${Convert_1.ToHex(this.valueBlock.valueBeforeDecodeView)}`;
|
10095
|
-
}
|
10096
|
-
isEqual(other) {
|
10097
|
-
if (this === other) {
|
10098
|
-
return true;
|
10099
|
-
}
|
10100
|
-
if (!(other instanceof this.constructor)) {
|
10101
|
-
return false;
|
10102
|
-
}
|
10103
|
-
const thisRaw = this.toBER();
|
10104
|
-
const otherRaw = other.toBER();
|
10105
|
-
return isEqualBuffer(thisRaw, otherRaw);
|
10106
|
-
}
|
10107
|
-
}
|
10108
|
-
BaseBlock.NAME = "BaseBlock";
|
10109
|
-
function prepareIndefiniteForm(baseBlock) {
|
10110
|
-
if (baseBlock instanceof typeStore.Constructed) {
|
10111
|
-
for (const value of baseBlock.valueBlock.value) {
|
10112
|
-
if (prepareIndefiniteForm(value)) {
|
10113
|
-
baseBlock.lenBlock.isIndefiniteForm = true;
|
10114
|
-
}
|
10115
|
-
}
|
10116
|
-
}
|
10117
|
-
return !!baseBlock.lenBlock.isIndefiniteForm;
|
10118
|
-
}
|
10119
|
-
|
10120
|
-
class BaseStringBlock extends BaseBlock {
|
10121
|
-
constructor({ value = EMPTY_STRING, ...parameters } = {}, stringValueBlockType) {
|
10122
|
-
super(parameters, stringValueBlockType);
|
10123
|
-
if (value) {
|
10124
|
-
this.fromString(value);
|
10125
|
-
}
|
10126
|
-
}
|
10127
|
-
getValue() {
|
10128
|
-
return this.valueBlock.value;
|
10129
|
-
}
|
10130
|
-
setValue(value) {
|
10131
|
-
this.valueBlock.value = value;
|
10132
|
-
}
|
10133
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10134
|
-
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, (this.lenBlock.isIndefiniteForm) ? inputLength : this.lenBlock.length);
|
10135
|
-
if (resultOffset === -1) {
|
10136
|
-
this.error = this.valueBlock.error;
|
10137
|
-
return resultOffset;
|
10138
|
-
}
|
10139
|
-
this.fromBuffer(this.valueBlock.valueHexView);
|
10140
|
-
if (!this.idBlock.error.length)
|
10141
|
-
this.blockLength += this.idBlock.blockLength;
|
10142
|
-
if (!this.lenBlock.error.length)
|
10143
|
-
this.blockLength += this.lenBlock.blockLength;
|
10144
|
-
if (!this.valueBlock.error.length)
|
10145
|
-
this.blockLength += this.valueBlock.blockLength;
|
10146
|
-
return resultOffset;
|
10147
|
-
}
|
10148
|
-
onAsciiEncoding() {
|
10149
|
-
return `${this.constructor.NAME} : '${this.valueBlock.value}'`;
|
10150
|
-
}
|
10151
|
-
}
|
10152
|
-
BaseStringBlock.NAME = "BaseStringBlock";
|
10153
|
-
|
10154
|
-
class LocalPrimitiveValueBlock extends HexBlock(ValueBlock) {
|
10155
|
-
constructor({ isHexOnly = true, ...parameters } = {}) {
|
10156
|
-
super(parameters);
|
10157
|
-
this.isHexOnly = isHexOnly;
|
10158
|
-
}
|
10159
|
-
}
|
10160
|
-
LocalPrimitiveValueBlock.NAME = "PrimitiveValueBlock";
|
10161
|
-
|
10162
|
-
var _a$w;
|
10163
|
-
class Primitive extends BaseBlock {
|
10164
|
-
constructor(parameters = {}) {
|
10165
|
-
super(parameters, LocalPrimitiveValueBlock);
|
10166
|
-
this.idBlock.isConstructed = false;
|
10167
|
-
}
|
10168
|
-
}
|
10169
|
-
_a$w = Primitive;
|
10170
|
-
(() => {
|
10171
|
-
typeStore.Primitive = _a$w;
|
10172
|
-
})();
|
10173
|
-
Primitive.NAME = "PRIMITIVE";
|
10174
|
-
|
10175
|
-
function localChangeType(inputObject, newType) {
|
10176
|
-
if (inputObject instanceof newType) {
|
10177
|
-
return inputObject;
|
10178
|
-
}
|
10179
|
-
const newObject = new newType();
|
10180
|
-
newObject.idBlock = inputObject.idBlock;
|
10181
|
-
newObject.lenBlock = inputObject.lenBlock;
|
10182
|
-
newObject.warnings = inputObject.warnings;
|
10183
|
-
newObject.valueBeforeDecodeView = inputObject.valueBeforeDecodeView;
|
10184
|
-
return newObject;
|
10185
|
-
}
|
10186
|
-
function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length) {
|
10187
|
-
const incomingOffset = inputOffset;
|
10188
|
-
let returnObject = new BaseBlock({}, ValueBlock);
|
10189
|
-
const baseBlock = new LocalBaseBlock();
|
10190
|
-
if (!checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength)) {
|
10191
|
-
returnObject.error = baseBlock.error;
|
10192
|
-
return {
|
10193
|
-
offset: -1,
|
10194
|
-
result: returnObject
|
10195
|
-
};
|
10196
|
-
}
|
10197
|
-
const intBuffer = inputBuffer.subarray(inputOffset, inputOffset + inputLength);
|
10198
|
-
if (!intBuffer.length) {
|
10199
|
-
returnObject.error = "Zero buffer length";
|
10200
|
-
return {
|
10201
|
-
offset: -1,
|
10202
|
-
result: returnObject
|
10203
|
-
};
|
10204
|
-
}
|
10205
|
-
let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
|
10206
|
-
if (returnObject.idBlock.warnings.length) {
|
10207
|
-
returnObject.warnings.concat(returnObject.idBlock.warnings);
|
10208
|
-
}
|
10209
|
-
if (resultOffset === -1) {
|
10210
|
-
returnObject.error = returnObject.idBlock.error;
|
10211
|
-
return {
|
10212
|
-
offset: -1,
|
10213
|
-
result: returnObject
|
10214
|
-
};
|
10215
|
-
}
|
10216
|
-
inputOffset = resultOffset;
|
10217
|
-
inputLength -= returnObject.idBlock.blockLength;
|
10218
|
-
resultOffset = returnObject.lenBlock.fromBER(inputBuffer, inputOffset, inputLength);
|
10219
|
-
if (returnObject.lenBlock.warnings.length) {
|
10220
|
-
returnObject.warnings.concat(returnObject.lenBlock.warnings);
|
10221
|
-
}
|
10222
|
-
if (resultOffset === -1) {
|
10223
|
-
returnObject.error = returnObject.lenBlock.error;
|
10224
|
-
return {
|
10225
|
-
offset: -1,
|
10226
|
-
result: returnObject
|
10227
|
-
};
|
10228
|
-
}
|
10229
|
-
inputOffset = resultOffset;
|
10230
|
-
inputLength -= returnObject.lenBlock.blockLength;
|
10231
|
-
if (!returnObject.idBlock.isConstructed &&
|
10232
|
-
returnObject.lenBlock.isIndefiniteForm) {
|
10233
|
-
returnObject.error = "Indefinite length form used for primitive encoding form";
|
10234
|
-
return {
|
10235
|
-
offset: -1,
|
10236
|
-
result: returnObject
|
10237
|
-
};
|
10238
|
-
}
|
10239
|
-
let newASN1Type = BaseBlock;
|
10240
|
-
switch (returnObject.idBlock.tagClass) {
|
10241
|
-
case 1:
|
10242
|
-
if ((returnObject.idBlock.tagNumber >= 37) &&
|
10243
|
-
(returnObject.idBlock.isHexOnly === false)) {
|
10244
|
-
returnObject.error = "UNIVERSAL 37 and upper tags are reserved by ASN.1 standard";
|
10245
|
-
return {
|
10246
|
-
offset: -1,
|
10247
|
-
result: returnObject
|
10248
|
-
};
|
10249
|
-
}
|
10250
|
-
switch (returnObject.idBlock.tagNumber) {
|
10251
|
-
case 0:
|
10252
|
-
if ((returnObject.idBlock.isConstructed) &&
|
10253
|
-
(returnObject.lenBlock.length > 0)) {
|
10254
|
-
returnObject.error = "Type [UNIVERSAL 0] is reserved";
|
10255
|
-
return {
|
10256
|
-
offset: -1,
|
10257
|
-
result: returnObject
|
10258
|
-
};
|
10259
|
-
}
|
10260
|
-
newASN1Type = typeStore.EndOfContent;
|
10261
|
-
break;
|
10262
|
-
case 1:
|
10263
|
-
newASN1Type = typeStore.Boolean;
|
10264
|
-
break;
|
10265
|
-
case 2:
|
10266
|
-
newASN1Type = typeStore.Integer;
|
10267
|
-
break;
|
10268
|
-
case 3:
|
10269
|
-
newASN1Type = typeStore.BitString;
|
10270
|
-
break;
|
10271
|
-
case 4:
|
10272
|
-
newASN1Type = typeStore.OctetString;
|
10273
|
-
break;
|
10274
|
-
case 5:
|
10275
|
-
newASN1Type = typeStore.Null;
|
10276
|
-
break;
|
10277
|
-
case 6:
|
10278
|
-
newASN1Type = typeStore.ObjectIdentifier;
|
10279
|
-
break;
|
10280
|
-
case 10:
|
10281
|
-
newASN1Type = typeStore.Enumerated;
|
10282
|
-
break;
|
10283
|
-
case 12:
|
10284
|
-
newASN1Type = typeStore.Utf8String;
|
10285
|
-
break;
|
10286
|
-
case 13:
|
10287
|
-
newASN1Type = typeStore.RelativeObjectIdentifier;
|
10288
|
-
break;
|
10289
|
-
case 14:
|
10290
|
-
newASN1Type = typeStore.TIME;
|
10291
|
-
break;
|
10292
|
-
case 15:
|
10293
|
-
returnObject.error = "[UNIVERSAL 15] is reserved by ASN.1 standard";
|
10294
|
-
return {
|
10295
|
-
offset: -1,
|
10296
|
-
result: returnObject
|
10297
|
-
};
|
10298
|
-
case 16:
|
10299
|
-
newASN1Type = typeStore.Sequence;
|
10300
|
-
break;
|
10301
|
-
case 17:
|
10302
|
-
newASN1Type = typeStore.Set;
|
10303
|
-
break;
|
10304
|
-
case 18:
|
10305
|
-
newASN1Type = typeStore.NumericString;
|
10306
|
-
break;
|
10307
|
-
case 19:
|
10308
|
-
newASN1Type = typeStore.PrintableString;
|
10309
|
-
break;
|
10310
|
-
case 20:
|
10311
|
-
newASN1Type = typeStore.TeletexString;
|
10312
|
-
break;
|
10313
|
-
case 21:
|
10314
|
-
newASN1Type = typeStore.VideotexString;
|
10315
|
-
break;
|
10316
|
-
case 22:
|
10317
|
-
newASN1Type = typeStore.IA5String;
|
10318
|
-
break;
|
10319
|
-
case 23:
|
10320
|
-
newASN1Type = typeStore.UTCTime;
|
10321
|
-
break;
|
10322
|
-
case 24:
|
10323
|
-
newASN1Type = typeStore.GeneralizedTime;
|
10324
|
-
break;
|
10325
|
-
case 25:
|
10326
|
-
newASN1Type = typeStore.GraphicString;
|
10327
|
-
break;
|
10328
|
-
case 26:
|
10329
|
-
newASN1Type = typeStore.VisibleString;
|
10330
|
-
break;
|
10331
|
-
case 27:
|
10332
|
-
newASN1Type = typeStore.GeneralString;
|
10333
|
-
break;
|
10334
|
-
case 28:
|
10335
|
-
newASN1Type = typeStore.UniversalString;
|
10336
|
-
break;
|
10337
|
-
case 29:
|
10338
|
-
newASN1Type = typeStore.CharacterString;
|
10339
|
-
break;
|
10340
|
-
case 30:
|
10341
|
-
newASN1Type = typeStore.BmpString;
|
10342
|
-
break;
|
10343
|
-
case 31:
|
10344
|
-
newASN1Type = typeStore.DATE;
|
10345
|
-
break;
|
10346
|
-
case 32:
|
10347
|
-
newASN1Type = typeStore.TimeOfDay;
|
10348
|
-
break;
|
10349
|
-
case 33:
|
10350
|
-
newASN1Type = typeStore.DateTime;
|
10351
|
-
break;
|
10352
|
-
case 34:
|
10353
|
-
newASN1Type = typeStore.Duration;
|
10354
|
-
break;
|
10355
|
-
default: {
|
10356
|
-
const newObject = returnObject.idBlock.isConstructed
|
10357
|
-
? new typeStore.Constructed()
|
10358
|
-
: new typeStore.Primitive();
|
10359
|
-
newObject.idBlock = returnObject.idBlock;
|
10360
|
-
newObject.lenBlock = returnObject.lenBlock;
|
10361
|
-
newObject.warnings = returnObject.warnings;
|
10362
|
-
returnObject = newObject;
|
10363
|
-
}
|
10364
|
-
}
|
10365
|
-
break;
|
10366
|
-
case 2:
|
10367
|
-
case 3:
|
10368
|
-
case 4:
|
10369
|
-
default: {
|
10370
|
-
newASN1Type = returnObject.idBlock.isConstructed
|
10371
|
-
? typeStore.Constructed
|
10372
|
-
: typeStore.Primitive;
|
10373
|
-
}
|
10374
|
-
}
|
10375
|
-
returnObject = localChangeType(returnObject, newASN1Type);
|
10376
|
-
resultOffset = returnObject.fromBER(inputBuffer, inputOffset, returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length);
|
10377
|
-
returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
|
10378
|
-
return {
|
10379
|
-
offset: resultOffset,
|
10380
|
-
result: returnObject
|
10381
|
-
};
|
10382
|
-
}
|
10383
|
-
function fromBER(inputBuffer) {
|
10384
|
-
if (!inputBuffer.byteLength) {
|
10385
|
-
const result = new BaseBlock({}, ValueBlock);
|
10386
|
-
result.error = "Input buffer has zero length";
|
10387
|
-
return {
|
10388
|
-
offset: -1,
|
10389
|
-
result
|
10390
|
-
};
|
10391
|
-
}
|
10392
|
-
return localFromBER(BufferSourceConverter_1.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength);
|
10393
|
-
}
|
10394
|
-
|
10395
|
-
function checkLen(indefiniteLength, length) {
|
10396
|
-
if (indefiniteLength) {
|
10397
|
-
return 1;
|
10398
|
-
}
|
10399
|
-
return length;
|
10400
|
-
}
|
10401
|
-
class LocalConstructedValueBlock extends ValueBlock {
|
10402
|
-
constructor({ value = [], isIndefiniteForm = false, ...parameters } = {}) {
|
10403
|
-
super(parameters);
|
10404
|
-
this.value = value;
|
10405
|
-
this.isIndefiniteForm = isIndefiniteForm;
|
10406
|
-
}
|
10407
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10408
|
-
const view = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
10409
|
-
if (!checkBufferParams(this, view, inputOffset, inputLength)) {
|
10410
|
-
return -1;
|
10411
|
-
}
|
10412
|
-
this.valueBeforeDecodeView = view.subarray(inputOffset, inputOffset + inputLength);
|
10413
|
-
if (this.valueBeforeDecodeView.length === 0) {
|
10414
|
-
this.warnings.push("Zero buffer length");
|
10415
|
-
return inputOffset;
|
10416
|
-
}
|
10417
|
-
let currentOffset = inputOffset;
|
10418
|
-
while (checkLen(this.isIndefiniteForm, inputLength) > 0) {
|
10419
|
-
const returnObject = localFromBER(view, currentOffset, inputLength);
|
10420
|
-
if (returnObject.offset === -1) {
|
10421
|
-
this.error = returnObject.result.error;
|
10422
|
-
this.warnings.concat(returnObject.result.warnings);
|
10423
|
-
return -1;
|
10424
|
-
}
|
10425
|
-
currentOffset = returnObject.offset;
|
10426
|
-
this.blockLength += returnObject.result.blockLength;
|
10427
|
-
inputLength -= returnObject.result.blockLength;
|
10428
|
-
this.value.push(returnObject.result);
|
10429
|
-
if (this.isIndefiniteForm && returnObject.result.constructor.NAME === END_OF_CONTENT_NAME) {
|
10430
|
-
break;
|
10431
|
-
}
|
10432
|
-
}
|
10433
|
-
if (this.isIndefiniteForm) {
|
10434
|
-
if (this.value[this.value.length - 1].constructor.NAME === END_OF_CONTENT_NAME) {
|
10435
|
-
this.value.pop();
|
10436
|
-
}
|
10437
|
-
else {
|
10438
|
-
this.warnings.push("No EndOfContent block encoded");
|
10439
|
-
}
|
10440
|
-
}
|
10441
|
-
return currentOffset;
|
10442
|
-
}
|
10443
|
-
toBER(sizeOnly, writer) {
|
10444
|
-
const _writer = writer || new ViewWriter();
|
10445
|
-
for (let i = 0; i < this.value.length; i++) {
|
10446
|
-
this.value[i].toBER(sizeOnly, _writer);
|
10447
|
-
}
|
10448
|
-
if (!writer) {
|
10449
|
-
return _writer.final();
|
10450
|
-
}
|
10451
|
-
return EMPTY_BUFFER;
|
10452
|
-
}
|
10453
|
-
toJSON() {
|
10454
|
-
const object = {
|
10455
|
-
...super.toJSON(),
|
10456
|
-
isIndefiniteForm: this.isIndefiniteForm,
|
10457
|
-
value: [],
|
10458
|
-
};
|
10459
|
-
for (const value of this.value) {
|
10460
|
-
object.value.push(value.toJSON());
|
10461
|
-
}
|
10462
|
-
return object;
|
10463
|
-
}
|
10464
|
-
}
|
10465
|
-
LocalConstructedValueBlock.NAME = "ConstructedValueBlock";
|
10466
|
-
|
10467
|
-
var _a$v;
|
10468
|
-
class Constructed extends BaseBlock {
|
10469
|
-
constructor(parameters = {}) {
|
10470
|
-
super(parameters, LocalConstructedValueBlock);
|
10471
|
-
this.idBlock.isConstructed = true;
|
10472
|
-
}
|
10473
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10474
|
-
this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
|
10475
|
-
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, (this.lenBlock.isIndefiniteForm) ? inputLength : this.lenBlock.length);
|
10476
|
-
if (resultOffset === -1) {
|
10477
|
-
this.error = this.valueBlock.error;
|
10478
|
-
return resultOffset;
|
10479
|
-
}
|
10480
|
-
if (!this.idBlock.error.length)
|
10481
|
-
this.blockLength += this.idBlock.blockLength;
|
10482
|
-
if (!this.lenBlock.error.length)
|
10483
|
-
this.blockLength += this.lenBlock.blockLength;
|
10484
|
-
if (!this.valueBlock.error.length)
|
10485
|
-
this.blockLength += this.valueBlock.blockLength;
|
10486
|
-
return resultOffset;
|
10487
|
-
}
|
10488
|
-
onAsciiEncoding() {
|
10489
|
-
const values = [];
|
10490
|
-
for (const value of this.valueBlock.value) {
|
10491
|
-
values.push(value.toString("ascii").split("\n").map(o => ` ${o}`).join("\n"));
|
10492
|
-
}
|
10493
|
-
const blockName = this.idBlock.tagClass === 3
|
10494
|
-
? `[${this.idBlock.tagNumber}]`
|
10495
|
-
: this.constructor.NAME;
|
10496
|
-
return values.length
|
10497
|
-
? `${blockName} :\n${values.join("\n")}`
|
10498
|
-
: `${blockName} :`;
|
10499
|
-
}
|
10500
|
-
}
|
10501
|
-
_a$v = Constructed;
|
10502
|
-
(() => {
|
10503
|
-
typeStore.Constructed = _a$v;
|
10504
|
-
})();
|
10505
|
-
Constructed.NAME = "CONSTRUCTED";
|
10506
|
-
|
10507
|
-
class LocalEndOfContentValueBlock extends ValueBlock {
|
10508
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10509
|
-
return inputOffset;
|
10510
|
-
}
|
10511
|
-
toBER(sizeOnly) {
|
10512
|
-
return EMPTY_BUFFER;
|
10513
|
-
}
|
10514
|
-
}
|
10515
|
-
LocalEndOfContentValueBlock.override = "EndOfContentValueBlock";
|
10516
|
-
|
10517
|
-
var _a$u;
|
10518
|
-
class EndOfContent extends BaseBlock {
|
10519
|
-
constructor(parameters = {}) {
|
10520
|
-
super(parameters, LocalEndOfContentValueBlock);
|
10521
|
-
this.idBlock.tagClass = 1;
|
10522
|
-
this.idBlock.tagNumber = 0;
|
10523
|
-
}
|
10524
|
-
}
|
10525
|
-
_a$u = EndOfContent;
|
10526
|
-
(() => {
|
10527
|
-
typeStore.EndOfContent = _a$u;
|
10528
|
-
})();
|
10529
|
-
EndOfContent.NAME = END_OF_CONTENT_NAME;
|
10530
|
-
|
10531
|
-
var _a$t;
|
10532
|
-
class Null extends BaseBlock {
|
10533
|
-
constructor(parameters = {}) {
|
10534
|
-
super(parameters, ValueBlock);
|
10535
|
-
this.idBlock.tagClass = 1;
|
10536
|
-
this.idBlock.tagNumber = 5;
|
10537
|
-
}
|
10538
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10539
|
-
if (this.lenBlock.length > 0)
|
10540
|
-
this.warnings.push("Non-zero length of value block for Null type");
|
10541
|
-
if (!this.idBlock.error.length)
|
10542
|
-
this.blockLength += this.idBlock.blockLength;
|
10543
|
-
if (!this.lenBlock.error.length)
|
10544
|
-
this.blockLength += this.lenBlock.blockLength;
|
10545
|
-
this.blockLength += inputLength;
|
10546
|
-
if ((inputOffset + inputLength) > inputBuffer.byteLength) {
|
10547
|
-
this.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
|
10548
|
-
return -1;
|
10549
|
-
}
|
10550
|
-
return (inputOffset + inputLength);
|
10551
|
-
}
|
10552
|
-
toBER(sizeOnly, writer) {
|
10553
|
-
const retBuf = new ArrayBuffer(2);
|
10554
|
-
if (!sizeOnly) {
|
10555
|
-
const retView = new Uint8Array(retBuf);
|
10556
|
-
retView[0] = 0x05;
|
10557
|
-
retView[1] = 0x00;
|
10558
|
-
}
|
10559
|
-
if (writer) {
|
10560
|
-
writer.write(retBuf);
|
10561
|
-
}
|
10562
|
-
return retBuf;
|
10563
|
-
}
|
10564
|
-
onAsciiEncoding() {
|
10565
|
-
return `${this.constructor.NAME}`;
|
10566
|
-
}
|
10567
|
-
}
|
10568
|
-
_a$t = Null;
|
10569
|
-
(() => {
|
10570
|
-
typeStore.Null = _a$t;
|
10571
|
-
})();
|
10572
|
-
Null.NAME = "NULL";
|
10573
|
-
|
10574
|
-
class LocalBooleanValueBlock extends HexBlock(ValueBlock) {
|
10575
|
-
constructor({ value, ...parameters } = {}) {
|
10576
|
-
super(parameters);
|
10577
|
-
if (parameters.valueHex) {
|
10578
|
-
this.valueHexView = BufferSourceConverter_1.toUint8Array(parameters.valueHex);
|
10579
|
-
}
|
10580
|
-
else {
|
10581
|
-
this.valueHexView = new Uint8Array(1);
|
10582
|
-
}
|
10583
|
-
if (value) {
|
10584
|
-
this.value = value;
|
10585
|
-
}
|
10586
|
-
}
|
10587
|
-
get value() {
|
10588
|
-
for (const octet of this.valueHexView) {
|
10589
|
-
if (octet > 0) {
|
10590
|
-
return true;
|
10591
|
-
}
|
10592
|
-
}
|
10593
|
-
return false;
|
10594
|
-
}
|
10595
|
-
set value(value) {
|
10596
|
-
this.valueHexView[0] = value ? 0xFF : 0x00;
|
10597
|
-
}
|
10598
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10599
|
-
const inputView = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
10600
|
-
if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
|
10601
|
-
return -1;
|
10602
|
-
}
|
10603
|
-
this.valueHexView = inputView.subarray(inputOffset, inputOffset + inputLength);
|
10604
|
-
if (inputLength > 1)
|
10605
|
-
this.warnings.push("Boolean value encoded in more then 1 octet");
|
10606
|
-
this.isHexOnly = true;
|
10607
|
-
utilDecodeTC.call(this);
|
10608
|
-
this.blockLength = inputLength;
|
10609
|
-
return (inputOffset + inputLength);
|
10610
|
-
}
|
10611
|
-
toBER() {
|
10612
|
-
return this.valueHexView.slice();
|
10613
|
-
}
|
10614
|
-
toJSON() {
|
10615
|
-
return {
|
10616
|
-
...super.toJSON(),
|
10617
|
-
value: this.value,
|
10618
|
-
};
|
10619
|
-
}
|
10620
|
-
}
|
10621
|
-
LocalBooleanValueBlock.NAME = "BooleanValueBlock";
|
10622
|
-
|
10623
|
-
var _a$s;
|
10624
|
-
let Boolean$1 = class Boolean extends BaseBlock {
|
10625
|
-
constructor(parameters = {}) {
|
10626
|
-
super(parameters, LocalBooleanValueBlock);
|
10627
|
-
this.idBlock.tagClass = 1;
|
10628
|
-
this.idBlock.tagNumber = 1;
|
10629
|
-
}
|
10630
|
-
getValue() {
|
10631
|
-
return this.valueBlock.value;
|
10632
|
-
}
|
10633
|
-
setValue(value) {
|
10634
|
-
this.valueBlock.value = value;
|
10635
|
-
}
|
10636
|
-
onAsciiEncoding() {
|
10637
|
-
return `${this.constructor.NAME} : ${this.getValue}`;
|
10638
|
-
}
|
10639
|
-
};
|
10640
|
-
_a$s = Boolean$1;
|
10641
|
-
(() => {
|
10642
|
-
typeStore.Boolean = _a$s;
|
10643
|
-
})();
|
10644
|
-
Boolean$1.NAME = "BOOLEAN";
|
10645
|
-
|
10646
|
-
class LocalOctetStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
10647
|
-
constructor({ isConstructed = false, ...parameters } = {}) {
|
10648
|
-
super(parameters);
|
10649
|
-
this.isConstructed = isConstructed;
|
10650
|
-
}
|
10651
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10652
|
-
let resultOffset = 0;
|
10653
|
-
if (this.isConstructed) {
|
10654
|
-
this.isHexOnly = false;
|
10655
|
-
resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
|
10656
|
-
if (resultOffset === -1)
|
10657
|
-
return resultOffset;
|
10658
|
-
for (let i = 0; i < this.value.length; i++) {
|
10659
|
-
const currentBlockName = this.value[i].constructor.NAME;
|
10660
|
-
if (currentBlockName === END_OF_CONTENT_NAME) {
|
10661
|
-
if (this.isIndefiniteForm)
|
10662
|
-
break;
|
10663
|
-
else {
|
10664
|
-
this.error = "EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only";
|
10665
|
-
return -1;
|
10666
|
-
}
|
10667
|
-
}
|
10668
|
-
if (currentBlockName !== OCTET_STRING_NAME) {
|
10669
|
-
this.error = "OCTET STRING may consists of OCTET STRINGs only";
|
10670
|
-
return -1;
|
10671
|
-
}
|
10672
|
-
}
|
10673
|
-
}
|
10674
|
-
else {
|
10675
|
-
this.isHexOnly = true;
|
10676
|
-
resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
|
10677
|
-
this.blockLength = inputLength;
|
10678
|
-
}
|
10679
|
-
return resultOffset;
|
10680
|
-
}
|
10681
|
-
toBER(sizeOnly, writer) {
|
10682
|
-
if (this.isConstructed)
|
10683
|
-
return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
|
10684
|
-
return sizeOnly
|
10685
|
-
? new ArrayBuffer(this.valueHexView.byteLength)
|
10686
|
-
: this.valueHexView.slice().buffer;
|
10687
|
-
}
|
10688
|
-
toJSON() {
|
10689
|
-
return {
|
10690
|
-
...super.toJSON(),
|
10691
|
-
isConstructed: this.isConstructed,
|
10692
|
-
};
|
10693
|
-
}
|
10694
|
-
}
|
10695
|
-
LocalOctetStringValueBlock.NAME = "OctetStringValueBlock";
|
10696
|
-
|
10697
|
-
var _a$r;
|
10698
|
-
class OctetString extends BaseBlock {
|
10699
|
-
constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
|
10700
|
-
var _b, _c;
|
10701
|
-
(_b = parameters.isConstructed) !== null && _b !== undefined ? _b : (parameters.isConstructed = !!((_c = parameters.value) === null || _c === undefined ? undefined : _c.length));
|
10702
|
-
super({
|
10703
|
-
idBlock: {
|
10704
|
-
isConstructed: parameters.isConstructed,
|
10705
|
-
...idBlock,
|
10706
|
-
},
|
10707
|
-
lenBlock: {
|
10708
|
-
...lenBlock,
|
10709
|
-
isIndefiniteForm: !!parameters.isIndefiniteForm,
|
10710
|
-
},
|
10711
|
-
...parameters,
|
10712
|
-
}, LocalOctetStringValueBlock);
|
10713
|
-
this.idBlock.tagClass = 1;
|
10714
|
-
this.idBlock.tagNumber = 4;
|
10715
|
-
}
|
10716
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10717
|
-
this.valueBlock.isConstructed = this.idBlock.isConstructed;
|
10718
|
-
this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
|
10719
|
-
if (inputLength === 0) {
|
10720
|
-
if (this.idBlock.error.length === 0)
|
10721
|
-
this.blockLength += this.idBlock.blockLength;
|
10722
|
-
if (this.lenBlock.error.length === 0)
|
10723
|
-
this.blockLength += this.lenBlock.blockLength;
|
10724
|
-
return inputOffset;
|
10725
|
-
}
|
10726
|
-
if (!this.valueBlock.isConstructed) {
|
10727
|
-
const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
|
10728
|
-
const buf = view.subarray(inputOffset, inputOffset + inputLength);
|
10729
|
-
try {
|
10730
|
-
if (buf.byteLength) {
|
10731
|
-
const asn = localFromBER(buf, 0, buf.byteLength);
|
10732
|
-
if (asn.offset !== -1 && asn.offset === inputLength) {
|
10733
|
-
this.valueBlock.value = [asn.result];
|
10734
|
-
}
|
10735
|
-
}
|
10736
|
-
}
|
10737
|
-
catch (e) {
|
10738
|
-
}
|
10739
|
-
}
|
10740
|
-
return super.fromBER(inputBuffer, inputOffset, inputLength);
|
10741
|
-
}
|
10742
|
-
onAsciiEncoding() {
|
10743
|
-
if (this.valueBlock.isConstructed || (this.valueBlock.value && this.valueBlock.value.length)) {
|
10744
|
-
return Constructed.prototype.onAsciiEncoding.call(this);
|
10745
|
-
}
|
10746
|
-
return `${this.constructor.NAME} : ${Convert_1.ToHex(this.valueBlock.valueHexView)}`;
|
10747
|
-
}
|
10748
|
-
getValue() {
|
10749
|
-
if (!this.idBlock.isConstructed) {
|
10750
|
-
return this.valueBlock.valueHexView.slice().buffer;
|
10751
|
-
}
|
10752
|
-
const array = [];
|
10753
|
-
for (const content of this.valueBlock.value) {
|
10754
|
-
if (content instanceof OctetString) {
|
10755
|
-
array.push(content.valueBlock.valueHexView);
|
10756
|
-
}
|
10757
|
-
}
|
10758
|
-
return BufferSourceConverter_1.concat(array);
|
10759
|
-
}
|
10760
|
-
}
|
10761
|
-
_a$r = OctetString;
|
10762
|
-
(() => {
|
10763
|
-
typeStore.OctetString = _a$r;
|
10764
|
-
})();
|
10765
|
-
OctetString.NAME = OCTET_STRING_NAME;
|
10766
|
-
|
10767
|
-
class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
10768
|
-
constructor({ unusedBits = 0, isConstructed = false, ...parameters } = {}) {
|
10769
|
-
super(parameters);
|
10770
|
-
this.unusedBits = unusedBits;
|
10771
|
-
this.isConstructed = isConstructed;
|
10772
|
-
this.blockLength = this.valueHexView.byteLength;
|
10773
|
-
}
|
10774
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10775
|
-
if (!inputLength) {
|
10776
|
-
return inputOffset;
|
10777
|
-
}
|
10778
|
-
let resultOffset = -1;
|
10779
|
-
if (this.isConstructed) {
|
10780
|
-
resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
|
10781
|
-
if (resultOffset === -1)
|
10782
|
-
return resultOffset;
|
10783
|
-
for (const value of this.value) {
|
10784
|
-
const currentBlockName = value.constructor.NAME;
|
10785
|
-
if (currentBlockName === END_OF_CONTENT_NAME) {
|
10786
|
-
if (this.isIndefiniteForm)
|
10787
|
-
break;
|
10788
|
-
else {
|
10789
|
-
this.error = "EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only";
|
10790
|
-
return -1;
|
10791
|
-
}
|
10792
|
-
}
|
10793
|
-
if (currentBlockName !== BIT_STRING_NAME) {
|
10794
|
-
this.error = "BIT STRING may consists of BIT STRINGs only";
|
10795
|
-
return -1;
|
10796
|
-
}
|
10797
|
-
const valueBlock = value.valueBlock;
|
10798
|
-
if ((this.unusedBits > 0) && (valueBlock.unusedBits > 0)) {
|
10799
|
-
this.error = "Using of \"unused bits\" inside constructive BIT STRING allowed for least one only";
|
10800
|
-
return -1;
|
10801
|
-
}
|
10802
|
-
this.unusedBits = valueBlock.unusedBits;
|
10803
|
-
}
|
10804
|
-
return resultOffset;
|
10805
|
-
}
|
10806
|
-
const inputView = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
10807
|
-
if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
|
10808
|
-
return -1;
|
10809
|
-
}
|
10810
|
-
const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
|
10811
|
-
this.unusedBits = intBuffer[0];
|
10812
|
-
if (this.unusedBits > 7) {
|
10813
|
-
this.error = "Unused bits for BitString must be in range 0-7";
|
10814
|
-
return -1;
|
10815
|
-
}
|
10816
|
-
if (!this.unusedBits) {
|
10817
|
-
const buf = intBuffer.subarray(1);
|
10818
|
-
try {
|
10819
|
-
if (buf.byteLength) {
|
10820
|
-
const asn = localFromBER(buf, 0, buf.byteLength);
|
10821
|
-
if (asn.offset !== -1 && asn.offset === (inputLength - 1)) {
|
10822
|
-
this.value = [asn.result];
|
10823
|
-
}
|
10824
|
-
}
|
10825
|
-
}
|
10826
|
-
catch (e) {
|
10827
|
-
}
|
10828
|
-
}
|
10829
|
-
this.valueHexView = intBuffer.subarray(1);
|
10830
|
-
this.blockLength = intBuffer.length;
|
10831
|
-
return (inputOffset + inputLength);
|
10832
|
-
}
|
10833
|
-
toBER(sizeOnly, writer) {
|
10834
|
-
if (this.isConstructed) {
|
10835
|
-
return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
|
10836
|
-
}
|
10837
|
-
if (sizeOnly) {
|
10838
|
-
return new ArrayBuffer(this.valueHexView.byteLength + 1);
|
10839
|
-
}
|
10840
|
-
if (!this.valueHexView.byteLength) {
|
10841
|
-
return EMPTY_BUFFER;
|
10842
|
-
}
|
10843
|
-
const retView = new Uint8Array(this.valueHexView.length + 1);
|
10844
|
-
retView[0] = this.unusedBits;
|
10845
|
-
retView.set(this.valueHexView, 1);
|
10846
|
-
return retView.buffer;
|
10847
|
-
}
|
10848
|
-
toJSON() {
|
10849
|
-
return {
|
10850
|
-
...super.toJSON(),
|
10851
|
-
unusedBits: this.unusedBits,
|
10852
|
-
isConstructed: this.isConstructed,
|
10853
|
-
};
|
10854
|
-
}
|
10855
|
-
}
|
10856
|
-
LocalBitStringValueBlock.NAME = "BitStringValueBlock";
|
10857
|
-
|
10858
|
-
var _a$q;
|
10859
|
-
class BitString extends BaseBlock {
|
10860
|
-
constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
|
10861
|
-
var _b, _c;
|
10862
|
-
(_b = parameters.isConstructed) !== null && _b !== undefined ? _b : (parameters.isConstructed = !!((_c = parameters.value) === null || _c === undefined ? undefined : _c.length));
|
10863
|
-
super({
|
10864
|
-
idBlock: {
|
10865
|
-
isConstructed: parameters.isConstructed,
|
10866
|
-
...idBlock,
|
10867
|
-
},
|
10868
|
-
lenBlock: {
|
10869
|
-
...lenBlock,
|
10870
|
-
isIndefiniteForm: !!parameters.isIndefiniteForm,
|
10871
|
-
},
|
10872
|
-
...parameters,
|
10873
|
-
}, LocalBitStringValueBlock);
|
10874
|
-
this.idBlock.tagClass = 1;
|
10875
|
-
this.idBlock.tagNumber = 3;
|
10876
|
-
}
|
10877
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
10878
|
-
this.valueBlock.isConstructed = this.idBlock.isConstructed;
|
10879
|
-
this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
|
10880
|
-
return super.fromBER(inputBuffer, inputOffset, inputLength);
|
10881
|
-
}
|
10882
|
-
onAsciiEncoding() {
|
10883
|
-
if (this.valueBlock.isConstructed || (this.valueBlock.value && this.valueBlock.value.length)) {
|
10884
|
-
return Constructed.prototype.onAsciiEncoding.call(this);
|
10885
|
-
}
|
10886
|
-
else {
|
10887
|
-
const bits = [];
|
10888
|
-
const valueHex = this.valueBlock.valueHexView;
|
10889
|
-
for (const byte of valueHex) {
|
10890
|
-
bits.push(byte.toString(2).padStart(8, "0"));
|
10891
|
-
}
|
10892
|
-
const bitsStr = bits.join("");
|
10893
|
-
return `${this.constructor.NAME} : ${bitsStr.substring(0, bitsStr.length - this.valueBlock.unusedBits)}`;
|
10894
|
-
}
|
10895
|
-
}
|
10896
|
-
}
|
10897
|
-
_a$q = BitString;
|
10898
|
-
(() => {
|
10899
|
-
typeStore.BitString = _a$q;
|
10900
|
-
})();
|
10901
|
-
BitString.NAME = BIT_STRING_NAME;
|
10902
|
-
|
10903
|
-
var _a$p;
|
10904
|
-
function viewAdd(first, second) {
|
10905
|
-
const c = new Uint8Array([0]);
|
10906
|
-
const firstView = new Uint8Array(first);
|
10907
|
-
const secondView = new Uint8Array(second);
|
10908
|
-
let firstViewCopy = firstView.slice(0);
|
10909
|
-
const firstViewCopyLength = firstViewCopy.length - 1;
|
10910
|
-
const secondViewCopy = secondView.slice(0);
|
10911
|
-
const secondViewCopyLength = secondViewCopy.length - 1;
|
10912
|
-
let value = 0;
|
10913
|
-
const max = (secondViewCopyLength < firstViewCopyLength) ? firstViewCopyLength : secondViewCopyLength;
|
10914
|
-
let counter = 0;
|
10915
|
-
for (let i = max; i >= 0; i--, counter++) {
|
10916
|
-
switch (true) {
|
10917
|
-
case (counter < secondViewCopy.length):
|
10918
|
-
value = firstViewCopy[firstViewCopyLength - counter] + secondViewCopy[secondViewCopyLength - counter] + c[0];
|
10919
|
-
break;
|
10920
|
-
default:
|
10921
|
-
value = firstViewCopy[firstViewCopyLength - counter] + c[0];
|
10922
|
-
}
|
10923
|
-
c[0] = value / 10;
|
10924
|
-
switch (true) {
|
10925
|
-
case (counter >= firstViewCopy.length):
|
10926
|
-
firstViewCopy = utilConcatView(new Uint8Array([value % 10]), firstViewCopy);
|
10927
|
-
break;
|
10928
|
-
default:
|
10929
|
-
firstViewCopy[firstViewCopyLength - counter] = value % 10;
|
10930
|
-
}
|
10931
|
-
}
|
10932
|
-
if (c[0] > 0)
|
10933
|
-
firstViewCopy = utilConcatView(c, firstViewCopy);
|
10934
|
-
return firstViewCopy;
|
10935
|
-
}
|
10936
|
-
function power2(n) {
|
10937
|
-
if (n >= powers2.length) {
|
10938
|
-
for (let p = powers2.length; p <= n; p++) {
|
10939
|
-
const c = new Uint8Array([0]);
|
10940
|
-
let digits = (powers2[p - 1]).slice(0);
|
10941
|
-
for (let i = (digits.length - 1); i >= 0; i--) {
|
10942
|
-
const newValue = new Uint8Array([(digits[i] << 1) + c[0]]);
|
10943
|
-
c[0] = newValue[0] / 10;
|
10944
|
-
digits[i] = newValue[0] % 10;
|
10945
|
-
}
|
10946
|
-
if (c[0] > 0)
|
10947
|
-
digits = utilConcatView(c, digits);
|
10948
|
-
powers2.push(digits);
|
10949
|
-
}
|
10950
|
-
}
|
10951
|
-
return powers2[n];
|
10952
|
-
}
|
10953
|
-
function viewSub(first, second) {
|
10954
|
-
let b = 0;
|
10955
|
-
const firstView = new Uint8Array(first);
|
10956
|
-
const secondView = new Uint8Array(second);
|
10957
|
-
const firstViewCopy = firstView.slice(0);
|
10958
|
-
const firstViewCopyLength = firstViewCopy.length - 1;
|
10959
|
-
const secondViewCopy = secondView.slice(0);
|
10960
|
-
const secondViewCopyLength = secondViewCopy.length - 1;
|
10961
|
-
let value;
|
10962
|
-
let counter = 0;
|
10963
|
-
for (let i = secondViewCopyLength; i >= 0; i--, counter++) {
|
10964
|
-
value = firstViewCopy[firstViewCopyLength - counter] - secondViewCopy[secondViewCopyLength - counter] - b;
|
10965
|
-
switch (true) {
|
10966
|
-
case (value < 0):
|
10967
|
-
b = 1;
|
10968
|
-
firstViewCopy[firstViewCopyLength - counter] = value + 10;
|
10969
|
-
break;
|
10970
|
-
default:
|
10971
|
-
b = 0;
|
10972
|
-
firstViewCopy[firstViewCopyLength - counter] = value;
|
10973
|
-
}
|
10974
|
-
}
|
10975
|
-
if (b > 0) {
|
10976
|
-
for (let i = (firstViewCopyLength - secondViewCopyLength + 1); i >= 0; i--, counter++) {
|
10977
|
-
value = firstViewCopy[firstViewCopyLength - counter] - b;
|
10978
|
-
if (value < 0) {
|
10979
|
-
b = 1;
|
10980
|
-
firstViewCopy[firstViewCopyLength - counter] = value + 10;
|
10981
|
-
}
|
10982
|
-
else {
|
10983
|
-
b = 0;
|
10984
|
-
firstViewCopy[firstViewCopyLength - counter] = value;
|
10985
|
-
break;
|
10986
|
-
}
|
10987
|
-
}
|
10988
|
-
}
|
10989
|
-
return firstViewCopy.slice();
|
10990
|
-
}
|
10991
|
-
class LocalIntegerValueBlock extends HexBlock(ValueBlock) {
|
10992
|
-
constructor({ value, ...parameters } = {}) {
|
10993
|
-
super(parameters);
|
10994
|
-
this._valueDec = 0;
|
10995
|
-
if (parameters.valueHex) {
|
10996
|
-
this.setValueHex();
|
10997
|
-
}
|
10998
|
-
if (value !== undefined) {
|
10999
|
-
this.valueDec = value;
|
11000
|
-
}
|
11001
|
-
}
|
11002
|
-
setValueHex() {
|
11003
|
-
if (this.valueHexView.length >= 4) {
|
11004
|
-
this.warnings.push("Too big Integer for decoding, hex only");
|
11005
|
-
this.isHexOnly = true;
|
11006
|
-
this._valueDec = 0;
|
11007
|
-
}
|
11008
|
-
else {
|
11009
|
-
this.isHexOnly = false;
|
11010
|
-
if (this.valueHexView.length > 0) {
|
11011
|
-
this._valueDec = utilDecodeTC.call(this);
|
11012
|
-
}
|
11013
|
-
}
|
11014
|
-
}
|
11015
|
-
set valueDec(v) {
|
11016
|
-
this._valueDec = v;
|
11017
|
-
this.isHexOnly = false;
|
11018
|
-
this.valueHexView = new Uint8Array(utilEncodeTC(v));
|
11019
|
-
}
|
11020
|
-
get valueDec() {
|
11021
|
-
return this._valueDec;
|
11022
|
-
}
|
11023
|
-
fromDER(inputBuffer, inputOffset, inputLength, expectedLength = 0) {
|
11024
|
-
const offset = this.fromBER(inputBuffer, inputOffset, inputLength);
|
11025
|
-
if (offset === -1)
|
11026
|
-
return offset;
|
11027
|
-
const view = this.valueHexView;
|
11028
|
-
if ((view[0] === 0x00) && ((view[1] & 0x80) !== 0)) {
|
11029
|
-
this.valueHexView = view.subarray(1);
|
11030
|
-
}
|
11031
|
-
else {
|
11032
|
-
if (expectedLength !== 0) {
|
11033
|
-
if (view.length < expectedLength) {
|
11034
|
-
if ((expectedLength - view.length) > 1)
|
11035
|
-
expectedLength = view.length + 1;
|
11036
|
-
this.valueHexView = view.subarray(expectedLength - view.length);
|
11037
|
-
}
|
11038
|
-
}
|
11039
|
-
}
|
11040
|
-
return offset;
|
11041
|
-
}
|
11042
|
-
toDER(sizeOnly = false) {
|
11043
|
-
const view = this.valueHexView;
|
11044
|
-
switch (true) {
|
11045
|
-
case ((view[0] & 0x80) !== 0):
|
11046
|
-
{
|
11047
|
-
const updatedView = new Uint8Array(this.valueHexView.length + 1);
|
11048
|
-
updatedView[0] = 0x00;
|
11049
|
-
updatedView.set(view, 1);
|
11050
|
-
this.valueHexView = updatedView;
|
11051
|
-
}
|
11052
|
-
break;
|
11053
|
-
case ((view[0] === 0x00) && ((view[1] & 0x80) === 0)):
|
11054
|
-
{
|
11055
|
-
this.valueHexView = this.valueHexView.subarray(1);
|
11056
|
-
}
|
11057
|
-
break;
|
11058
|
-
}
|
11059
|
-
return this.toBER(sizeOnly);
|
11060
|
-
}
|
11061
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
11062
|
-
const resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
|
11063
|
-
if (resultOffset === -1) {
|
11064
|
-
return resultOffset;
|
11065
|
-
}
|
11066
|
-
this.setValueHex();
|
11067
|
-
return resultOffset;
|
11068
|
-
}
|
11069
|
-
toBER(sizeOnly) {
|
11070
|
-
return sizeOnly
|
11071
|
-
? new ArrayBuffer(this.valueHexView.length)
|
11072
|
-
: this.valueHexView.slice().buffer;
|
11073
|
-
}
|
11074
|
-
toJSON() {
|
11075
|
-
return {
|
11076
|
-
...super.toJSON(),
|
11077
|
-
valueDec: this.valueDec,
|
11078
|
-
};
|
11079
|
-
}
|
11080
|
-
toString() {
|
11081
|
-
const firstBit = (this.valueHexView.length * 8) - 1;
|
11082
|
-
let digits = new Uint8Array((this.valueHexView.length * 8) / 3);
|
11083
|
-
let bitNumber = 0;
|
11084
|
-
let currentByte;
|
11085
|
-
const asn1View = this.valueHexView;
|
11086
|
-
let result = "";
|
11087
|
-
let flag = false;
|
11088
|
-
for (let byteNumber = (asn1View.byteLength - 1); byteNumber >= 0; byteNumber--) {
|
11089
|
-
currentByte = asn1View[byteNumber];
|
11090
|
-
for (let i = 0; i < 8; i++) {
|
11091
|
-
if ((currentByte & 1) === 1) {
|
11092
|
-
switch (bitNumber) {
|
11093
|
-
case firstBit:
|
11094
|
-
digits = viewSub(power2(bitNumber), digits);
|
11095
|
-
result = "-";
|
11096
|
-
break;
|
11097
|
-
default:
|
11098
|
-
digits = viewAdd(digits, power2(bitNumber));
|
11099
|
-
}
|
11100
|
-
}
|
11101
|
-
bitNumber++;
|
11102
|
-
currentByte >>= 1;
|
11103
|
-
}
|
11104
|
-
}
|
11105
|
-
for (let i = 0; i < digits.length; i++) {
|
11106
|
-
if (digits[i])
|
11107
|
-
flag = true;
|
11108
|
-
if (flag)
|
11109
|
-
result += digitsString.charAt(digits[i]);
|
11110
|
-
}
|
11111
|
-
if (flag === false)
|
11112
|
-
result += digitsString.charAt(0);
|
11113
|
-
return result;
|
11114
|
-
}
|
11115
|
-
}
|
11116
|
-
_a$p = LocalIntegerValueBlock;
|
11117
|
-
LocalIntegerValueBlock.NAME = "IntegerValueBlock";
|
11118
|
-
(() => {
|
11119
|
-
Object.defineProperty(_a$p.prototype, "valueHex", {
|
11120
|
-
set: function (v) {
|
11121
|
-
this.valueHexView = new Uint8Array(v);
|
11122
|
-
this.setValueHex();
|
11123
|
-
},
|
11124
|
-
get: function () {
|
11125
|
-
return this.valueHexView.slice().buffer;
|
11126
|
-
},
|
11127
|
-
});
|
11128
|
-
})();
|
9635
|
+
return -1
|
9636
|
+
}
|
9637
|
+
*/
|
11129
9638
|
|
11130
|
-
|
11131
|
-
|
11132
|
-
|
11133
|
-
|
11134
|
-
|
11135
|
-
|
11136
|
-
|
11137
|
-
|
11138
|
-
|
11139
|
-
|
11140
|
-
|
11141
|
-
|
11142
|
-
|
11143
|
-
|
11144
|
-
|
11145
|
-
|
11146
|
-
|
11147
|
-
|
11148
|
-
|
11149
|
-
|
11150
|
-
|
11151
|
-
|
11152
|
-
|
11153
|
-
|
11154
|
-
|
11155
|
-
|
11156
|
-
|
11157
|
-
|
11158
|
-
|
11159
|
-
|
11160
|
-
|
11161
|
-
|
11162
|
-
|
11163
|
-
|
11164
|
-
|
11165
|
-
|
11166
|
-
|
11167
|
-
|
11168
|
-
|
11169
|
-
|
11170
|
-
|
11171
|
-
|
11172
|
-
|
11173
|
-
|
11174
|
-
|
11175
|
-
|
11176
|
-
|
11177
|
-
|
11178
|
-
|
11179
|
-
|
11180
|
-
|
11181
|
-
|
11182
|
-
}
|
11183
|
-
|
11184
|
-
(
|
11185
|
-
|
11186
|
-
|
11187
|
-
|
11188
|
-
|
11189
|
-
|
11190
|
-
|
11191
|
-
|
11192
|
-
|
11193
|
-
|
11194
|
-
|
11195
|
-
|
11196
|
-
}
|
11197
|
-
|
11198
|
-
(
|
11199
|
-
|
11200
|
-
|
11201
|
-
|
11202
|
-
|
11203
|
-
|
11204
|
-
|
11205
|
-
|
11206
|
-
|
11207
|
-
|
11208
|
-
|
11209
|
-
|
11210
|
-
|
11211
|
-
|
11212
|
-
|
11213
|
-
|
11214
|
-
|
11215
|
-
|
11216
|
-
|
11217
|
-
|
11218
|
-
|
11219
|
-
|
11220
|
-
|
11221
|
-
|
11222
|
-
|
11223
|
-
|
11224
|
-
|
11225
|
-
|
11226
|
-
|
11227
|
-
|
11228
|
-
}
|
11229
|
-
|
11230
|
-
|
11231
|
-
|
11232
|
-
|
11233
|
-
|
11234
|
-
|
11235
|
-
|
11236
|
-
|
11237
|
-
|
11238
|
-
|
11239
|
-
|
11240
|
-
|
11241
|
-
|
11242
|
-
|
11243
|
-
|
11244
|
-
|
11245
|
-
|
11246
|
-
|
11247
|
-
|
11248
|
-
|
11249
|
-
|
11250
|
-
|
11251
|
-
|
11252
|
-
|
11253
|
-
|
11254
|
-
|
11255
|
-
|
11256
|
-
|
11257
|
-
|
11258
|
-
|
11259
|
-
|
11260
|
-
|
11261
|
-
|
11262
|
-
|
11263
|
-
|
11264
|
-
|
11265
|
-
return retView.buffer;
|
11266
|
-
}
|
11267
|
-
const encodedBuf = utilToBase(this.valueDec, 7);
|
11268
|
-
if (encodedBuf.byteLength === 0) {
|
11269
|
-
this.error = "Error during encoding SID value";
|
11270
|
-
return EMPTY_BUFFER;
|
11271
|
-
}
|
11272
|
-
const retView = new Uint8Array(encodedBuf.byteLength);
|
11273
|
-
if (!sizeOnly) {
|
11274
|
-
const encodedView = new Uint8Array(encodedBuf);
|
11275
|
-
const len = encodedBuf.byteLength - 1;
|
11276
|
-
for (let i = 0; i < len; i++)
|
11277
|
-
retView[i] = encodedView[i] | 0x80;
|
11278
|
-
retView[len] = encodedView[len];
|
11279
|
-
}
|
11280
|
-
return retView;
|
11281
|
-
}
|
11282
|
-
toString() {
|
11283
|
-
let result = "";
|
11284
|
-
if (this.isHexOnly)
|
11285
|
-
result = Convert_1.ToHex(this.valueHexView);
|
11286
|
-
else {
|
11287
|
-
if (this.isFirstSid) {
|
11288
|
-
let sidValue = this.valueDec;
|
11289
|
-
if (this.valueDec <= 39)
|
11290
|
-
result = "0.";
|
11291
|
-
else {
|
11292
|
-
if (this.valueDec <= 79) {
|
11293
|
-
result = "1.";
|
11294
|
-
sidValue -= 40;
|
11295
|
-
}
|
11296
|
-
else {
|
11297
|
-
result = "2.";
|
11298
|
-
sidValue -= 80;
|
11299
|
-
}
|
11300
|
-
}
|
11301
|
-
result += sidValue.toString();
|
11302
|
-
}
|
11303
|
-
else
|
11304
|
-
result = this.valueDec.toString();
|
11305
|
-
}
|
11306
|
-
return result;
|
11307
|
-
}
|
11308
|
-
toJSON() {
|
11309
|
-
return {
|
11310
|
-
...super.toJSON(),
|
11311
|
-
valueDec: this.valueDec,
|
11312
|
-
isFirstSid: this.isFirstSid,
|
11313
|
-
};
|
11314
|
-
}
|
11315
|
-
}
|
11316
|
-
LocalSidValueBlock.NAME = "sidBlock";
|
11317
|
-
|
11318
|
-
class LocalObjectIdentifierValueBlock extends ValueBlock {
|
11319
|
-
constructor({ value = EMPTY_STRING, ...parameters } = {}) {
|
11320
|
-
super(parameters);
|
11321
|
-
this.value = [];
|
11322
|
-
if (value) {
|
11323
|
-
this.fromString(value);
|
11324
|
-
}
|
11325
|
-
}
|
11326
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
11327
|
-
let resultOffset = inputOffset;
|
11328
|
-
while (inputLength > 0) {
|
11329
|
-
const sidBlock = new LocalSidValueBlock();
|
11330
|
-
resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
|
11331
|
-
if (resultOffset === -1) {
|
11332
|
-
this.blockLength = 0;
|
11333
|
-
this.error = sidBlock.error;
|
11334
|
-
return resultOffset;
|
11335
|
-
}
|
11336
|
-
if (this.value.length === 0)
|
11337
|
-
sidBlock.isFirstSid = true;
|
11338
|
-
this.blockLength += sidBlock.blockLength;
|
11339
|
-
inputLength -= sidBlock.blockLength;
|
11340
|
-
this.value.push(sidBlock);
|
11341
|
-
}
|
11342
|
-
return resultOffset;
|
11343
|
-
}
|
11344
|
-
toBER(sizeOnly) {
|
11345
|
-
const retBuffers = [];
|
11346
|
-
for (let i = 0; i < this.value.length; i++) {
|
11347
|
-
const valueBuf = this.value[i].toBER(sizeOnly);
|
11348
|
-
if (valueBuf.byteLength === 0) {
|
11349
|
-
this.error = this.value[i].error;
|
11350
|
-
return EMPTY_BUFFER;
|
11351
|
-
}
|
11352
|
-
retBuffers.push(valueBuf);
|
11353
|
-
}
|
11354
|
-
return concat(retBuffers);
|
11355
|
-
}
|
11356
|
-
fromString(string) {
|
11357
|
-
this.value = [];
|
11358
|
-
let pos1 = 0;
|
11359
|
-
let pos2 = 0;
|
11360
|
-
let sid = "";
|
11361
|
-
let flag = false;
|
11362
|
-
do {
|
11363
|
-
pos2 = string.indexOf(".", pos1);
|
11364
|
-
if (pos2 === -1)
|
11365
|
-
sid = string.substring(pos1);
|
11366
|
-
else
|
11367
|
-
sid = string.substring(pos1, pos2);
|
11368
|
-
pos1 = pos2 + 1;
|
11369
|
-
if (flag) {
|
11370
|
-
const sidBlock = this.value[0];
|
11371
|
-
let plus = 0;
|
11372
|
-
switch (sidBlock.valueDec) {
|
11373
|
-
case 0:
|
11374
|
-
break;
|
11375
|
-
case 1:
|
11376
|
-
plus = 40;
|
11377
|
-
break;
|
11378
|
-
case 2:
|
11379
|
-
plus = 80;
|
11380
|
-
break;
|
11381
|
-
default:
|
11382
|
-
this.value = [];
|
11383
|
-
return;
|
11384
|
-
}
|
11385
|
-
const parsedSID = parseInt(sid, 10);
|
11386
|
-
if (isNaN(parsedSID))
|
11387
|
-
return;
|
11388
|
-
sidBlock.valueDec = parsedSID + plus;
|
11389
|
-
flag = false;
|
11390
|
-
}
|
11391
|
-
else {
|
11392
|
-
const sidBlock = new LocalSidValueBlock();
|
11393
|
-
if (sid > Number.MAX_SAFE_INTEGER) {
|
11394
|
-
assertBigInt();
|
11395
|
-
const sidValue = BigInt(sid);
|
11396
|
-
sidBlock.valueBigInt = sidValue;
|
11397
|
-
}
|
11398
|
-
else {
|
11399
|
-
sidBlock.valueDec = parseInt(sid, 10);
|
11400
|
-
if (isNaN(sidBlock.valueDec))
|
11401
|
-
return;
|
11402
|
-
}
|
11403
|
-
if (!this.value.length) {
|
11404
|
-
sidBlock.isFirstSid = true;
|
11405
|
-
flag = true;
|
11406
|
-
}
|
11407
|
-
this.value.push(sidBlock);
|
11408
|
-
}
|
11409
|
-
} while (pos2 !== -1);
|
11410
|
-
}
|
11411
|
-
toString() {
|
11412
|
-
let result = "";
|
11413
|
-
let isHexOnly = false;
|
11414
|
-
for (let i = 0; i < this.value.length; i++) {
|
11415
|
-
isHexOnly = this.value[i].isHexOnly;
|
11416
|
-
let sidStr = this.value[i].toString();
|
11417
|
-
if (i !== 0)
|
11418
|
-
result = `${result}.`;
|
11419
|
-
if (isHexOnly) {
|
11420
|
-
sidStr = `{${sidStr}}`;
|
11421
|
-
if (this.value[i].isFirstSid)
|
11422
|
-
result = `2.{${sidStr} - 80}`;
|
11423
|
-
else
|
11424
|
-
result += sidStr;
|
11425
|
-
}
|
11426
|
-
else
|
11427
|
-
result += sidStr;
|
11428
|
-
}
|
11429
|
-
return result;
|
11430
|
-
}
|
11431
|
-
toJSON() {
|
11432
|
-
const object = {
|
11433
|
-
...super.toJSON(),
|
11434
|
-
value: this.toString(),
|
11435
|
-
sidArray: [],
|
11436
|
-
};
|
11437
|
-
for (let i = 0; i < this.value.length; i++) {
|
11438
|
-
object.sidArray.push(this.value[i].toJSON());
|
11439
|
-
}
|
11440
|
-
return object;
|
11441
|
-
}
|
11442
|
-
}
|
11443
|
-
LocalObjectIdentifierValueBlock.NAME = "ObjectIdentifierValueBlock";
|
11444
|
-
|
11445
|
-
var _a$m;
|
11446
|
-
class ObjectIdentifier extends BaseBlock {
|
11447
|
-
constructor(parameters = {}) {
|
11448
|
-
super(parameters, LocalObjectIdentifierValueBlock);
|
11449
|
-
this.idBlock.tagClass = 1;
|
11450
|
-
this.idBlock.tagNumber = 6;
|
11451
|
-
}
|
11452
|
-
getValue() {
|
11453
|
-
return this.valueBlock.toString();
|
11454
|
-
}
|
11455
|
-
setValue(value) {
|
11456
|
-
this.valueBlock.fromString(value);
|
11457
|
-
}
|
11458
|
-
onAsciiEncoding() {
|
11459
|
-
return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
|
11460
|
-
}
|
11461
|
-
toJSON() {
|
11462
|
-
return {
|
11463
|
-
...super.toJSON(),
|
11464
|
-
value: this.getValue(),
|
11465
|
-
};
|
11466
|
-
}
|
11467
|
-
}
|
11468
|
-
_a$m = ObjectIdentifier;
|
11469
|
-
(() => {
|
11470
|
-
typeStore.ObjectIdentifier = _a$m;
|
11471
|
-
})();
|
11472
|
-
ObjectIdentifier.NAME = "OBJECT IDENTIFIER";
|
11473
|
-
|
11474
|
-
class LocalRelativeSidValueBlock extends HexBlock(LocalBaseBlock) {
|
11475
|
-
constructor({ valueDec = 0, ...parameters } = {}) {
|
11476
|
-
super(parameters);
|
11477
|
-
this.valueDec = valueDec;
|
11478
|
-
}
|
11479
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
11480
|
-
if (inputLength === 0)
|
11481
|
-
return inputOffset;
|
11482
|
-
const inputView = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
11483
|
-
if (!checkBufferParams(this, inputView, inputOffset, inputLength))
|
11484
|
-
return -1;
|
11485
|
-
const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
|
11486
|
-
this.valueHexView = new Uint8Array(inputLength);
|
11487
|
-
for (let i = 0; i < inputLength; i++) {
|
11488
|
-
this.valueHexView[i] = intBuffer[i] & 0x7F;
|
11489
|
-
this.blockLength++;
|
11490
|
-
if ((intBuffer[i] & 0x80) === 0x00)
|
11491
|
-
break;
|
11492
|
-
}
|
11493
|
-
const tempView = new Uint8Array(this.blockLength);
|
11494
|
-
for (let i = 0; i < this.blockLength; i++)
|
11495
|
-
tempView[i] = this.valueHexView[i];
|
11496
|
-
this.valueHexView = tempView;
|
11497
|
-
if ((intBuffer[this.blockLength - 1] & 0x80) !== 0x00) {
|
11498
|
-
this.error = "End of input reached before message was fully decoded";
|
11499
|
-
return -1;
|
11500
|
-
}
|
11501
|
-
if (this.valueHexView[0] === 0x00)
|
11502
|
-
this.warnings.push("Needlessly long format of SID encoding");
|
11503
|
-
if (this.blockLength <= 8)
|
11504
|
-
this.valueDec = utilFromBase(this.valueHexView, 7);
|
11505
|
-
else {
|
11506
|
-
this.isHexOnly = true;
|
11507
|
-
this.warnings.push("Too big SID for decoding, hex only");
|
11508
|
-
}
|
11509
|
-
return (inputOffset + this.blockLength);
|
11510
|
-
}
|
11511
|
-
toBER(sizeOnly) {
|
11512
|
-
if (this.isHexOnly) {
|
11513
|
-
if (sizeOnly)
|
11514
|
-
return (new ArrayBuffer(this.valueHexView.byteLength));
|
11515
|
-
const curView = this.valueHexView;
|
11516
|
-
const retView = new Uint8Array(this.blockLength);
|
11517
|
-
for (let i = 0; i < (this.blockLength - 1); i++)
|
11518
|
-
retView[i] = curView[i] | 0x80;
|
11519
|
-
retView[this.blockLength - 1] = curView[this.blockLength - 1];
|
11520
|
-
return retView.buffer;
|
11521
|
-
}
|
11522
|
-
const encodedBuf = utilToBase(this.valueDec, 7);
|
11523
|
-
if (encodedBuf.byteLength === 0) {
|
11524
|
-
this.error = "Error during encoding SID value";
|
11525
|
-
return EMPTY_BUFFER;
|
11526
|
-
}
|
11527
|
-
const retView = new Uint8Array(encodedBuf.byteLength);
|
11528
|
-
if (!sizeOnly) {
|
11529
|
-
const encodedView = new Uint8Array(encodedBuf);
|
11530
|
-
const len = encodedBuf.byteLength - 1;
|
11531
|
-
for (let i = 0; i < len; i++)
|
11532
|
-
retView[i] = encodedView[i] | 0x80;
|
11533
|
-
retView[len] = encodedView[len];
|
11534
|
-
}
|
11535
|
-
return retView.buffer;
|
11536
|
-
}
|
11537
|
-
toString() {
|
11538
|
-
let result = "";
|
11539
|
-
if (this.isHexOnly)
|
11540
|
-
result = Convert_1.ToHex(this.valueHexView);
|
11541
|
-
else {
|
11542
|
-
result = this.valueDec.toString();
|
11543
|
-
}
|
11544
|
-
return result;
|
11545
|
-
}
|
11546
|
-
toJSON() {
|
11547
|
-
return {
|
11548
|
-
...super.toJSON(),
|
11549
|
-
valueDec: this.valueDec,
|
11550
|
-
};
|
11551
|
-
}
|
11552
|
-
}
|
11553
|
-
LocalRelativeSidValueBlock.NAME = "relativeSidBlock";
|
11554
|
-
|
11555
|
-
class LocalRelativeObjectIdentifierValueBlock extends ValueBlock {
|
11556
|
-
constructor({ value = EMPTY_STRING, ...parameters } = {}) {
|
11557
|
-
super(parameters);
|
11558
|
-
this.value = [];
|
11559
|
-
if (value) {
|
11560
|
-
this.fromString(value);
|
11561
|
-
}
|
11562
|
-
}
|
11563
|
-
fromBER(inputBuffer, inputOffset, inputLength) {
|
11564
|
-
let resultOffset = inputOffset;
|
11565
|
-
while (inputLength > 0) {
|
11566
|
-
const sidBlock = new LocalRelativeSidValueBlock();
|
11567
|
-
resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
|
11568
|
-
if (resultOffset === -1) {
|
11569
|
-
this.blockLength = 0;
|
11570
|
-
this.error = sidBlock.error;
|
11571
|
-
return resultOffset;
|
11572
|
-
}
|
11573
|
-
this.blockLength += sidBlock.blockLength;
|
11574
|
-
inputLength -= sidBlock.blockLength;
|
11575
|
-
this.value.push(sidBlock);
|
11576
|
-
}
|
11577
|
-
return resultOffset;
|
11578
|
-
}
|
11579
|
-
toBER(sizeOnly, writer) {
|
11580
|
-
const retBuffers = [];
|
11581
|
-
for (let i = 0; i < this.value.length; i++) {
|
11582
|
-
const valueBuf = this.value[i].toBER(sizeOnly);
|
11583
|
-
if (valueBuf.byteLength === 0) {
|
11584
|
-
this.error = this.value[i].error;
|
11585
|
-
return EMPTY_BUFFER;
|
11586
|
-
}
|
11587
|
-
retBuffers.push(valueBuf);
|
11588
|
-
}
|
11589
|
-
return concat(retBuffers);
|
11590
|
-
}
|
11591
|
-
fromString(string) {
|
11592
|
-
this.value = [];
|
11593
|
-
let pos1 = 0;
|
11594
|
-
let pos2 = 0;
|
11595
|
-
let sid = "";
|
11596
|
-
do {
|
11597
|
-
pos2 = string.indexOf(".", pos1);
|
11598
|
-
if (pos2 === -1)
|
11599
|
-
sid = string.substring(pos1);
|
11600
|
-
else
|
11601
|
-
sid = string.substring(pos1, pos2);
|
11602
|
-
pos1 = pos2 + 1;
|
11603
|
-
const sidBlock = new LocalRelativeSidValueBlock();
|
11604
|
-
sidBlock.valueDec = parseInt(sid, 10);
|
11605
|
-
if (isNaN(sidBlock.valueDec))
|
11606
|
-
return true;
|
11607
|
-
this.value.push(sidBlock);
|
11608
|
-
} while (pos2 !== -1);
|
11609
|
-
return true;
|
11610
|
-
}
|
11611
|
-
toString() {
|
11612
|
-
let result = "";
|
11613
|
-
let isHexOnly = false;
|
11614
|
-
for (let i = 0; i < this.value.length; i++) {
|
11615
|
-
isHexOnly = this.value[i].isHexOnly;
|
11616
|
-
let sidStr = this.value[i].toString();
|
11617
|
-
if (i !== 0)
|
11618
|
-
result = `${result}.`;
|
11619
|
-
if (isHexOnly) {
|
11620
|
-
sidStr = `{${sidStr}}`;
|
11621
|
-
result += sidStr;
|
11622
|
-
}
|
11623
|
-
else
|
11624
|
-
result += sidStr;
|
11625
|
-
}
|
11626
|
-
return result;
|
11627
|
-
}
|
11628
|
-
toJSON() {
|
11629
|
-
const object = {
|
11630
|
-
...super.toJSON(),
|
11631
|
-
value: this.toString(),
|
11632
|
-
sidArray: [],
|
11633
|
-
};
|
11634
|
-
for (let i = 0; i < this.value.length; i++)
|
11635
|
-
object.sidArray.push(this.value[i].toJSON());
|
11636
|
-
return object;
|
11637
|
-
}
|
11638
|
-
}
|
11639
|
-
LocalRelativeObjectIdentifierValueBlock.NAME = "RelativeObjectIdentifierValueBlock";
|
11640
|
-
|
11641
|
-
var _a$l;
|
11642
|
-
class RelativeObjectIdentifier extends BaseBlock {
|
11643
|
-
constructor(parameters = {}) {
|
11644
|
-
super(parameters, LocalRelativeObjectIdentifierValueBlock);
|
11645
|
-
this.idBlock.tagClass = 1;
|
11646
|
-
this.idBlock.tagNumber = 13;
|
11647
|
-
}
|
11648
|
-
getValue() {
|
11649
|
-
return this.valueBlock.toString();
|
11650
|
-
}
|
11651
|
-
setValue(value) {
|
11652
|
-
this.valueBlock.fromString(value);
|
11653
|
-
}
|
11654
|
-
onAsciiEncoding() {
|
11655
|
-
return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
|
11656
|
-
}
|
11657
|
-
toJSON() {
|
11658
|
-
return {
|
11659
|
-
...super.toJSON(),
|
11660
|
-
value: this.getValue(),
|
11661
|
-
};
|
11662
|
-
}
|
11663
|
-
}
|
11664
|
-
_a$l = RelativeObjectIdentifier;
|
11665
|
-
(() => {
|
11666
|
-
typeStore.RelativeObjectIdentifier = _a$l;
|
11667
|
-
})();
|
11668
|
-
RelativeObjectIdentifier.NAME = "RelativeObjectIdentifier";
|
11669
|
-
|
11670
|
-
var _a$k;
|
11671
|
-
class Sequence extends Constructed {
|
11672
|
-
constructor(parameters = {}) {
|
11673
|
-
super(parameters);
|
11674
|
-
this.idBlock.tagClass = 1;
|
11675
|
-
this.idBlock.tagNumber = 16;
|
11676
|
-
}
|
11677
|
-
}
|
11678
|
-
_a$k = Sequence;
|
11679
|
-
(() => {
|
11680
|
-
typeStore.Sequence = _a$k;
|
11681
|
-
})();
|
11682
|
-
Sequence.NAME = "SEQUENCE";
|
11683
|
-
|
11684
|
-
var _a$j;
|
11685
|
-
class Set extends Constructed {
|
11686
|
-
constructor(parameters = {}) {
|
11687
|
-
super(parameters);
|
11688
|
-
this.idBlock.tagClass = 1;
|
11689
|
-
this.idBlock.tagNumber = 17;
|
11690
|
-
}
|
11691
|
-
}
|
11692
|
-
_a$j = Set;
|
11693
|
-
(() => {
|
11694
|
-
typeStore.Set = _a$j;
|
11695
|
-
})();
|
11696
|
-
Set.NAME = "SET";
|
11697
|
-
|
11698
|
-
class LocalStringValueBlock extends HexBlock(ValueBlock) {
|
11699
|
-
constructor({ ...parameters } = {}) {
|
11700
|
-
super(parameters);
|
11701
|
-
this.isHexOnly = true;
|
11702
|
-
this.value = EMPTY_STRING;
|
11703
|
-
}
|
11704
|
-
toJSON() {
|
11705
|
-
return {
|
11706
|
-
...super.toJSON(),
|
11707
|
-
value: this.value,
|
11708
|
-
};
|
11709
|
-
}
|
11710
|
-
}
|
11711
|
-
LocalStringValueBlock.NAME = "StringValueBlock";
|
11712
|
-
|
11713
|
-
class LocalSimpleStringValueBlock extends LocalStringValueBlock {
|
11714
|
-
}
|
11715
|
-
LocalSimpleStringValueBlock.NAME = "SimpleStringValueBlock";
|
11716
|
-
|
11717
|
-
class LocalSimpleStringBlock extends BaseStringBlock {
|
11718
|
-
constructor({ ...parameters } = {}) {
|
11719
|
-
super(parameters, LocalSimpleStringValueBlock);
|
11720
|
-
}
|
11721
|
-
fromBuffer(inputBuffer) {
|
11722
|
-
this.valueBlock.value = String.fromCharCode.apply(null, BufferSourceConverter_1.toUint8Array(inputBuffer));
|
11723
|
-
}
|
11724
|
-
fromString(inputString) {
|
11725
|
-
const strLen = inputString.length;
|
11726
|
-
const view = this.valueBlock.valueHexView = new Uint8Array(strLen);
|
11727
|
-
for (let i = 0; i < strLen; i++)
|
11728
|
-
view[i] = inputString.charCodeAt(i);
|
11729
|
-
this.valueBlock.value = inputString;
|
11730
|
-
}
|
11731
|
-
}
|
11732
|
-
LocalSimpleStringBlock.NAME = "SIMPLE STRING";
|
11733
|
-
|
11734
|
-
class LocalUtf8StringValueBlock extends LocalSimpleStringBlock {
|
11735
|
-
fromBuffer(inputBuffer) {
|
11736
|
-
this.valueBlock.valueHexView = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
11737
|
-
try {
|
11738
|
-
this.valueBlock.value = Convert_1.ToUtf8String(inputBuffer);
|
11739
|
-
}
|
11740
|
-
catch (ex) {
|
11741
|
-
this.warnings.push(`Error during "decodeURIComponent": ${ex}, using raw string`);
|
11742
|
-
this.valueBlock.value = Convert_1.ToBinary(inputBuffer);
|
11743
|
-
}
|
11744
|
-
}
|
11745
|
-
fromString(inputString) {
|
11746
|
-
this.valueBlock.valueHexView = new Uint8Array(Convert_1.FromUtf8String(inputString));
|
11747
|
-
this.valueBlock.value = inputString;
|
11748
|
-
}
|
11749
|
-
}
|
11750
|
-
LocalUtf8StringValueBlock.NAME = "Utf8StringValueBlock";
|
11751
|
-
|
11752
|
-
var _a$i;
|
11753
|
-
class Utf8String extends LocalUtf8StringValueBlock {
|
11754
|
-
constructor(parameters = {}) {
|
11755
|
-
super(parameters);
|
11756
|
-
this.idBlock.tagClass = 1;
|
11757
|
-
this.idBlock.tagNumber = 12;
|
11758
|
-
}
|
11759
|
-
}
|
11760
|
-
_a$i = Utf8String;
|
11761
|
-
(() => {
|
11762
|
-
typeStore.Utf8String = _a$i;
|
11763
|
-
})();
|
11764
|
-
Utf8String.NAME = "UTF8String";
|
11765
|
-
|
11766
|
-
class LocalBmpStringValueBlock extends LocalSimpleStringBlock {
|
11767
|
-
fromBuffer(inputBuffer) {
|
11768
|
-
this.valueBlock.value = Convert_1.ToUtf16String(inputBuffer);
|
11769
|
-
this.valueBlock.valueHexView = BufferSourceConverter_1.toUint8Array(inputBuffer);
|
11770
|
-
}
|
11771
|
-
fromString(inputString) {
|
11772
|
-
this.valueBlock.value = inputString;
|
11773
|
-
this.valueBlock.valueHexView = new Uint8Array(Convert_1.FromUtf16String(inputString));
|
11774
|
-
}
|
11775
|
-
}
|
11776
|
-
LocalBmpStringValueBlock.NAME = "BmpStringValueBlock";
|
11777
|
-
|
11778
|
-
var _a$h;
|
11779
|
-
class BmpString extends LocalBmpStringValueBlock {
|
11780
|
-
constructor({ ...parameters } = {}) {
|
11781
|
-
super(parameters);
|
11782
|
-
this.idBlock.tagClass = 1;
|
11783
|
-
this.idBlock.tagNumber = 30;
|
11784
|
-
}
|
11785
|
-
}
|
11786
|
-
_a$h = BmpString;
|
11787
|
-
(() => {
|
11788
|
-
typeStore.BmpString = _a$h;
|
11789
|
-
})();
|
11790
|
-
BmpString.NAME = "BMPString";
|
11791
|
-
|
11792
|
-
class LocalUniversalStringValueBlock extends LocalSimpleStringBlock {
|
11793
|
-
fromBuffer(inputBuffer) {
|
11794
|
-
const copyBuffer = ArrayBuffer.isView(inputBuffer) ? inputBuffer.slice().buffer : inputBuffer.slice(0);
|
11795
|
-
const valueView = new Uint8Array(copyBuffer);
|
11796
|
-
for (let i = 0; i < valueView.length; i += 4) {
|
11797
|
-
valueView[i] = valueView[i + 3];
|
11798
|
-
valueView[i + 1] = valueView[i + 2];
|
11799
|
-
valueView[i + 2] = 0x00;
|
11800
|
-
valueView[i + 3] = 0x00;
|
11801
|
-
}
|
11802
|
-
this.valueBlock.value = String.fromCharCode.apply(null, new Uint32Array(copyBuffer));
|
11803
|
-
}
|
11804
|
-
fromString(inputString) {
|
11805
|
-
const strLength = inputString.length;
|
11806
|
-
const valueHexView = this.valueBlock.valueHexView = new Uint8Array(strLength * 4);
|
11807
|
-
for (let i = 0; i < strLength; i++) {
|
11808
|
-
const codeBuf = utilToBase(inputString.charCodeAt(i), 8);
|
11809
|
-
const codeView = new Uint8Array(codeBuf);
|
11810
|
-
if (codeView.length > 4)
|
11811
|
-
continue;
|
11812
|
-
const dif = 4 - codeView.length;
|
11813
|
-
for (let j = (codeView.length - 1); j >= 0; j--)
|
11814
|
-
valueHexView[i * 4 + j + dif] = codeView[j];
|
11815
|
-
}
|
11816
|
-
this.valueBlock.value = inputString;
|
11817
|
-
}
|
11818
|
-
}
|
11819
|
-
LocalUniversalStringValueBlock.NAME = "UniversalStringValueBlock";
|
11820
|
-
|
11821
|
-
var _a$g;
|
11822
|
-
class UniversalString extends LocalUniversalStringValueBlock {
|
11823
|
-
constructor({ ...parameters } = {}) {
|
11824
|
-
super(parameters);
|
11825
|
-
this.idBlock.tagClass = 1;
|
11826
|
-
this.idBlock.tagNumber = 28;
|
11827
|
-
}
|
11828
|
-
}
|
11829
|
-
_a$g = UniversalString;
|
11830
|
-
(() => {
|
11831
|
-
typeStore.UniversalString = _a$g;
|
11832
|
-
})();
|
11833
|
-
UniversalString.NAME = "UniversalString";
|
11834
|
-
|
11835
|
-
var _a$f;
|
11836
|
-
class NumericString extends LocalSimpleStringBlock {
|
11837
|
-
constructor(parameters = {}) {
|
11838
|
-
super(parameters);
|
11839
|
-
this.idBlock.tagClass = 1;
|
11840
|
-
this.idBlock.tagNumber = 18;
|
11841
|
-
}
|
11842
|
-
}
|
11843
|
-
_a$f = NumericString;
|
11844
|
-
(() => {
|
11845
|
-
typeStore.NumericString = _a$f;
|
11846
|
-
})();
|
11847
|
-
NumericString.NAME = "NumericString";
|
11848
|
-
|
11849
|
-
var _a$e;
|
11850
|
-
class PrintableString extends LocalSimpleStringBlock {
|
11851
|
-
constructor(parameters = {}) {
|
11852
|
-
super(parameters);
|
11853
|
-
this.idBlock.tagClass = 1;
|
11854
|
-
this.idBlock.tagNumber = 19;
|
11855
|
-
}
|
11856
|
-
}
|
11857
|
-
_a$e = PrintableString;
|
11858
|
-
(() => {
|
11859
|
-
typeStore.PrintableString = _a$e;
|
11860
|
-
})();
|
11861
|
-
PrintableString.NAME = "PrintableString";
|
11862
|
-
|
11863
|
-
var _a$d;
|
11864
|
-
class TeletexString extends LocalSimpleStringBlock {
|
11865
|
-
constructor(parameters = {}) {
|
11866
|
-
super(parameters);
|
11867
|
-
this.idBlock.tagClass = 1;
|
11868
|
-
this.idBlock.tagNumber = 20;
|
11869
|
-
}
|
11870
|
-
}
|
11871
|
-
_a$d = TeletexString;
|
11872
|
-
(() => {
|
11873
|
-
typeStore.TeletexString = _a$d;
|
11874
|
-
})();
|
11875
|
-
TeletexString.NAME = "TeletexString";
|
11876
|
-
|
11877
|
-
var _a$c;
|
11878
|
-
class VideotexString extends LocalSimpleStringBlock {
|
11879
|
-
constructor(parameters = {}) {
|
11880
|
-
super(parameters);
|
11881
|
-
this.idBlock.tagClass = 1;
|
11882
|
-
this.idBlock.tagNumber = 21;
|
11883
|
-
}
|
11884
|
-
}
|
11885
|
-
_a$c = VideotexString;
|
11886
|
-
(() => {
|
11887
|
-
typeStore.VideotexString = _a$c;
|
11888
|
-
})();
|
11889
|
-
VideotexString.NAME = "VideotexString";
|
11890
|
-
|
11891
|
-
var _a$b;
|
11892
|
-
class IA5String extends LocalSimpleStringBlock {
|
11893
|
-
constructor(parameters = {}) {
|
11894
|
-
super(parameters);
|
11895
|
-
this.idBlock.tagClass = 1;
|
11896
|
-
this.idBlock.tagNumber = 22;
|
11897
|
-
}
|
11898
|
-
}
|
11899
|
-
_a$b = IA5String;
|
11900
|
-
(() => {
|
11901
|
-
typeStore.IA5String = _a$b;
|
11902
|
-
})();
|
11903
|
-
IA5String.NAME = "IA5String";
|
11904
|
-
|
11905
|
-
var _a$a;
|
11906
|
-
class GraphicString extends LocalSimpleStringBlock {
|
11907
|
-
constructor(parameters = {}) {
|
11908
|
-
super(parameters);
|
11909
|
-
this.idBlock.tagClass = 1;
|
11910
|
-
this.idBlock.tagNumber = 25;
|
11911
|
-
}
|
11912
|
-
}
|
11913
|
-
_a$a = GraphicString;
|
11914
|
-
(() => {
|
11915
|
-
typeStore.GraphicString = _a$a;
|
11916
|
-
})();
|
11917
|
-
GraphicString.NAME = "GraphicString";
|
11918
|
-
|
11919
|
-
var _a$9;
|
11920
|
-
class VisibleString extends LocalSimpleStringBlock {
|
11921
|
-
constructor(parameters = {}) {
|
11922
|
-
super(parameters);
|
11923
|
-
this.idBlock.tagClass = 1;
|
11924
|
-
this.idBlock.tagNumber = 26;
|
11925
|
-
}
|
11926
|
-
}
|
11927
|
-
_a$9 = VisibleString;
|
11928
|
-
(() => {
|
11929
|
-
typeStore.VisibleString = _a$9;
|
11930
|
-
})();
|
11931
|
-
VisibleString.NAME = "VisibleString";
|
11932
|
-
|
11933
|
-
var _a$8;
|
11934
|
-
class GeneralString extends LocalSimpleStringBlock {
|
11935
|
-
constructor(parameters = {}) {
|
11936
|
-
super(parameters);
|
11937
|
-
this.idBlock.tagClass = 1;
|
11938
|
-
this.idBlock.tagNumber = 27;
|
11939
|
-
}
|
11940
|
-
}
|
11941
|
-
_a$8 = GeneralString;
|
11942
|
-
(() => {
|
11943
|
-
typeStore.GeneralString = _a$8;
|
11944
|
-
})();
|
11945
|
-
GeneralString.NAME = "GeneralString";
|
11946
|
-
|
11947
|
-
var _a$7;
|
11948
|
-
class CharacterString extends LocalSimpleStringBlock {
|
11949
|
-
constructor(parameters = {}) {
|
11950
|
-
super(parameters);
|
11951
|
-
this.idBlock.tagClass = 1;
|
11952
|
-
this.idBlock.tagNumber = 29;
|
11953
|
-
}
|
11954
|
-
}
|
11955
|
-
_a$7 = CharacterString;
|
11956
|
-
(() => {
|
11957
|
-
typeStore.CharacterString = _a$7;
|
11958
|
-
})();
|
11959
|
-
CharacterString.NAME = "CharacterString";
|
11960
|
-
|
11961
|
-
var _a$6;
|
11962
|
-
class UTCTime extends VisibleString {
|
11963
|
-
constructor({ value, valueDate, ...parameters } = {}) {
|
11964
|
-
super(parameters);
|
11965
|
-
this.year = 0;
|
11966
|
-
this.month = 0;
|
11967
|
-
this.day = 0;
|
11968
|
-
this.hour = 0;
|
11969
|
-
this.minute = 0;
|
11970
|
-
this.second = 0;
|
11971
|
-
if (value) {
|
11972
|
-
this.fromString(value);
|
11973
|
-
this.valueBlock.valueHexView = new Uint8Array(value.length);
|
11974
|
-
for (let i = 0; i < value.length; i++)
|
11975
|
-
this.valueBlock.valueHexView[i] = value.charCodeAt(i);
|
11976
|
-
}
|
11977
|
-
if (valueDate) {
|
11978
|
-
this.fromDate(valueDate);
|
11979
|
-
this.valueBlock.valueHexView = new Uint8Array(this.toBuffer());
|
11980
|
-
}
|
11981
|
-
this.idBlock.tagClass = 1;
|
11982
|
-
this.idBlock.tagNumber = 23;
|
11983
|
-
}
|
11984
|
-
fromBuffer(inputBuffer) {
|
11985
|
-
this.fromString(String.fromCharCode.apply(null, BufferSourceConverter_1.toUint8Array(inputBuffer)));
|
11986
|
-
}
|
11987
|
-
toBuffer() {
|
11988
|
-
const str = this.toString();
|
11989
|
-
const buffer = new ArrayBuffer(str.length);
|
11990
|
-
const view = new Uint8Array(buffer);
|
11991
|
-
for (let i = 0; i < str.length; i++)
|
11992
|
-
view[i] = str.charCodeAt(i);
|
11993
|
-
return buffer;
|
11994
|
-
}
|
11995
|
-
fromDate(inputDate) {
|
11996
|
-
this.year = inputDate.getUTCFullYear();
|
11997
|
-
this.month = inputDate.getUTCMonth() + 1;
|
11998
|
-
this.day = inputDate.getUTCDate();
|
11999
|
-
this.hour = inputDate.getUTCHours();
|
12000
|
-
this.minute = inputDate.getUTCMinutes();
|
12001
|
-
this.second = inputDate.getUTCSeconds();
|
12002
|
-
}
|
12003
|
-
toDate() {
|
12004
|
-
return (new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second)));
|
12005
|
-
}
|
12006
|
-
fromString(inputString) {
|
12007
|
-
const parser = /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig;
|
12008
|
-
const parserArray = parser.exec(inputString);
|
12009
|
-
if (parserArray === null) {
|
12010
|
-
this.error = "Wrong input string for conversion";
|
12011
|
-
return;
|
12012
|
-
}
|
12013
|
-
const year = parseInt(parserArray[1], 10);
|
12014
|
-
if (year >= 50)
|
12015
|
-
this.year = 1900 + year;
|
12016
|
-
else
|
12017
|
-
this.year = 2000 + year;
|
12018
|
-
this.month = parseInt(parserArray[2], 10);
|
12019
|
-
this.day = parseInt(parserArray[3], 10);
|
12020
|
-
this.hour = parseInt(parserArray[4], 10);
|
12021
|
-
this.minute = parseInt(parserArray[5], 10);
|
12022
|
-
this.second = parseInt(parserArray[6], 10);
|
12023
|
-
}
|
12024
|
-
toString(encoding = "iso") {
|
12025
|
-
if (encoding === "iso") {
|
12026
|
-
const outputArray = new Array(7);
|
12027
|
-
outputArray[0] = padNumber(((this.year < 2000) ? (this.year - 1900) : (this.year - 2000)), 2);
|
12028
|
-
outputArray[1] = padNumber(this.month, 2);
|
12029
|
-
outputArray[2] = padNumber(this.day, 2);
|
12030
|
-
outputArray[3] = padNumber(this.hour, 2);
|
12031
|
-
outputArray[4] = padNumber(this.minute, 2);
|
12032
|
-
outputArray[5] = padNumber(this.second, 2);
|
12033
|
-
outputArray[6] = "Z";
|
12034
|
-
return outputArray.join("");
|
12035
|
-
}
|
12036
|
-
return super.toString(encoding);
|
12037
|
-
}
|
12038
|
-
onAsciiEncoding() {
|
12039
|
-
return `${this.constructor.NAME} : ${this.toDate().toISOString()}`;
|
12040
|
-
}
|
12041
|
-
toJSON() {
|
12042
|
-
return {
|
12043
|
-
...super.toJSON(),
|
12044
|
-
year: this.year,
|
12045
|
-
month: this.month,
|
12046
|
-
day: this.day,
|
12047
|
-
hour: this.hour,
|
12048
|
-
minute: this.minute,
|
12049
|
-
second: this.second,
|
12050
|
-
};
|
12051
|
-
}
|
12052
|
-
}
|
12053
|
-
_a$6 = UTCTime;
|
12054
|
-
(() => {
|
12055
|
-
typeStore.UTCTime = _a$6;
|
12056
|
-
})();
|
12057
|
-
UTCTime.NAME = "UTCTime";
|
12058
|
-
|
12059
|
-
var _a$5;
|
12060
|
-
class GeneralizedTime extends UTCTime {
|
12061
|
-
constructor(parameters = {}) {
|
12062
|
-
var _b;
|
12063
|
-
super(parameters);
|
12064
|
-
(_b = this.millisecond) !== null && _b !== undefined ? _b : (this.millisecond = 0);
|
12065
|
-
this.idBlock.tagClass = 1;
|
12066
|
-
this.idBlock.tagNumber = 24;
|
12067
|
-
}
|
12068
|
-
fromDate(inputDate) {
|
12069
|
-
super.fromDate(inputDate);
|
12070
|
-
this.millisecond = inputDate.getUTCMilliseconds();
|
12071
|
-
}
|
12072
|
-
toDate() {
|
12073
|
-
return (new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond)));
|
12074
|
-
}
|
12075
|
-
fromString(inputString) {
|
12076
|
-
let isUTC = false;
|
12077
|
-
let timeString = "";
|
12078
|
-
let dateTimeString = "";
|
12079
|
-
let fractionPart = 0;
|
12080
|
-
let parser;
|
12081
|
-
let hourDifference = 0;
|
12082
|
-
let minuteDifference = 0;
|
12083
|
-
if (inputString[inputString.length - 1] === "Z") {
|
12084
|
-
timeString = inputString.substring(0, inputString.length - 1);
|
12085
|
-
isUTC = true;
|
12086
|
-
}
|
12087
|
-
else {
|
12088
|
-
const number = new Number(inputString[inputString.length - 1]);
|
12089
|
-
if (isNaN(number.valueOf()))
|
12090
|
-
throw new Error("Wrong input string for conversion");
|
12091
|
-
timeString = inputString;
|
12092
|
-
}
|
12093
|
-
if (isUTC) {
|
12094
|
-
if (timeString.indexOf("+") !== -1)
|
12095
|
-
throw new Error("Wrong input string for conversion");
|
12096
|
-
if (timeString.indexOf("-") !== -1)
|
12097
|
-
throw new Error("Wrong input string for conversion");
|
12098
|
-
}
|
12099
|
-
else {
|
12100
|
-
let multiplier = 1;
|
12101
|
-
let differencePosition = timeString.indexOf("+");
|
12102
|
-
let differenceString = "";
|
12103
|
-
if (differencePosition === -1) {
|
12104
|
-
differencePosition = timeString.indexOf("-");
|
12105
|
-
multiplier = -1;
|
12106
|
-
}
|
12107
|
-
if (differencePosition !== -1) {
|
12108
|
-
differenceString = timeString.substring(differencePosition + 1);
|
12109
|
-
timeString = timeString.substring(0, differencePosition);
|
12110
|
-
if ((differenceString.length !== 2) && (differenceString.length !== 4))
|
12111
|
-
throw new Error("Wrong input string for conversion");
|
12112
|
-
let number = parseInt(differenceString.substring(0, 2), 10);
|
12113
|
-
if (isNaN(number.valueOf()))
|
12114
|
-
throw new Error("Wrong input string for conversion");
|
12115
|
-
hourDifference = multiplier * number;
|
12116
|
-
if (differenceString.length === 4) {
|
12117
|
-
number = parseInt(differenceString.substring(2, 4), 10);
|
12118
|
-
if (isNaN(number.valueOf()))
|
12119
|
-
throw new Error("Wrong input string for conversion");
|
12120
|
-
minuteDifference = multiplier * number;
|
12121
|
-
}
|
12122
|
-
}
|
12123
|
-
}
|
12124
|
-
let fractionPointPosition = timeString.indexOf(".");
|
12125
|
-
if (fractionPointPosition === -1)
|
12126
|
-
fractionPointPosition = timeString.indexOf(",");
|
12127
|
-
if (fractionPointPosition !== -1) {
|
12128
|
-
const fractionPartCheck = new Number(`0${timeString.substring(fractionPointPosition)}`);
|
12129
|
-
if (isNaN(fractionPartCheck.valueOf()))
|
12130
|
-
throw new Error("Wrong input string for conversion");
|
12131
|
-
fractionPart = fractionPartCheck.valueOf();
|
12132
|
-
dateTimeString = timeString.substring(0, fractionPointPosition);
|
12133
|
-
}
|
12134
|
-
else
|
12135
|
-
dateTimeString = timeString;
|
12136
|
-
switch (true) {
|
12137
|
-
case (dateTimeString.length === 8):
|
12138
|
-
parser = /(\d{4})(\d{2})(\d{2})/ig;
|
12139
|
-
if (fractionPointPosition !== -1)
|
12140
|
-
throw new Error("Wrong input string for conversion");
|
12141
|
-
break;
|
12142
|
-
case (dateTimeString.length === 10):
|
12143
|
-
parser = /(\d{4})(\d{2})(\d{2})(\d{2})/ig;
|
12144
|
-
if (fractionPointPosition !== -1) {
|
12145
|
-
let fractionResult = 60 * fractionPart;
|
12146
|
-
this.minute = Math.floor(fractionResult);
|
12147
|
-
fractionResult = 60 * (fractionResult - this.minute);
|
12148
|
-
this.second = Math.floor(fractionResult);
|
12149
|
-
fractionResult = 1000 * (fractionResult - this.second);
|
12150
|
-
this.millisecond = Math.floor(fractionResult);
|
12151
|
-
}
|
12152
|
-
break;
|
12153
|
-
case (dateTimeString.length === 12):
|
12154
|
-
parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
|
12155
|
-
if (fractionPointPosition !== -1) {
|
12156
|
-
let fractionResult = 60 * fractionPart;
|
12157
|
-
this.second = Math.floor(fractionResult);
|
12158
|
-
fractionResult = 1000 * (fractionResult - this.second);
|
12159
|
-
this.millisecond = Math.floor(fractionResult);
|
12160
|
-
}
|
12161
|
-
break;
|
12162
|
-
case (dateTimeString.length === 14):
|
12163
|
-
parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
|
12164
|
-
if (fractionPointPosition !== -1) {
|
12165
|
-
const fractionResult = 1000 * fractionPart;
|
12166
|
-
this.millisecond = Math.floor(fractionResult);
|
12167
|
-
}
|
12168
|
-
break;
|
12169
|
-
default:
|
12170
|
-
throw new Error("Wrong input string for conversion");
|
12171
|
-
}
|
12172
|
-
const parserArray = parser.exec(dateTimeString);
|
12173
|
-
if (parserArray === null)
|
12174
|
-
throw new Error("Wrong input string for conversion");
|
12175
|
-
for (let j = 1; j < parserArray.length; j++) {
|
12176
|
-
switch (j) {
|
12177
|
-
case 1:
|
12178
|
-
this.year = parseInt(parserArray[j], 10);
|
12179
|
-
break;
|
12180
|
-
case 2:
|
12181
|
-
this.month = parseInt(parserArray[j], 10);
|
12182
|
-
break;
|
12183
|
-
case 3:
|
12184
|
-
this.day = parseInt(parserArray[j], 10);
|
12185
|
-
break;
|
12186
|
-
case 4:
|
12187
|
-
this.hour = parseInt(parserArray[j], 10) + hourDifference;
|
12188
|
-
break;
|
12189
|
-
case 5:
|
12190
|
-
this.minute = parseInt(parserArray[j], 10) + minuteDifference;
|
12191
|
-
break;
|
12192
|
-
case 6:
|
12193
|
-
this.second = parseInt(parserArray[j], 10);
|
12194
|
-
break;
|
12195
|
-
default:
|
12196
|
-
throw new Error("Wrong input string for conversion");
|
12197
|
-
}
|
12198
|
-
}
|
12199
|
-
if (isUTC === false) {
|
12200
|
-
const tempDate = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
|
12201
|
-
this.year = tempDate.getUTCFullYear();
|
12202
|
-
this.month = tempDate.getUTCMonth();
|
12203
|
-
this.day = tempDate.getUTCDay();
|
12204
|
-
this.hour = tempDate.getUTCHours();
|
12205
|
-
this.minute = tempDate.getUTCMinutes();
|
12206
|
-
this.second = tempDate.getUTCSeconds();
|
12207
|
-
this.millisecond = tempDate.getUTCMilliseconds();
|
12208
|
-
}
|
12209
|
-
}
|
12210
|
-
toString(encoding = "iso") {
|
12211
|
-
if (encoding === "iso") {
|
12212
|
-
const outputArray = [];
|
12213
|
-
outputArray.push(padNumber(this.year, 4));
|
12214
|
-
outputArray.push(padNumber(this.month, 2));
|
12215
|
-
outputArray.push(padNumber(this.day, 2));
|
12216
|
-
outputArray.push(padNumber(this.hour, 2));
|
12217
|
-
outputArray.push(padNumber(this.minute, 2));
|
12218
|
-
outputArray.push(padNumber(this.second, 2));
|
12219
|
-
if (this.millisecond !== 0) {
|
12220
|
-
outputArray.push(".");
|
12221
|
-
outputArray.push(padNumber(this.millisecond, 3));
|
12222
|
-
}
|
12223
|
-
outputArray.push("Z");
|
12224
|
-
return outputArray.join("");
|
12225
|
-
}
|
12226
|
-
return super.toString(encoding);
|
12227
|
-
}
|
12228
|
-
toJSON() {
|
12229
|
-
return {
|
12230
|
-
...super.toJSON(),
|
12231
|
-
millisecond: this.millisecond,
|
12232
|
-
};
|
12233
|
-
}
|
12234
|
-
}
|
12235
|
-
_a$5 = GeneralizedTime;
|
12236
|
-
(() => {
|
12237
|
-
typeStore.GeneralizedTime = _a$5;
|
12238
|
-
})();
|
12239
|
-
GeneralizedTime.NAME = "GeneralizedTime";
|
12240
|
-
|
12241
|
-
var _a$4;
|
12242
|
-
class DATE extends Utf8String {
|
12243
|
-
constructor(parameters = {}) {
|
12244
|
-
super(parameters);
|
12245
|
-
this.idBlock.tagClass = 1;
|
12246
|
-
this.idBlock.tagNumber = 31;
|
12247
|
-
}
|
12248
|
-
}
|
12249
|
-
_a$4 = DATE;
|
12250
|
-
(() => {
|
12251
|
-
typeStore.DATE = _a$4;
|
12252
|
-
})();
|
12253
|
-
DATE.NAME = "DATE";
|
12254
|
-
|
12255
|
-
var _a$3;
|
12256
|
-
class TimeOfDay extends Utf8String {
|
12257
|
-
constructor(parameters = {}) {
|
12258
|
-
super(parameters);
|
12259
|
-
this.idBlock.tagClass = 1;
|
12260
|
-
this.idBlock.tagNumber = 32;
|
12261
|
-
}
|
12262
|
-
}
|
12263
|
-
_a$3 = TimeOfDay;
|
12264
|
-
(() => {
|
12265
|
-
typeStore.TimeOfDay = _a$3;
|
12266
|
-
})();
|
12267
|
-
TimeOfDay.NAME = "TimeOfDay";
|
12268
|
-
|
12269
|
-
var _a$2;
|
12270
|
-
class DateTime extends Utf8String {
|
12271
|
-
constructor(parameters = {}) {
|
12272
|
-
super(parameters);
|
12273
|
-
this.idBlock.tagClass = 1;
|
12274
|
-
this.idBlock.tagNumber = 33;
|
12275
|
-
}
|
12276
|
-
}
|
12277
|
-
_a$2 = DateTime;
|
12278
|
-
(() => {
|
12279
|
-
typeStore.DateTime = _a$2;
|
12280
|
-
})();
|
12281
|
-
DateTime.NAME = "DateTime";
|
12282
|
-
|
12283
|
-
var _a$1;
|
12284
|
-
class Duration extends Utf8String {
|
12285
|
-
constructor(parameters = {}) {
|
12286
|
-
super(parameters);
|
12287
|
-
this.idBlock.tagClass = 1;
|
12288
|
-
this.idBlock.tagNumber = 34;
|
12289
|
-
}
|
12290
|
-
}
|
12291
|
-
_a$1 = Duration;
|
12292
|
-
(() => {
|
12293
|
-
typeStore.Duration = _a$1;
|
12294
|
-
})();
|
12295
|
-
Duration.NAME = "Duration";
|
12296
|
-
|
12297
|
-
var _a;
|
12298
|
-
class TIME extends Utf8String {
|
12299
|
-
constructor(parameters = {}) {
|
12300
|
-
super(parameters);
|
12301
|
-
this.idBlock.tagClass = 1;
|
12302
|
-
this.idBlock.tagNumber = 14;
|
12303
|
-
}
|
12304
|
-
}
|
12305
|
-
_a = TIME;
|
12306
|
-
(() => {
|
12307
|
-
typeStore.TIME = _a;
|
12308
|
-
})();
|
12309
|
-
TIME.NAME = "TIME";
|
9639
|
+
const TAG_MASK = parseInt('11111', 2);
|
9640
|
+
const LONG_LENGTH_MASK = parseInt('10000000', 2);
|
9641
|
+
const LONG_LENGTH_BYTES_MASK = parseInt('01111111', 2);
|
9642
|
+
const decoders = {
|
9643
|
+
0x2: readInteger,
|
9644
|
+
0x3: readBitString,
|
9645
|
+
0x5: readNull,
|
9646
|
+
0x6: readObjectIdentifier,
|
9647
|
+
0x10: readSequence,
|
9648
|
+
0x16: readSequence,
|
9649
|
+
0x30: readSequence
|
9650
|
+
};
|
9651
|
+
function decodeDer(buf, context = { offset: 0 }) {
|
9652
|
+
const tag = buf[context.offset] & TAG_MASK;
|
9653
|
+
context.offset++;
|
9654
|
+
if (decoders[tag] != null) {
|
9655
|
+
return decoders[tag](buf, context);
|
9656
|
+
}
|
9657
|
+
throw new Error('No decoder for tag ' + tag);
|
9658
|
+
}
|
9659
|
+
function readLength(buf, context) {
|
9660
|
+
let length = 0;
|
9661
|
+
if ((buf[context.offset] & LONG_LENGTH_MASK) === LONG_LENGTH_MASK) {
|
9662
|
+
// long length
|
9663
|
+
const count = buf[context.offset] & LONG_LENGTH_BYTES_MASK;
|
9664
|
+
let str = '0x';
|
9665
|
+
context.offset++;
|
9666
|
+
for (let i = 0; i < count; i++, context.offset++) {
|
9667
|
+
str += buf[context.offset].toString(16).padStart(2, '0');
|
9668
|
+
}
|
9669
|
+
length = parseInt(str, 16);
|
9670
|
+
}
|
9671
|
+
else {
|
9672
|
+
length = buf[context.offset];
|
9673
|
+
context.offset++;
|
9674
|
+
}
|
9675
|
+
return length;
|
9676
|
+
}
|
9677
|
+
function readSequence(buf, context) {
|
9678
|
+
readLength(buf, context);
|
9679
|
+
const entries = [];
|
9680
|
+
while (true) {
|
9681
|
+
if (context.offset >= buf.byteLength) {
|
9682
|
+
break;
|
9683
|
+
}
|
9684
|
+
const result = decodeDer(buf, context);
|
9685
|
+
if (result === null) {
|
9686
|
+
break;
|
9687
|
+
}
|
9688
|
+
entries.push(result);
|
9689
|
+
}
|
9690
|
+
return entries;
|
9691
|
+
}
|
9692
|
+
function readInteger(buf, context) {
|
9693
|
+
const length = readLength(buf, context);
|
9694
|
+
const start = context.offset;
|
9695
|
+
const end = context.offset + length;
|
9696
|
+
const vals = [];
|
9697
|
+
for (let i = start; i < end; i++) {
|
9698
|
+
if (i === start && buf[i] === 0) {
|
9699
|
+
continue;
|
9700
|
+
}
|
9701
|
+
vals.push(buf[i]);
|
9702
|
+
}
|
9703
|
+
context.offset += length;
|
9704
|
+
return Uint8Array.from(vals);
|
9705
|
+
}
|
9706
|
+
function readObjectIdentifier(buf, context) {
|
9707
|
+
const count = readLength(buf, context);
|
9708
|
+
// skip OID
|
9709
|
+
context.offset += count;
|
9710
|
+
return ['oid-unimplemented'];
|
9711
|
+
}
|
9712
|
+
function readNull(buf, context) {
|
9713
|
+
context.offset++;
|
9714
|
+
return null;
|
9715
|
+
}
|
9716
|
+
function readBitString(buf, context) {
|
9717
|
+
const length = readLength(buf, context);
|
9718
|
+
const unusedBits = buf[context.offset];
|
9719
|
+
context.offset++;
|
9720
|
+
const bytes = buf.subarray(context.offset, context.offset + length);
|
9721
|
+
context.offset += length;
|
9722
|
+
if (unusedBits !== 0) {
|
9723
|
+
// need to shift all bytes along by this many bits
|
9724
|
+
throw new Error('Unused bits in bit string is unimplemented');
|
9725
|
+
}
|
9726
|
+
return decodeDer(bytes, {
|
9727
|
+
offset: 0
|
9728
|
+
});
|
9729
|
+
}
|
9730
|
+
function encodeNumber(value) {
|
9731
|
+
let number = value.toString(16);
|
9732
|
+
if (number.length % 2 === 1) {
|
9733
|
+
number = '0' + number;
|
9734
|
+
}
|
9735
|
+
const array = new Uint8ArrayList();
|
9736
|
+
for (let i = 0; i < number.length; i += 2) {
|
9737
|
+
array.append(Uint8Array.from([parseInt(`${number[i]}${number[i + 1]}`, 16)]));
|
9738
|
+
}
|
9739
|
+
return array;
|
9740
|
+
}
|
9741
|
+
function encodeLength(bytes) {
|
9742
|
+
if (bytes.byteLength < 128) {
|
9743
|
+
return Uint8Array.from([bytes.byteLength]);
|
9744
|
+
}
|
9745
|
+
// long length
|
9746
|
+
const length = encodeNumber(bytes.byteLength);
|
9747
|
+
return new Uint8ArrayList(Uint8Array.from([
|
9748
|
+
length.byteLength | LONG_LENGTH_MASK
|
9749
|
+
]), length);
|
9750
|
+
}
|
9751
|
+
function encodeInteger(value) {
|
9752
|
+
const contents = new Uint8ArrayList();
|
9753
|
+
const mask = parseInt('10000000', 2);
|
9754
|
+
const positive = (value.subarray()[0] & mask) === mask;
|
9755
|
+
if (positive) {
|
9756
|
+
contents.append(Uint8Array.from([0]));
|
9757
|
+
}
|
9758
|
+
contents.append(value);
|
9759
|
+
return new Uint8ArrayList(Uint8Array.from([0x02]), encodeLength(contents), contents);
|
9760
|
+
}
|
9761
|
+
function encodeBitString(value) {
|
9762
|
+
// unused bits is always 0 with full-byte-only values
|
9763
|
+
const unusedBits = Uint8Array.from([0]);
|
9764
|
+
const contents = new Uint8ArrayList(unusedBits, value);
|
9765
|
+
return new Uint8ArrayList(Uint8Array.from([0x03]), encodeLength(contents), contents);
|
9766
|
+
}
|
9767
|
+
function encodeSequence(values) {
|
9768
|
+
const output = new Uint8ArrayList();
|
9769
|
+
for (const buf of values) {
|
9770
|
+
output.append(buf);
|
9771
|
+
}
|
9772
|
+
return new Uint8ArrayList(Uint8Array.from([0x30]), encodeLength(output), output);
|
9773
|
+
}
|
12310
9774
|
|
12311
9775
|
/**
|
12312
9776
|
* Signing a message failed
|
@@ -12354,16 +9818,6 @@ async function hashAndVerify$1(key, sig, msg) {
|
|
12354
9818
|
}, false, ['verify']);
|
12355
9819
|
return webcrypto.get().subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, publicKey, sig, msg instanceof Uint8Array ? msg : msg.subarray());
|
12356
9820
|
}
|
12357
|
-
function rsaKeySize(jwk) {
|
12358
|
-
if (jwk.kty !== 'RSA') {
|
12359
|
-
throw new InvalidParametersError('invalid key type');
|
12360
|
-
}
|
12361
|
-
else if (jwk.n == null) {
|
12362
|
-
throw new InvalidParametersError('invalid key modulus');
|
12363
|
-
}
|
12364
|
-
const bytes = fromString(jwk.n, 'base64url');
|
12365
|
-
return bytes.length * 8;
|
12366
|
-
}
|
12367
9821
|
|
12368
9822
|
class RSAPublicKey {
|
12369
9823
|
type = 'RSA';
|
@@ -12400,87 +9854,57 @@ class RSAPublicKey {
|
|
12400
9854
|
}
|
12401
9855
|
}
|
12402
9856
|
|
12403
|
-
const MAX_RSA_KEY_SIZE = 8192;
|
12404
9857
|
const SHA2_256_CODE = 0x12;
|
9858
|
+
const MAX_RSA_JWK_SIZE = 1062;
|
9859
|
+
const RSA_ALGORITHM_IDENTIFIER = Uint8Array.from([
|
9860
|
+
0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00
|
9861
|
+
]);
|
12405
9862
|
/**
|
12406
|
-
* Convert a PKIX in ASN1 DER format to a JWK key
|
9863
|
+
* Convert a PKIX in ASN1 DER format to a JWK public key
|
12407
9864
|
*/
|
12408
9865
|
function pkixToJwk(bytes) {
|
12409
|
-
const
|
12410
|
-
|
12411
|
-
|
12412
|
-
|
9866
|
+
const decoded = decodeDer(bytes, {
|
9867
|
+
offset: 0
|
9868
|
+
});
|
9869
|
+
// this looks fragile but DER is a canonical format so we are safe to have
|
9870
|
+
// deeply property chains like this
|
12413
9871
|
return {
|
12414
9872
|
kty: 'RSA',
|
12415
|
-
n:
|
12416
|
-
e:
|
9873
|
+
n: toString$1(decoded[1][0], 'base64url'),
|
9874
|
+
e: toString$1(decoded[1][1], 'base64url')
|
12417
9875
|
};
|
12418
9876
|
}
|
12419
9877
|
/**
|
12420
|
-
* Convert a JWK key to PKIX in ASN1 DER format
|
9878
|
+
* Convert a JWK public key to PKIX in ASN1 DER format
|
12421
9879
|
*/
|
12422
9880
|
function jwkToPkix(jwk) {
|
12423
9881
|
if (jwk.n == null || jwk.e == null) {
|
12424
9882
|
throw new InvalidParametersError('JWK was missing components');
|
12425
9883
|
}
|
12426
|
-
const
|
12427
|
-
|
12428
|
-
|
12429
|
-
|
12430
|
-
|
12431
|
-
|
12432
|
-
|
12433
|
-
|
12434
|
-
new Null()
|
12435
|
-
]
|
12436
|
-
}),
|
12437
|
-
// this appears to be a bug in asn1js.js - this should really be a Sequence
|
12438
|
-
// and not a BitString but it generates the same bytes as node-forge so 🤷♂️
|
12439
|
-
new BitString({
|
12440
|
-
valueHex: new Sequence({
|
12441
|
-
value: [
|
12442
|
-
Integer.fromBigInt(bufToBn(fromString(jwk.n, 'base64url'))),
|
12443
|
-
Integer.fromBigInt(bufToBn(fromString(jwk.e, 'base64url')))
|
12444
|
-
]
|
12445
|
-
}).toBER()
|
12446
|
-
})
|
12447
|
-
]
|
12448
|
-
});
|
12449
|
-
const der = root.toBER();
|
12450
|
-
return new Uint8Array(der, 0, der.byteLength);
|
12451
|
-
}
|
12452
|
-
function asn1jsIntegerToBase64(int) {
|
12453
|
-
let buf = int.valueBlock.valueHexView;
|
12454
|
-
// chrome rejects values with leading 0s
|
12455
|
-
while (buf[0] === 0) {
|
12456
|
-
buf = buf.subarray(1);
|
12457
|
-
}
|
12458
|
-
return toString$1(buf, 'base64url');
|
12459
|
-
}
|
12460
|
-
function bufToBn(u8) {
|
12461
|
-
const hex = [];
|
12462
|
-
u8.forEach(function (i) {
|
12463
|
-
let h = i.toString(16);
|
12464
|
-
if (h.length % 2 > 0) {
|
12465
|
-
h = `0${h}`;
|
12466
|
-
}
|
12467
|
-
hex.push(h);
|
12468
|
-
});
|
12469
|
-
return BigInt('0x' + hex.join(''));
|
9884
|
+
const subjectPublicKeyInfo = encodeSequence([
|
9885
|
+
RSA_ALGORITHM_IDENTIFIER,
|
9886
|
+
encodeBitString(encodeSequence([
|
9887
|
+
encodeInteger(fromString(jwk.n, 'base64url')),
|
9888
|
+
encodeInteger(fromString(jwk.e, 'base64url'))
|
9889
|
+
]))
|
9890
|
+
]);
|
9891
|
+
return subjectPublicKeyInfo.subarray();
|
12470
9892
|
}
|
12471
9893
|
/**
|
12472
9894
|
* Turn PKIX bytes to a PublicKey
|
12473
9895
|
*/
|
12474
|
-
function pkixToRSAPublicKey(bytes) {
|
12475
|
-
|
12476
|
-
if (rsaKeySize(jwk) > MAX_RSA_KEY_SIZE) {
|
9896
|
+
function pkixToRSAPublicKey(bytes, digest) {
|
9897
|
+
if (bytes.byteLength >= MAX_RSA_JWK_SIZE) {
|
12477
9898
|
throw new InvalidPublicKeyError('Key size is too large');
|
12478
9899
|
}
|
12479
|
-
const
|
12480
|
-
|
12481
|
-
|
12482
|
-
|
12483
|
-
|
9900
|
+
const jwk = pkixToJwk(bytes);
|
9901
|
+
if (digest == null) {
|
9902
|
+
const hash = sha256(PublicKey.encode({
|
9903
|
+
Type: KeyType.RSA,
|
9904
|
+
Data: bytes
|
9905
|
+
}));
|
9906
|
+
digest = create(SHA2_256_CODE, hash);
|
9907
|
+
}
|
12484
9908
|
return new RSAPublicKey(jwk, digest);
|
12485
9909
|
}
|
12486
9910
|
|
@@ -14396,7 +11820,7 @@ class EnrCreator {
|
|
14396
11820
|
}
|
14397
11821
|
}
|
14398
11822
|
|
14399
|
-
const version$2 = "logger/5.
|
11823
|
+
const version$2 = "logger/5.8.0";
|
14400
11824
|
|
14401
11825
|
let _permanentCensorErrors = false;
|
14402
11826
|
let _censorErrors = false;
|
@@ -14747,7 +12171,7 @@ class Logger {
|
|
14747
12171
|
Logger.errors = ErrorCode;
|
14748
12172
|
Logger.levels = LogLevel;
|
14749
12173
|
|
14750
|
-
const version$1 = "bytes/5.
|
12174
|
+
const version$1 = "bytes/5.8.0";
|
14751
12175
|
|
14752
12176
|
const logger$1 = new Logger(version$1);
|
14753
12177
|
///////////////////////////////
|
@@ -14901,7 +12325,7 @@ function hexlify(value, options) {
|
|
14901
12325
|
return logger$1.throwArgumentError("invalid hexlify value", "value", value);
|
14902
12326
|
}
|
14903
12327
|
|
14904
|
-
const version = "rlp/5.
|
12328
|
+
const version = "rlp/5.8.0";
|
14905
12329
|
|
14906
12330
|
const logger = new Logger(version);
|
14907
12331
|
function arrayifyInteger(value) {
|