@syncfusion/ej2-office-common 35.1.37

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.
Files changed (147) hide show
  1. package/.eslintrc.json +263 -0
  2. package/.prettierrc.json +5 -0
  3. package/README.md +167 -0
  4. package/api-extractor.json +35 -0
  5. package/core.js +4 -0
  6. package/dist/ej2-office-common.umd.min.js +11 -0
  7. package/dist/ej2-office-common.umd.min.js.map +1 -0
  8. package/dist/es6/ej2-office-common.es2015.js +6585 -0
  9. package/dist/es6/ej2-office-common.es2015.js.map +1 -0
  10. package/dist/es6/ej2-office-common.es5.js +7955 -0
  11. package/dist/es6/ej2-office-common.es5.js.map +1 -0
  12. package/dist/global/ej2-office-common.min.js +11 -0
  13. package/dist/global/ej2-office-common.min.js.map +1 -0
  14. package/dist/global/index.d.ts +14 -0
  15. package/encryption.js +4 -0
  16. package/features.js +4 -0
  17. package/global.json +6 -0
  18. package/index.js +4 -0
  19. package/license +10 -0
  20. package/nuget.config +7 -0
  21. package/package.json +23 -0
  22. package/src/all.d.ts +41 -0
  23. package/src/all.js +38 -0
  24. package/src/core/index.d.ts +6 -0
  25. package/src/core/index.js +6 -0
  26. package/src/core/xml/index.d.ts +7 -0
  27. package/src/core/xml/index.js +6 -0
  28. package/src/core/xml/model.d.ts +71 -0
  29. package/src/core/xml/model.js +20 -0
  30. package/src/encryption/agile-constants.d.ts +61 -0
  31. package/src/encryption/agile-constants.js +71 -0
  32. package/src/encryption/agile-encryption-info.d.ts +46 -0
  33. package/src/encryption/agile-encryption-info.js +333 -0
  34. package/src/encryption/agile-password.d.ts +8 -0
  35. package/src/encryption/agile-password.js +58 -0
  36. package/src/encryption/cfb-reader.d.ts +11 -0
  37. package/src/encryption/cfb-reader.js +345 -0
  38. package/src/encryption/crypto-primitives.d.ts +74 -0
  39. package/src/encryption/crypto-primitives.js +302 -0
  40. package/src/encryption/decrypt-encrypted-package.d.ts +16 -0
  41. package/src/encryption/decrypt-encrypted-package.js +138 -0
  42. package/src/encryption/encryption-info-xml.d.ts +21 -0
  43. package/src/encryption/encryption-info-xml.js +282 -0
  44. package/src/encryption/errors.d.ts +66 -0
  45. package/src/encryption/errors.js +124 -0
  46. package/src/encryption/index.d.ts +35 -0
  47. package/src/encryption/index.js +100 -0
  48. package/src/features/diagrams/constants.d.ts +83 -0
  49. package/src/features/diagrams/constants.js +101 -0
  50. package/src/features/diagrams/diagram-data-model.d.ts +148 -0
  51. package/src/features/diagrams/diagram-data-model.js +446 -0
  52. package/src/features/diagrams/diagram-parsers.d.ts +28 -0
  53. package/src/features/diagrams/diagram-parsers.js +182 -0
  54. package/src/features/diagrams/diagram-serializers.d.ts +20 -0
  55. package/src/features/diagrams/diagram-serializers.js +110 -0
  56. package/src/features/diagrams/diagram-views.d.ts +60 -0
  57. package/src/features/diagrams/diagram-views.js +213 -0
  58. package/src/features/diagrams/element-tree.d.ts +55 -0
  59. package/src/features/diagrams/element-tree.js +197 -0
  60. package/src/features/diagrams/errors.d.ts +17 -0
  61. package/src/features/diagrams/errors.js +59 -0
  62. package/src/features/diagrams/index.d.ts +17 -0
  63. package/src/features/diagrams/index.js +17 -0
  64. package/src/features/diagrams/smart-art-catalog.d.ts +107 -0
  65. package/src/features/diagrams/smart-art-catalog.js +422 -0
  66. package/src/features/diagrams/smart-art-diagram.d.ts +96 -0
  67. package/src/features/diagrams/smart-art-diagram.js +258 -0
  68. package/src/features/index.d.ts +11 -0
  69. package/src/features/index.js +11 -0
  70. package/src/features/ink/constants.d.ts +54 -0
  71. package/src/features/ink/constants.js +54 -0
  72. package/src/features/ink/index.d.ts +18 -0
  73. package/src/features/ink/index.js +15 -0
  74. package/src/features/ink/ink-effects.d.ts +35 -0
  75. package/src/features/ink/ink-effects.js +45 -0
  76. package/src/features/ink/ink-model.d.ts +237 -0
  77. package/src/features/ink/ink-model.js +406 -0
  78. package/src/features/ink/ink-parser.d.ts +59 -0
  79. package/src/features/ink/ink-parser.js +671 -0
  80. package/src/features/ink/ink-serializer.d.ts +16 -0
  81. package/src/features/ink/ink-serializer.js +281 -0
  82. package/src/features/ink/ink-units.d.ts +33 -0
  83. package/src/features/ink/ink-units.js +92 -0
  84. package/src/features/ink/ink-xml.d.ts +26 -0
  85. package/src/features/ink/ink-xml.js +165 -0
  86. package/src/features/ink/trace-codec.d.ts +127 -0
  87. package/src/features/ink/trace-codec.js +266 -0
  88. package/src/features/mathml/constants.d.ts +47 -0
  89. package/src/features/mathml/constants.js +47 -0
  90. package/src/features/mathml/errors.d.ts +50 -0
  91. package/src/features/mathml/errors.js +69 -0
  92. package/src/features/mathml/index.d.ts +30 -0
  93. package/src/features/mathml/index.js +22 -0
  94. package/src/features/mathml/math-factory.d.ts +26 -0
  95. package/src/features/mathml/math-factory.js +568 -0
  96. package/src/features/mathml/model/controls.d.ts +896 -0
  97. package/src/features/mathml/model/controls.js +1541 -0
  98. package/src/features/mathml/model/enums.d.ts +153 -0
  99. package/src/features/mathml/model/enums.js +133 -0
  100. package/src/features/mathml/model/math-element.d.ts +173 -0
  101. package/src/features/mathml/model/math-element.js +315 -0
  102. package/src/features/mathml/model/roots.d.ts +82 -0
  103. package/src/features/mathml/model/roots.js +177 -0
  104. package/src/features/mathml/openxml.d.ts +56 -0
  105. package/src/features/mathml/openxml.js +87 -0
  106. package/src/features/mathml/parse/math-parser.d.ts +43 -0
  107. package/src/features/mathml/parse/math-parser.js +636 -0
  108. package/src/features/mathml/serialize/math-serializer.d.ts +34 -0
  109. package/src/features/mathml/serialize/math-serializer.js +749 -0
  110. package/src/features/smart-art/diagram-xml.d.ts +63 -0
  111. package/src/features/smart-art/diagram-xml.js +459 -0
  112. package/src/features/smart-art/errors.d.ts +24 -0
  113. package/src/features/smart-art/errors.js +47 -0
  114. package/src/features/smart-art/index.d.ts +26 -0
  115. package/src/features/smart-art/index.js +26 -0
  116. package/src/features/smart-art/minimal-samples.d.ts +18 -0
  117. package/src/features/smart-art/minimal-samples.js +40 -0
  118. package/src/features/smart-art/mutators.d.ts +60 -0
  119. package/src/features/smart-art/mutators.js +566 -0
  120. package/src/features/smart-art/namespaces.d.ts +153 -0
  121. package/src/features/smart-art/namespaces.js +163 -0
  122. package/src/features/smart-art/package-graph.d.ts +61 -0
  123. package/src/features/smart-art/package-graph.js +413 -0
  124. package/src/features/smart-art/parse-colors.d.ts +19 -0
  125. package/src/features/smart-art/parse-colors.js +39 -0
  126. package/src/features/smart-art/parse-data.d.ts +21 -0
  127. package/src/features/smart-art/parse-data.js +121 -0
  128. package/src/features/smart-art/parse-layout.d.ts +20 -0
  129. package/src/features/smart-art/parse-layout.js +40 -0
  130. package/src/features/smart-art/parse-rel-ids.d.ts +71 -0
  131. package/src/features/smart-art/parse-rel-ids.js +233 -0
  132. package/src/features/smart-art/parse-style.d.ts +19 -0
  133. package/src/features/smart-art/parse-style.js +39 -0
  134. package/src/features/smart-art/point-text.d.ts +80 -0
  135. package/src/features/smart-art/point-text.js +424 -0
  136. package/src/features/smart-art/register.d.ts +33 -0
  137. package/src/features/smart-art/register.js +95 -0
  138. package/src/features/smart-art/serialize.d.ts +40 -0
  139. package/src/features/smart-art/serialize.js +48 -0
  140. package/src/features/smart-art/types.d.ts +403 -0
  141. package/src/features/smart-art/types.js +28 -0
  142. package/src/global.js +1 -0
  143. package/src/index.d.ts +21 -0
  144. package/src/index.js +22 -0
  145. package/tsconfig.build.json +13 -0
  146. package/tsconfig.harness.json +32 -0
  147. package/tslint.json +111 -0
@@ -0,0 +1,345 @@
1
+ /*
2
+ * Minimal OLE Compound File Binary (CFB) reader for OFFCRYPTO streams.
3
+ *
4
+ * @remarks
5
+ * Reads only what is required to extract root storage streams named
6
+ * `EncryptionInfo` and `EncryptedPackage` ([MS-OFFCRYPTO] §2.3.4.4,
7
+ * §2.3.4.10). Layout fields follow the well-known CFB header / FAT /
8
+ * directory structure used by ECMA-376 encrypted packages. This is **not** a
9
+ * full [MS-CFB] implementation — no local MS-CFB corpus is present under
10
+ * `specs/`; only the subset needed for named-stream extraction is coded.
11
+ *
12
+ * Fail closed on truncated headers, broken FAT chains, or missing streams.
13
+ *
14
+ * @private
15
+ */
16
+ var __values = (this && this.__values) || function (o) {
17
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
18
+ if (m) return m.call(o);
19
+ return {
20
+ next: function () {
21
+ if (o && i >= o.length) o = void 0;
22
+ return { value: o && o[i++], done: !o };
23
+ }
24
+ };
25
+ };
26
+ import { EncryptedPackageError } from './errors';
27
+ import { STREAM_ENCRYPTED_PACKAGE, STREAM_ENCRYPTION_INFO } from './agile-constants';
28
+ /** OLE CFB header signature ([MS-CFB]). */
29
+ var OLE_CFB_SIGNATURE = Object.freeze([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]);
30
+ /** Sector size shift for 512-byte sectors (common default). */
31
+ var SECTOR_SHIFT_512 = 9;
32
+ /** Sector size shift for 4096-byte sectors. */
33
+ var SECTOR_SHIFT_4096 = 12;
34
+ var ENDOFCHAIN = 0xfffffffe;
35
+ var FREESECT = 0xffffffff;
36
+ var FATSECT = 0xfffffffd;
37
+ var DIFSECT = 0xfffffffc;
38
+ var DIR_ENTRY_SIZE = 128;
39
+ var MAX_DIR_ENTRIES = 65536;
40
+ var MAX_FAT_SECTORS = 1048576;
41
+ /**
42
+ * Extracts `\EncryptionInfo` and `\EncryptedPackage` from an OFFCRYPTO CFB.
43
+ *
44
+ * @param input - Entire OLE compound-file bytes.
45
+ * @throws {EncryptedPackageError} When structure is incomplete or streams missing.
46
+ */
47
+ export function readOffCryptoStreams(input) {
48
+ if (input.byteLength < 512) {
49
+ throw new EncryptedPackageError('OFFCRYPTO package is truncated (CFB header)');
50
+ }
51
+ for (var i = 0; i < OLE_CFB_SIGNATURE.length; i++) {
52
+ if (input[i] !== OLE_CFB_SIGNATURE[i]) {
53
+ throw new EncryptedPackageError('Package is not a valid OLE compound file');
54
+ }
55
+ }
56
+ var view = new DataView(input.buffer, input.byteOffset, input.byteLength);
57
+ var sectorShift = view.getUint16(30, true);
58
+ if (sectorShift !== SECTOR_SHIFT_512 && sectorShift !== SECTOR_SHIFT_4096) {
59
+ throw new EncryptedPackageError('Unsupported CFB sector size');
60
+ }
61
+ var sectorSize = 1 << sectorShift;
62
+ var miniSectorShift = view.getUint16(32, true);
63
+ if (miniSectorShift !== 6) {
64
+ // Standard mini-sector is 64 bytes; refuse unknown layouts.
65
+ throw new EncryptedPackageError('Unsupported CFB mini-sector size');
66
+ }
67
+ var miniSectorSize = 1 << miniSectorShift;
68
+ var miniStreamCutoff = view.getUint32(56, true);
69
+ var firstDirSector = view.getUint32(48, true);
70
+ var firstMiniFatSector = view.getUint32(60, true);
71
+ var miniFatSectorCount = view.getUint32(64, true);
72
+ var fatSectorCount = view.getUint32(44, true);
73
+ var firstDifatSector = view.getUint32(68, true);
74
+ var difatSectorCount = view.getUint32(72, true);
75
+ if (fatSectorCount > MAX_FAT_SECTORS) {
76
+ throw new EncryptedPackageError('CFB FAT is unreasonably large');
77
+ }
78
+ var difat = [];
79
+ for (var i = 0; i < 109; i++) {
80
+ var sect = view.getUint32(76 + i * 4, true);
81
+ if (sect !== FREESECT) {
82
+ difat.push(sect);
83
+ }
84
+ }
85
+ var difatSect = firstDifatSector;
86
+ for (var n = 0; n < difatSectorCount; n++) {
87
+ if (difatSect === ENDOFCHAIN || difatSect === FREESECT) {
88
+ break;
89
+ }
90
+ var offset = sectorOffset(difatSect, sectorSize);
91
+ ensureRange(input, offset, sectorSize);
92
+ var entriesPerSector = sectorSize / 4 - 1;
93
+ for (var i = 0; i < entriesPerSector; i++) {
94
+ var sect = view.getUint32(offset + i * 4, true);
95
+ if (sect !== FREESECT) {
96
+ difat.push(sect);
97
+ }
98
+ }
99
+ difatSect = view.getUint32(offset + entriesPerSector * 4, true);
100
+ }
101
+ if (difat.length < fatSectorCount) {
102
+ throw new EncryptedPackageError('CFB DIFAT is truncated');
103
+ }
104
+ var fat = [];
105
+ for (var i = 0; i < fatSectorCount; i++) {
106
+ var fatSect = difat[i];
107
+ if (fatSect === undefined) {
108
+ throw new EncryptedPackageError('CFB DIFAT is truncated');
109
+ }
110
+ var offset = sectorOffset(fatSect, sectorSize);
111
+ ensureRange(input, offset, sectorSize);
112
+ var entries_1 = sectorSize / 4;
113
+ for (var j = 0; j < entries_1; j++) {
114
+ fat.push(view.getUint32(offset + j * 4, true));
115
+ }
116
+ }
117
+ var directoryBytes = readChain(input, view, fat, firstDirSector, sectorSize, undefined);
118
+ if (directoryBytes.byteLength < DIR_ENTRY_SIZE) {
119
+ throw new EncryptedPackageError('CFB directory is empty');
120
+ }
121
+ var entryCount = Math.min(Math.floor(directoryBytes.byteLength / DIR_ENTRY_SIZE), MAX_DIR_ENTRIES);
122
+ var dirView = new DataView(directoryBytes.buffer, directoryBytes.byteOffset, directoryBytes.byteLength);
123
+ var entries = [];
124
+ for (var i = 0; i < entryCount; i++) {
125
+ var base = i * DIR_ENTRY_SIZE;
126
+ var nameLength = dirView.getUint16(base + 64, true);
127
+ // nameLength includes the terminating null (2 bytes) when non-zero.
128
+ var charCount = nameLength >= 2 ? Math.floor((nameLength - 2) / 2) : 0;
129
+ var name_1 = '';
130
+ for (var c = 0; c < charCount && c < 32; c++) {
131
+ name_1 += String.fromCharCode(dirView.getUint16(base + c * 2, true));
132
+ }
133
+ var objectType = dirView.getUint8(base + 66);
134
+ var childId = dirView.getUint32(base + 76, true);
135
+ var startSector = dirView.getUint32(base + 116, true);
136
+ // Stream size is 8 bytes LE; OFFCRYPTO streams fit in lower 32 bits for our limits.
137
+ var streamSizeLow = dirView.getUint32(base + 120, true);
138
+ var streamSizeHigh = dirView.getUint32(base + 124, true);
139
+ if (streamSizeHigh !== 0) {
140
+ throw new EncryptedPackageError('OFFCRYPTO stream exceeds supported size');
141
+ }
142
+ entries.push({
143
+ name: name_1,
144
+ objectType: objectType,
145
+ startSector: startSector,
146
+ streamSize: streamSizeLow,
147
+ childId: childId,
148
+ });
149
+ }
150
+ var root = entries[0];
151
+ if (root === undefined || root.objectType !== 5) {
152
+ throw new EncryptedPackageError('CFB root storage is missing');
153
+ }
154
+ // Collect names under root via sibling tree walk (left/right/child).
155
+ var found = new Map();
156
+ var visited = new Set();
157
+ var walk = function (id) {
158
+ if (id > 0xfffffffa || id >= entries.length || visited.has(id)) {
159
+ return;
160
+ }
161
+ visited.add(id);
162
+ var e = entries[id];
163
+ if (e === undefined) {
164
+ return;
165
+ }
166
+ var left = dirView.getUint32(id * DIR_ENTRY_SIZE + 68, true);
167
+ var right = dirView.getUint32(id * DIR_ENTRY_SIZE + 72, true);
168
+ walk(left);
169
+ if (e.objectType === 2 /* stream */) {
170
+ found.set(e.name, e);
171
+ }
172
+ walk(right);
173
+ if (e.objectType === 1 /* storage */ || e.objectType === 5 /* root */) {
174
+ walk(e.childId);
175
+ }
176
+ };
177
+ walk(root.childId);
178
+ var infoEntry = found.get(STREAM_ENCRYPTION_INFO);
179
+ var pkgEntry = found.get(STREAM_ENCRYPTED_PACKAGE);
180
+ if (infoEntry === undefined || pkgEntry === undefined) {
181
+ throw new EncryptedPackageError('OFFCRYPTO streams EncryptionInfo and/or EncryptedPackage are missing');
182
+ }
183
+ var miniFat;
184
+ var miniStream;
185
+ var readStream = function (entry) {
186
+ if (entry.streamSize === 0) {
187
+ return new Uint8Array(0);
188
+ }
189
+ if (entry.streamSize < miniStreamCutoff && entry !== root) {
190
+ if (miniFat === undefined) {
191
+ miniFat = readMiniFat(input, view, fat, firstMiniFatSector, miniFatSectorCount, sectorSize);
192
+ // Root stream size may be larger than mini data; chain until end.
193
+ miniStream = readChain(input, view, fat, root.startSector, sectorSize, undefined);
194
+ }
195
+ if (miniStream === undefined) {
196
+ throw new EncryptedPackageError('CFB mini-stream is unavailable');
197
+ }
198
+ return readMiniChain(miniStream, miniFat, entry.startSector, miniSectorSize, entry.streamSize);
199
+ }
200
+ return readChain(input, view, fat, entry.startSector, sectorSize, entry.streamSize);
201
+ };
202
+ return {
203
+ encryptionInfo: readStream(infoEntry),
204
+ encryptedPackage: readStream(pkgEntry),
205
+ };
206
+ }
207
+ function sectorOffset(sectorIndex, sectorSize) {
208
+ // Sector 0 starts after the 512-byte header for 512-byte sectors; for 4096,
209
+ // header occupies the first sector region — offset is still (sector+1)*size
210
+ // relative to file start for standard CFB.
211
+ return (sectorIndex + 1) * sectorSize;
212
+ }
213
+ function ensureRange(input, offset, length) {
214
+ if (offset < 0 || length < 0 || offset + length > input.byteLength) {
215
+ throw new EncryptedPackageError('OFFCRYPTO package is truncated (CFB sector)');
216
+ }
217
+ }
218
+ function readChain(input, view, fat, startSector, sectorSize, maxBytes) {
219
+ if (startSector === ENDOFCHAIN || startSector === FREESECT) {
220
+ return new Uint8Array(0);
221
+ }
222
+ var chunks = [];
223
+ var total = 0;
224
+ var sector = startSector;
225
+ var guard = 0;
226
+ var maxGuard = fat.length + 2;
227
+ while (sector !== ENDOFCHAIN && sector !== FREESECT) {
228
+ if (guard++ > maxGuard) {
229
+ throw new EncryptedPackageError('CFB FAT chain is cyclic or unbounded');
230
+ }
231
+ if (sector === FATSECT || sector === DIFSECT) {
232
+ throw new EncryptedPackageError('CFB FAT chain contains reserved sector');
233
+ }
234
+ if (sector < 0 || sector >= fat.length) {
235
+ // Allow reading last data sector without FAT entry for short files: still need bounds.
236
+ var offsetTry = sectorOffset(sector, sectorSize);
237
+ if (offsetTry + sectorSize > input.byteLength && offsetTry >= input.byteLength) {
238
+ throw new EncryptedPackageError('CFB FAT chain sector out of range');
239
+ }
240
+ }
241
+ var offset = sectorOffset(sector, sectorSize);
242
+ ensureRange(input, offset, Math.min(sectorSize, input.byteLength - offset));
243
+ var take = Math.min(sectorSize, input.byteLength - offset);
244
+ var slice = input.subarray(offset, offset + take);
245
+ chunks.push(slice);
246
+ total += slice.byteLength;
247
+ if (maxBytes !== undefined && total >= maxBytes) {
248
+ break;
249
+ }
250
+ if (sector >= fat.length) {
251
+ throw new EncryptedPackageError('CFB FAT chain sector out of range');
252
+ }
253
+ var nextSector = fat[sector];
254
+ if (nextSector === undefined) {
255
+ throw new EncryptedPackageError('CFB FAT chain sector out of range');
256
+ }
257
+ sector = nextSector;
258
+ }
259
+ var out = concat(chunks);
260
+ if (maxBytes !== undefined) {
261
+ if (out.byteLength < maxBytes) {
262
+ throw new EncryptedPackageError('OFFCRYPTO stream data is truncated');
263
+ }
264
+ return out.subarray(0, maxBytes);
265
+ }
266
+ return out;
267
+ }
268
+ function readMiniFat(input, view, fat, firstMiniFatSector, miniFatSectorCount, sectorSize) {
269
+ if (miniFatSectorCount === 0 || firstMiniFatSector === ENDOFCHAIN) {
270
+ return [];
271
+ }
272
+ var bytes = readChain(input, view, fat, firstMiniFatSector, sectorSize, miniFatSectorCount * sectorSize);
273
+ var dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
274
+ var entries = [];
275
+ for (var i = 0; i + 4 <= bytes.byteLength; i += 4) {
276
+ entries.push(dv.getUint32(i, true));
277
+ }
278
+ return entries;
279
+ }
280
+ function readMiniChain(miniStream, miniFat, startSector, miniSectorSize, streamSize) {
281
+ var chunks = [];
282
+ var total = 0;
283
+ var sector = startSector;
284
+ var guard = 0;
285
+ var maxGuard = miniFat.length + 2;
286
+ while (sector !== ENDOFCHAIN && sector !== FREESECT && total < streamSize) {
287
+ if (guard++ > maxGuard) {
288
+ throw new EncryptedPackageError('CFB mini-FAT chain is cyclic or unbounded');
289
+ }
290
+ var offset = sector * miniSectorSize;
291
+ if (offset >= miniStream.byteLength) {
292
+ throw new EncryptedPackageError('CFB mini-stream is truncated');
293
+ }
294
+ var take = Math.min(miniSectorSize, miniStream.byteLength - offset, streamSize - total);
295
+ chunks.push(miniStream.subarray(offset, offset + take));
296
+ total += take;
297
+ if (sector >= miniFat.length) {
298
+ throw new EncryptedPackageError('CFB mini-FAT sector out of range');
299
+ }
300
+ var nextMini = miniFat[sector];
301
+ if (nextMini === undefined) {
302
+ throw new EncryptedPackageError('CFB mini-FAT sector out of range');
303
+ }
304
+ sector = nextMini;
305
+ }
306
+ var out = concat(chunks);
307
+ if (out.byteLength < streamSize) {
308
+ throw new EncryptedPackageError('OFFCRYPTO mini-stream data is truncated');
309
+ }
310
+ return out.subarray(0, streamSize);
311
+ }
312
+ function concat(chunks) {
313
+ var e_1, _a, e_2, _b;
314
+ var total = 0;
315
+ try {
316
+ for (var chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next(); !chunks_1_1.done; chunks_1_1 = chunks_1.next()) {
317
+ var c = chunks_1_1.value;
318
+ total += c.byteLength;
319
+ }
320
+ }
321
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
322
+ finally {
323
+ try {
324
+ if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1.return)) _a.call(chunks_1);
325
+ }
326
+ finally { if (e_1) throw e_1.error; }
327
+ }
328
+ var out = new Uint8Array(total);
329
+ var offset = 0;
330
+ try {
331
+ for (var chunks_2 = __values(chunks), chunks_2_1 = chunks_2.next(); !chunks_2_1.done; chunks_2_1 = chunks_2.next()) {
332
+ var c = chunks_2_1.value;
333
+ out.set(c, offset);
334
+ offset += c.byteLength;
335
+ }
336
+ }
337
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
338
+ finally {
339
+ try {
340
+ if (chunks_2_1 && !chunks_2_1.done && (_b = chunks_2.return)) _b.call(chunks_2);
341
+ }
342
+ finally { if (e_2) throw e_2.error; }
343
+ }
344
+ return out;
345
+ }
@@ -0,0 +1,74 @@
1
+ /** Hash algorithm names as in EncryptionInfo XML ([MS-OFFCRYPTO] §2.3.4.10). */
2
+ export declare type AgileHashName = 'SHA-1' | 'SHA256' | 'SHA384' | 'SHA512';
3
+ /**
4
+ * Maps OFFCRYPTO hashAlgorithm attribute to an internal name.
5
+ *
6
+ * @throws {UnsupportedEncryptionError} When the algorithm is not in the v1 set.
7
+ */
8
+ export declare function resolveHashAlgorithm(name: string): AgileHashName;
9
+ /**
10
+ * Validates cipherAlgorithm + cipherChaining for v1 (AES + CBC only).
11
+ *
12
+ * @throws {UnsupportedEncryptionError} When not AES/CBC.
13
+ */
14
+ export declare function assertSupportedCipher(cipherAlgorithm: string, cipherChaining: string): void;
15
+ /**
16
+ * Validates AES keyBits (128 / 192 / 256).
17
+ *
18
+ * @throws {UnsupportedEncryptionError} When key length is not a supported AES size.
19
+ */
20
+ export declare function assertAesKeyBits(keyBits: number): void;
21
+ /** Digest length in bytes for a resolved hash algorithm. */
22
+ export declare function hashDigestLength(hash: AgileHashName): number;
23
+ /** One-shot hash. */
24
+ export declare function hashBytes(hash: AgileHashName, data: Uint8Array): Uint8Array;
25
+ /** HMAC over message with key (DataIntegrity §2.3.4.14). */
26
+ export declare function hmacBytes(hash: AgileHashName, key: Uint8Array, message: Uint8Array): Uint8Array;
27
+ /**
28
+ * Concatenates byte arrays.
29
+ *
30
+ * @public
31
+ */
32
+ export declare function concatBytes(...parts: Uint8Array[]): Uint8Array;
33
+ /**
34
+ * Encodes a JavaScript string as UTF-16LE (Unicode password bytes, §2.3.4.11).
35
+ */
36
+ export declare function encodePasswordUtf16Le(password: string): Uint8Array;
37
+ /**
38
+ * Password-based encryption key (§2.3.4.11).
39
+ *
40
+ * H0 = H(salt + password); Hn = H(iterator LE u32 + Hn-1) for spinCount iterations;
41
+ * Hfinal = H(Hn + blockKey); pad/truncate to keyBits/8 with 0x36.
42
+ */
43
+ export declare function deriveAgileKey(hash: AgileHashName, salt: Uint8Array, passwordUtf16Le: Uint8Array, spinCount: number, blockKey: Uint8Array, keyBits: number): Uint8Array;
44
+ /**
45
+ * Initialization vector (§2.3.4.12).
46
+ *
47
+ * With blockKey: IV = H(keySalt + blockKey); without: IV = keySalt.
48
+ * Pad/truncate to blockSize with 0x36.
49
+ */
50
+ export declare function deriveAgileIv(hash: AgileHashName, keySalt: Uint8Array, blockKey: Uint8Array | undefined, blockSize: number): Uint8Array;
51
+ /**
52
+ * AES-CBC decrypt with zero padding (no PKCS #7 strip).
53
+ *
54
+ * @param key - AES key (16/24/32 bytes).
55
+ * @param iv - IV of blockSize bytes (AES block is 16; OFFCRYPTO blockSize is 16 for AES).
56
+ * @param ciphertext - Length MUST be a multiple of 16.
57
+ * @returns Plaintext of the same length as ciphertext (including zero pad).
58
+ */
59
+ export declare function aesCbcDecrypt(key: Uint8Array, iv: Uint8Array, ciphertext: Uint8Array): Uint8Array;
60
+ /**
61
+ * AES-CBC encrypt with zero padding (no PKCS #7).
62
+ *
63
+ * @remarks
64
+ * Used by test fixture builders and host encrypt harnesses. Same zero-pad
65
+ * rules as decrypt ([MS-OFFCRYPTO] §2.3.4.13 / §2.3.4.15).
66
+ *
67
+ * @public
68
+ */
69
+ export declare function aesCbcEncrypt(key: Uint8Array, iv: Uint8Array, plaintext: Uint8Array): Uint8Array;
70
+ /**
71
+ * Constant-time comparison of two equal-length buffers.
72
+ * Returns false when lengths differ (not constant-time on length).
73
+ */
74
+ export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;