diff --git a/src/Database.ts b/src/Database.ts index db8a080f..6eab25ce 100644 --- a/src/Database.ts +++ b/src/Database.ts @@ -1,9 +1,9 @@ -import { CodecHandler, createCodecHandler } from "./codec-handler/index.js"; +import { type CodecHandler, createCodecHandler } from "./codec-handler/index.js"; import { decryptRC4 } from "./crypto/index.js"; import { readDateTime } from "./data/datetime.js"; -import { getJetFormat, JetFormat } from "./JetFormat/index.js"; +import { getJetFormat, type JetFormat } from "./JetFormat/index.js"; import { PageType, assertPageType } from "./PageType.js"; -import { SortOrder } from "./types.js"; +import type { SortOrder } from "./types.js"; import { uncompressText } from "./unicodeCompression.js"; import { isEmptyBuffer, xor } from "./util.js"; diff --git a/src/JetFormat/Jet12Format.ts b/src/JetFormat/Jet12Format.ts index a1317507..77a97ab8 100644 --- a/src/JetFormat/Jet12Format.ts +++ b/src/JetFormat/Jet12Format.ts @@ -1,7 +1,7 @@ import { jet4Format } from "./Jet4Format.js"; -import { CodecType, JetFormat } from "./types.js"; +import { CodecType, type JetFormat } from "./types.js"; export const jet12Format: JetFormat = { ...jet4Format, codecType: CodecType.OFFICE, -}; \ No newline at end of file +}; diff --git a/src/JetFormat/Jet14Format.ts b/src/JetFormat/Jet14Format.ts index 0735723f..e870c904 100644 --- a/src/JetFormat/Jet14Format.ts +++ b/src/JetFormat/Jet14Format.ts @@ -1,6 +1,6 @@ import { GENERAL_SORT_ORDER } from "../SortOrder.js"; import { jet12Format } from "./Jet12Format.js"; -import { JetFormat } from "./types.js"; +import type { JetFormat } from "./types.js"; export const jet14Format: JetFormat = { ...jet12Format, diff --git a/src/JetFormat/Jet15Format.ts b/src/JetFormat/Jet15Format.ts index af2a22f4..dbb14c8a 100644 --- a/src/JetFormat/Jet15Format.ts +++ b/src/JetFormat/Jet15Format.ts @@ -1,4 +1,4 @@ import { jet14Format } from "./Jet14Format.js"; -import { JetFormat } from "./types.js"; +import type { JetFormat } from "./types.js"; export const jet15Format: JetFormat = jet14Format; diff --git a/src/JetFormat/Jet16Format.ts b/src/JetFormat/Jet16Format.ts index 143d3104..039ce26e 100644 --- a/src/JetFormat/Jet16Format.ts +++ b/src/JetFormat/Jet16Format.ts @@ -1,4 +1,4 @@ import { jet15Format } from "./Jet15Format.js"; -import { JetFormat } from "./types.js"; +import type { JetFormat } from "./types.js"; export const jet16Format: JetFormat = jet15Format; diff --git a/src/JetFormat/Jet17Format.ts b/src/JetFormat/Jet17Format.ts index dca27386..cdc8264b 100644 --- a/src/JetFormat/Jet17Format.ts +++ b/src/JetFormat/Jet17Format.ts @@ -1,4 +1,4 @@ import { jet16Format } from "./Jet16Format.js"; -import { JetFormat } from "./types.js"; +import type { JetFormat } from "./types.js"; export const jet17Format: JetFormat = jet16Format; diff --git a/src/JetFormat/Jet3Format.ts b/src/JetFormat/Jet3Format.ts index d620f57a..089be497 100644 --- a/src/JetFormat/Jet3Format.ts +++ b/src/JetFormat/Jet3Format.ts @@ -1,5 +1,5 @@ import { GENERAL_97_SORT_ORDER } from "../SortOrder.js"; -import { CodecType, JetFormat } from "./types.js"; +import { CodecType, type JetFormat } from "./types.js"; export const jet3Format: JetFormat = { codecType: CodecType.JET, diff --git a/src/JetFormat/Jet4Format.ts b/src/JetFormat/Jet4Format.ts index b3a8d172..a57f6e9f 100644 --- a/src/JetFormat/Jet4Format.ts +++ b/src/JetFormat/Jet4Format.ts @@ -1,9 +1,9 @@ import { GENERAL_LEGACY_SORT_ORDER } from "../SortOrder.js"; -import { CodecType, JetFormat } from "./types.js"; +import { CodecType, type JetFormat } from "./types.js"; export const jet4Format: JetFormat = { codecType: CodecType.JET, - + pageSize: 4096, textEncoding: "ucs-2", diff --git a/src/JetFormat/MSISAMFormat.ts b/src/JetFormat/MSISAMFormat.ts index 2b7b692b..43cae602 100644 --- a/src/JetFormat/MSISAMFormat.ts +++ b/src/JetFormat/MSISAMFormat.ts @@ -1,5 +1,5 @@ import { jet4Format } from "./Jet4Format.js"; -import { CodecType, JetFormat } from "./types.js"; +import { CodecType, type JetFormat } from "./types.js"; export const msisamFormat: JetFormat = { ...jet4Format, diff --git a/src/JetFormat/index.ts b/src/JetFormat/index.ts index d77db0a7..4b5789a6 100644 --- a/src/JetFormat/index.ts +++ b/src/JetFormat/index.ts @@ -6,7 +6,7 @@ import { jet17Format } from "./Jet17Format.js"; import { jet3Format } from "./Jet3Format.js"; import { jet4Format } from "./Jet4Format.js"; import { msisamFormat } from "./MSISAMFormat.js"; -import { JetFormat } from "./types.js"; +import type { JetFormat } from "./types.js"; export type { JetFormat } from "./types.js"; diff --git a/src/JetFormat/types.ts b/src/JetFormat/types.ts index 4b87cee0..f89b530a 100644 --- a/src/JetFormat/types.ts +++ b/src/JetFormat/types.ts @@ -1,4 +1,4 @@ -import { SortOrder } from "../types.js"; +import type { SortOrder } from "../types.js"; export interface JetFormat { codecType: CodecType; diff --git a/src/MDBReader.ts b/src/MDBReader.ts index 3f2392bd..8941b45a 100644 --- a/src/MDBReader.ts +++ b/src/MDBReader.ts @@ -1,8 +1,8 @@ import { Database } from "./Database.js"; import { PageType, assertPageType } from "./PageType.js"; -import { SysObject, isSysObjectType, isSystemObject, SysObjectTypes } from "./SysObject.js"; +import { type SysObject, isSysObjectType, isSystemObject, SysObjectTypes } from "./SysObject.js"; import { Table } from "./Table.js"; -import { SortOrder } from "./types.js"; +import type { SortOrder } from "./types.js"; const MSYS_OBJECTS_TABLE = "MSysObjects"; const MSYS_OBJECTS_PAGE = 2; diff --git a/src/SortOrder.ts b/src/SortOrder.ts index afcf0b88..51177697 100644 --- a/src/SortOrder.ts +++ b/src/SortOrder.ts @@ -1,4 +1,4 @@ -import { SortOrder } from "./types.js"; +import type { SortOrder } from "./types.js"; const GENERAL_SORT_ORDER_VALUE = 1033; diff --git a/src/Table.ts b/src/Table.ts index 3365d44d..bf578c75 100644 --- a/src/Table.ts +++ b/src/Table.ts @@ -1,9 +1,9 @@ import { ColumnTypes } from "./index.js"; -import { Column, ColumnDefinition, getColumnType, parseColumnFlags } from "./column.js"; +import { type Column, type ColumnDefinition, getColumnType, parseColumnFlags } from "./column.js"; import { readFieldValue } from "./data/index.js"; import { Database } from "./Database.js"; import { PageType, assertPageType } from "./PageType.js"; -import { Value } from "./types.js"; +import type { Value } from "./types.js"; import { uncompressText } from "./unicodeCompression.js"; import { findMapPages } from "./usage-map.js"; import { getBitmapValue, roundToFullByte } from "./util.js"; diff --git a/src/codec-handler/create.ts b/src/codec-handler/create.ts index f377cbc8..7d7bed2a 100644 --- a/src/codec-handler/create.ts +++ b/src/codec-handler/create.ts @@ -1,4 +1,4 @@ -import { CodecHandler } from "./index.js"; +import type { CodecHandler } from "./index.js"; import { getJetFormat } from "../JetFormat/index.js"; import { CodecType } from "../JetFormat/types.js"; import { createIdentityHandler } from "./handlers/identity.js"; diff --git a/src/codec-handler/handlers/identity.ts b/src/codec-handler/handlers/identity.ts index 6fd86efb..5d2e0dab 100644 --- a/src/codec-handler/handlers/identity.ts +++ b/src/codec-handler/handlers/identity.ts @@ -1,8 +1,8 @@ -import { CodecHandler } from "../types.js"; +import type { CodecHandler } from "../types.js"; export function createIdentityHandler(): CodecHandler { return { decryptPage: (b) => b, - verifyPassword: () => true + verifyPassword: () => true, }; } diff --git a/src/codec-handler/handlers/jet.ts b/src/codec-handler/handlers/jet.ts index d31296fe..5d1c8251 100644 --- a/src/codec-handler/handlers/jet.ts +++ b/src/codec-handler/handlers/jet.ts @@ -1,8 +1,8 @@ -import { CodecHandler } from "../index.js"; +import type { CodecHandler } from "../index.js"; import { decryptRC4 } from "../../crypto/index.js"; import { isEmptyBuffer } from "../../util.js"; import { createIdentityHandler } from "./identity.js"; -import { DecryptPage } from "../types.js"; +import type { DecryptPage } from "../types.js"; import { getPageEncodingKey } from "../util.js"; const KEY_OFFSET = 0x3e; // 62 diff --git a/src/codec-handler/handlers/office/EncryptionHeader.ts b/src/codec-handler/handlers/office/EncryptionHeader.ts index a8959110..cc99b6ee 100644 --- a/src/codec-handler/handlers/office/EncryptionHeader.ts +++ b/src/codec-handler/handlers/office/EncryptionHeader.ts @@ -1,6 +1,6 @@ import { isInRange } from "../../../util.js"; -import { CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js"; -import { HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js"; +import { type CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js"; +import { type HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js"; const FLAGS_OFFSET = 0; const CRYPTO_OFFSET = 8; diff --git a/src/codec-handler/handlers/office/EncryptionVerifier.ts b/src/codec-handler/handlers/office/EncryptionVerifier.ts index dda7f66e..3cdcbaf1 100644 --- a/src/codec-handler/handlers/office/EncryptionVerifier.ts +++ b/src/codec-handler/handlers/office/EncryptionVerifier.ts @@ -1,4 +1,4 @@ -import { CryptoAlgorithm } from "./CryptoAlgorithm.js"; +import type { CryptoAlgorithm } from "./CryptoAlgorithm.js"; // are those the same values for ECMA Standard? const SALT_SIZE_OFFSET = 138; diff --git a/src/codec-handler/handlers/office/agile/EncryptionDescriptor.ts b/src/codec-handler/handlers/office/agile/EncryptionDescriptor.ts index 3a27434c..2d15affc 100644 --- a/src/codec-handler/handlers/office/agile/EncryptionDescriptor.ts +++ b/src/codec-handler/handlers/office/agile/EncryptionDescriptor.ts @@ -1,5 +1,5 @@ import { XMLParser } from "fast-xml-parser"; -import { EncryptionDescriptor } from "./types.js"; +import type { EncryptionDescriptor } from "./types.js"; const xmlParser = new XMLParser({ ignoreAttributes: false, diff --git a/src/codec-handler/handlers/office/agile/index.ts b/src/codec-handler/handlers/office/agile/index.ts index bec8b459..11823550 100644 --- a/src/codec-handler/handlers/office/agile/index.ts +++ b/src/codec-handler/handlers/office/agile/index.ts @@ -1,10 +1,10 @@ -import { CodecHandler, VerifyPassword } from "../../../index.js"; +import type { CodecHandler, VerifyPassword } from "../../../index.js"; import { blockDecrypt, deriveKey, hash } from "../../../../crypto/index.js"; import { fixBufferLength, roundToFullByte } from "../../../../util.js"; -import { DecryptPage } from "../../../types.js"; +import type { DecryptPage } from "../../../types.js"; import { getPageEncodingKey } from "../../../util.js"; import { parseEncryptionDescriptor } from "./EncryptionDescriptor.js"; -import { PasswordKeyEncryptor } from "./types.js"; +import type { PasswordKeyEncryptor } from "./types.js"; const ENC_VERIFIER_INPUT_BLOCK = [0xfe, 0xa7, 0xd2, 0x76, 0x3b, 0x4b, 0x9e, 0x79]; const ENC_VERIFIER_VALUE_BLOCK = [0xd7, 0xaa, 0x0f, 0x6d, 0x30, 0x61, 0x34, 0x4e]; diff --git a/src/codec-handler/handlers/office/index.ts b/src/codec-handler/handlers/office/index.ts index 18374055..f4356557 100644 --- a/src/codec-handler/handlers/office/index.ts +++ b/src/codec-handler/handlers/office/index.ts @@ -3,7 +3,7 @@ import { createIdentityHandler } from "../identity.js"; import { createAgileCodecHandler } from "./agile/index.js"; import { EncryptionHeaderFlags, isFlagSet } from "./EncryptionHeader.js"; import { createRC4CryptoAPICodecHandler } from "./rc4-cryptoapi.js"; -import { CodecHandler } from "../../types.js"; +import type { CodecHandler } from "../../types.js"; const MAX_PASSWORD_LENGTH = 255; const CRYPT_STRUCTURE_OFFSET = 0x299; @@ -41,27 +41,26 @@ export function createOfficeCodecHandler(databaseDefinitionPage: Buffer, passwor case "4.2": case "3.2": - case "2.2": - { - const flags = encryptionProviderBuffer.readInt32LE(4); - if (isFlagSet(flags, EncryptionHeaderFlags.FCRYPTO_API_FLAG)) { - if (isFlagSet(flags, EncryptionHeaderFlags.FAES_FLAG)) { - // Standard Encryption - throw new Error("Not implemented yet"); - } else { - try { - // RC4 CryptoAPI Encryption - return createRC4CryptoAPICodecHandler(encodingKey, encryptionProviderBuffer, passwordBuffer); - } catch (e) { - // Non Standard Encryption - } - - throw new Error("Not implemented yet"); - } + case "2.2": { + const flags = encryptionProviderBuffer.readInt32LE(4); + if (isFlagSet(flags, EncryptionHeaderFlags.FCRYPTO_API_FLAG)) { + if (isFlagSet(flags, EncryptionHeaderFlags.FAES_FLAG)) { + // Standard Encryption + throw new Error("Not implemented yet"); } else { - throw new Error("Unknown encryption"); + try { + // RC4 CryptoAPI Encryption + return createRC4CryptoAPICodecHandler(encodingKey, encryptionProviderBuffer, passwordBuffer); + } catch (e) { + // Non Standard Encryption + } + + throw new Error("Not implemented yet"); } + } else { + throw new Error("Unknown encryption"); } + } case "1.1": // RC4 Encryption: 1.1 diff --git a/src/codec-handler/handlers/office/rc4-cryptoapi.ts b/src/codec-handler/handlers/office/rc4-cryptoapi.ts index 7b0d124c..7ad39001 100644 --- a/src/codec-handler/handlers/office/rc4-cryptoapi.ts +++ b/src/codec-handler/handlers/office/rc4-cryptoapi.ts @@ -1,11 +1,11 @@ import { createRC4Decrypter, decryptRC4, hash } from "../../../crypto/index.js"; import { fixBufferLength, intToBuffer, roundToFullByte } from "../../../util.js"; -import { CodecHandler, DecryptPage } from "../../types.js"; +import type { CodecHandler, DecryptPage } from "../../types.js"; import { getPageEncodingKey } from "../../util.js"; -import { CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js"; -import { EncryptionHeader, parseEncryptionHeader } from "./EncryptionHeader.js"; +import { type CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js"; +import { type EncryptionHeader, parseEncryptionHeader } from "./EncryptionHeader.js"; import { parseEncryptionVerifier } from "./EncryptionVerifier.js"; -import { HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js"; +import { type HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js"; const VALID_CRYPTO_ALGORITHMS: CryptoAlgorithm[] = [CRYPTO_ALGORITHMS.RC4]; const VALID_HASH_ALGORITHMS: HashAlgorithm[] = [HASH_ALGORITHMS.SHA1]; diff --git a/src/column.ts b/src/column.ts index 844aa9db..17c95b15 100644 --- a/src/column.ts +++ b/src/column.ts @@ -1,4 +1,4 @@ -import { ColumnType, ColumnTypes } from "./types.js"; +import { type ColumnType, ColumnTypes } from "./types.js"; export interface Column { /** diff --git a/src/crypto/blockDecrypt.ts b/src/crypto/blockDecrypt.ts index 7ccbb4b1..a388254e 100644 --- a/src/crypto/blockDecrypt.ts +++ b/src/crypto/blockDecrypt.ts @@ -1,5 +1,5 @@ import { createDecipheriv } from "../environment/index.js"; -import { Cipher } from "./types.js"; +import type { Cipher } from "./types.js"; export function blockDecrypt(cipher: Cipher, key: Buffer, iv: Buffer, data: Buffer): Buffer { const algorithm = `${cipher.algorithm}-${key.length * 8}-${cipher.chaining.slice(-3)}`; diff --git a/src/data/index.ts b/src/data/index.ts index 9faab4dc..c879c160 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -1,6 +1,6 @@ -import { Column, ColumnDefinition } from "../column.js"; +import type { Column, ColumnDefinition } from "../column.js"; import { Database } from "../Database.js"; -import { ColumnType, ColumnTypes, Value, ValueMap } from "../types.js"; +import { type ColumnType, ColumnTypes, type Value, type ValueMap } from "../types.js"; import { readBigInt } from "./bigint.js"; import { readBinary } from "./binary.js"; import { readByte } from "./byte.js"; diff --git a/src/data/memo.ts b/src/data/memo.ts index f4d0e2e0..3bbdc265 100644 --- a/src/data/memo.ts +++ b/src/data/memo.ts @@ -1,4 +1,4 @@ -import { Column } from "../index.js"; +import type { Column } from "../index.js"; import { Database } from "../Database.js"; import { uncompressText } from "../unicodeCompression.js"; diff --git a/src/data/numeric.ts b/src/data/numeric.ts index 5b0b2245..019a7627 100644 --- a/src/data/numeric.ts +++ b/src/data/numeric.ts @@ -1,5 +1,5 @@ import { addArray, multiplyArray, toArray } from "../array.js"; -import { Column } from "../column.js"; +import type { Column } from "../column.js"; import { buildValue } from "./util.js"; const MAX_PRECISION = 40; diff --git a/src/data/ole.ts b/src/data/ole.ts index 4ed67518..21d26b1f 100644 --- a/src/data/ole.ts +++ b/src/data/ole.ts @@ -1,4 +1,4 @@ -import { Column } from "../column.js"; +import type { Column } from "../column.js"; import { Database } from "../Database.js"; /** diff --git a/src/data/text.ts b/src/data/text.ts index 73f9da0e..fbb879ee 100644 --- a/src/data/text.ts +++ b/src/data/text.ts @@ -1,4 +1,4 @@ -import { Column } from "../index.js"; +import type { Column } from "../index.js"; import { Database } from "../Database.js"; import { uncompressText } from "../unicodeCompression.js"; diff --git a/src/unicodeCompression.ts b/src/unicodeCompression.ts index bc83ec0b..2661719f 100644 --- a/src/unicodeCompression.ts +++ b/src/unicodeCompression.ts @@ -1,4 +1,4 @@ -import { JetFormat } from "./JetFormat/index.js"; +import type { JetFormat } from "./JetFormat/index.js"; import { decodeWindows1252 } from "./dependencies/iconv-lite/index.js"; /** diff --git a/tsconfig.browser.json b/tsconfig.browser.json index 5d8aed38..5ccf6614 100644 --- a/tsconfig.browser.json +++ b/tsconfig.browser.json @@ -4,7 +4,8 @@ "outDir": "lib/browser", "module": "Node16", "moduleResolution": "node16", - "declaration": false + "declaration": false, + "verbatimModuleSyntax": true }, "files": ["src/index.ts", "typings/browserify-aes.d.ts", "typings/create-hash.d.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 9626a168..6b1ebf40 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "module": "Node16", "moduleResolution": "node16", "declaration": true, - "declarationDir": "lib/types" + "declarationDir": "lib/types", + "verbatimModuleSyntax": true }, "files": ["src/index.ts"] }