@neoware_inc/neozipkit 0.5.0

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 (171) hide show
  1. package/README.md +134 -0
  2. package/dist/browser/ZipkitBrowser.d.ts +27 -0
  3. package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
  4. package/dist/browser/ZipkitBrowser.js +303 -0
  5. package/dist/browser/ZipkitBrowser.js.map +1 -0
  6. package/dist/browser/index.d.ts +9 -0
  7. package/dist/browser/index.d.ts.map +1 -0
  8. package/dist/browser/index.esm.d.ts +12 -0
  9. package/dist/browser/index.esm.d.ts.map +1 -0
  10. package/dist/browser/index.esm.js +46 -0
  11. package/dist/browser/index.esm.js.map +1 -0
  12. package/dist/browser/index.js +38 -0
  13. package/dist/browser/index.js.map +1 -0
  14. package/dist/browser-esm/index.d.ts +9 -0
  15. package/dist/browser-esm/index.js +50211 -0
  16. package/dist/browser-esm/index.js.map +7 -0
  17. package/dist/browser-umd/index.d.ts +9 -0
  18. package/dist/browser-umd/index.js +50221 -0
  19. package/dist/browser-umd/index.js.map +7 -0
  20. package/dist/browser-umd/index.min.js +39 -0
  21. package/dist/browser.d.ts +9 -0
  22. package/dist/browser.js +38 -0
  23. package/dist/core/ZipCompress.d.ts +99 -0
  24. package/dist/core/ZipCompress.d.ts.map +1 -0
  25. package/dist/core/ZipCompress.js +287 -0
  26. package/dist/core/ZipCompress.js.map +1 -0
  27. package/dist/core/ZipCopy.d.ts +175 -0
  28. package/dist/core/ZipCopy.d.ts.map +1 -0
  29. package/dist/core/ZipCopy.js +310 -0
  30. package/dist/core/ZipCopy.js.map +1 -0
  31. package/dist/core/ZipDecompress.d.ts +57 -0
  32. package/dist/core/ZipDecompress.d.ts.map +1 -0
  33. package/dist/core/ZipDecompress.js +155 -0
  34. package/dist/core/ZipDecompress.js.map +1 -0
  35. package/dist/core/ZipEntry.d.ts +138 -0
  36. package/dist/core/ZipEntry.d.ts.map +1 -0
  37. package/dist/core/ZipEntry.js +829 -0
  38. package/dist/core/ZipEntry.js.map +1 -0
  39. package/dist/core/Zipkit.d.ts +315 -0
  40. package/dist/core/Zipkit.d.ts.map +1 -0
  41. package/dist/core/Zipkit.js +647 -0
  42. package/dist/core/Zipkit.js.map +1 -0
  43. package/dist/core/ZstdManager.d.ts +56 -0
  44. package/dist/core/ZstdManager.d.ts.map +1 -0
  45. package/dist/core/ZstdManager.js +144 -0
  46. package/dist/core/ZstdManager.js.map +1 -0
  47. package/dist/core/components/HashCalculator.d.ts +138 -0
  48. package/dist/core/components/HashCalculator.d.ts.map +1 -0
  49. package/dist/core/components/HashCalculator.js +360 -0
  50. package/dist/core/components/HashCalculator.js.map +1 -0
  51. package/dist/core/components/Logger.d.ts +73 -0
  52. package/dist/core/components/Logger.d.ts.map +1 -0
  53. package/dist/core/components/Logger.js +156 -0
  54. package/dist/core/components/Logger.js.map +1 -0
  55. package/dist/core/components/ProgressTracker.d.ts +43 -0
  56. package/dist/core/components/ProgressTracker.d.ts.map +1 -0
  57. package/dist/core/components/ProgressTracker.js +112 -0
  58. package/dist/core/components/ProgressTracker.js.map +1 -0
  59. package/dist/core/components/Support.d.ts +64 -0
  60. package/dist/core/components/Support.d.ts.map +1 -0
  61. package/dist/core/components/Support.js +71 -0
  62. package/dist/core/components/Support.js.map +1 -0
  63. package/dist/core/components/Util.d.ts +26 -0
  64. package/dist/core/components/Util.d.ts.map +1 -0
  65. package/dist/core/components/Util.js +95 -0
  66. package/dist/core/components/Util.js.map +1 -0
  67. package/dist/core/constants/Errors.d.ts +52 -0
  68. package/dist/core/constants/Errors.d.ts.map +1 -0
  69. package/dist/core/constants/Errors.js +67 -0
  70. package/dist/core/constants/Errors.js.map +1 -0
  71. package/dist/core/constants/Headers.d.ts +170 -0
  72. package/dist/core/constants/Headers.d.ts.map +1 -0
  73. package/dist/core/constants/Headers.js +194 -0
  74. package/dist/core/constants/Headers.js.map +1 -0
  75. package/dist/core/encryption/Manager.d.ts +58 -0
  76. package/dist/core/encryption/Manager.d.ts.map +1 -0
  77. package/dist/core/encryption/Manager.js +121 -0
  78. package/dist/core/encryption/Manager.js.map +1 -0
  79. package/dist/core/encryption/ZipCrypto.d.ts +172 -0
  80. package/dist/core/encryption/ZipCrypto.d.ts.map +1 -0
  81. package/dist/core/encryption/ZipCrypto.js +554 -0
  82. package/dist/core/encryption/ZipCrypto.js.map +1 -0
  83. package/dist/core/encryption/index.d.ts +9 -0
  84. package/dist/core/encryption/index.d.ts.map +1 -0
  85. package/dist/core/encryption/index.js +17 -0
  86. package/dist/core/encryption/index.js.map +1 -0
  87. package/dist/core/encryption/types.d.ts +29 -0
  88. package/dist/core/encryption/types.d.ts.map +1 -0
  89. package/dist/core/encryption/types.js +12 -0
  90. package/dist/core/encryption/types.js.map +1 -0
  91. package/dist/core/index.d.ts +27 -0
  92. package/dist/core/index.d.ts.map +1 -0
  93. package/dist/core/index.js +59 -0
  94. package/dist/core/index.js.map +1 -0
  95. package/dist/core/version.d.ts +5 -0
  96. package/dist/core/version.d.ts.map +1 -0
  97. package/dist/core/version.js +31 -0
  98. package/dist/core/version.js.map +1 -0
  99. package/dist/index.d.ts +9 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +38 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/node/ZipCompressNode.d.ts +123 -0
  104. package/dist/node/ZipCompressNode.d.ts.map +1 -0
  105. package/dist/node/ZipCompressNode.js +565 -0
  106. package/dist/node/ZipCompressNode.js.map +1 -0
  107. package/dist/node/ZipCopyNode.d.ts +165 -0
  108. package/dist/node/ZipCopyNode.d.ts.map +1 -0
  109. package/dist/node/ZipCopyNode.js +347 -0
  110. package/dist/node/ZipCopyNode.js.map +1 -0
  111. package/dist/node/ZipDecompressNode.d.ts +197 -0
  112. package/dist/node/ZipDecompressNode.d.ts.map +1 -0
  113. package/dist/node/ZipDecompressNode.js +678 -0
  114. package/dist/node/ZipDecompressNode.js.map +1 -0
  115. package/dist/node/ZipkitNode.d.ts +466 -0
  116. package/dist/node/ZipkitNode.d.ts.map +1 -0
  117. package/dist/node/ZipkitNode.js +1426 -0
  118. package/dist/node/ZipkitNode.js.map +1 -0
  119. package/dist/node/index.d.ts +25 -0
  120. package/dist/node/index.d.ts.map +1 -0
  121. package/dist/node/index.js +54 -0
  122. package/dist/node/index.js.map +1 -0
  123. package/dist/types/index.d.ts +45 -0
  124. package/dist/types/index.d.ts.map +1 -0
  125. package/dist/types/index.js +11 -0
  126. package/dist/types/index.js.map +1 -0
  127. package/examples/README.md +261 -0
  128. package/examples/append-data.json +44 -0
  129. package/examples/copy-zip-append.ts +139 -0
  130. package/examples/copy-zip.ts +152 -0
  131. package/examples/create-zip.ts +172 -0
  132. package/examples/extract-zip.ts +118 -0
  133. package/examples/list-zip.ts +161 -0
  134. package/examples/test-files/data.json +116 -0
  135. package/examples/test-files/document.md +80 -0
  136. package/examples/test-files/document.txt +6 -0
  137. package/examples/test-files/file1.txt +48 -0
  138. package/examples/test-files/file2.txt +80 -0
  139. package/examples/tsconfig.json +44 -0
  140. package/package.json +167 -0
  141. package/src/browser/ZipkitBrowser.ts +305 -0
  142. package/src/browser/index.esm.ts +32 -0
  143. package/src/browser/index.ts +19 -0
  144. package/src/core/ZipCompress.ts +370 -0
  145. package/src/core/ZipCopy.ts +434 -0
  146. package/src/core/ZipDecompress.ts +191 -0
  147. package/src/core/ZipEntry.ts +917 -0
  148. package/src/core/Zipkit.ts +794 -0
  149. package/src/core/ZstdManager.ts +165 -0
  150. package/src/core/components/HashCalculator.ts +384 -0
  151. package/src/core/components/Logger.ts +180 -0
  152. package/src/core/components/ProgressTracker.ts +134 -0
  153. package/src/core/components/Support.ts +77 -0
  154. package/src/core/components/Util.ts +91 -0
  155. package/src/core/constants/Errors.ts +78 -0
  156. package/src/core/constants/Headers.ts +205 -0
  157. package/src/core/encryption/Manager.ts +137 -0
  158. package/src/core/encryption/ZipCrypto.ts +650 -0
  159. package/src/core/encryption/index.ts +15 -0
  160. package/src/core/encryption/types.ts +33 -0
  161. package/src/core/index.ts +42 -0
  162. package/src/core/version.ts +33 -0
  163. package/src/index.ts +19 -0
  164. package/src/node/ZipCompressNode.ts +618 -0
  165. package/src/node/ZipCopyNode.ts +437 -0
  166. package/src/node/ZipDecompressNode.ts +793 -0
  167. package/src/node/ZipkitNode.ts +1706 -0
  168. package/src/node/index.ts +40 -0
  169. package/src/types/index.ts +68 -0
  170. package/src/types/modules.d.ts +22 -0
  171. package/src/types/opentimestamps.d.ts +1 -0
@@ -0,0 +1,205 @@
1
+ // ======================================
2
+ // Headers.ts
3
+ // Copyright (c) 2024 NeoWare, Inc. All rights reserved.
4
+ // ======================================
5
+ // Zip File Format Constants
6
+
7
+ export const LOCAL_FILE_HEADER = 'PK\x03\x04';
8
+ export const CENTRAL_FILE_HEADER = 'PK\x01\x02';
9
+ export const CENTRAL_DIRECTORY_END = 'PK\x05\x06';
10
+ export const ZIP64_CENTRAL_DIRECTORY_LOCATOR = 'PK\x06\x07';
11
+ export const ZIP64_CENTRAL_DIRECTORY_END = 'PK\x06\x06';
12
+ export const DATA_DESCRIPTOR = 'PK\x07\x08';
13
+
14
+ export const TIMESTAMP_SUBMITTED = 'META-INF/TS-SUBMIT.OTS';
15
+ export const TIMESTAMP_METADATA = 'META-INF/TIMESTAMP.OTS';
16
+ export const TOKENIZED_METADATA = 'META-INF/NZIP.TOKEN';
17
+
18
+ // Local file header
19
+ export const LOCAL_HDR = {
20
+ SIZE: 30, // LOC header size in bytes
21
+ SIGNATURE: 0x04034b50, // "PK\003\004"
22
+ VER_EXTRACT: 4, // version needed to extract
23
+ FLAGS: 6, // general purpose bit flag
24
+ COMPRESSION: 8, // compression method
25
+ TIMEDATE_DOS: 10, // modification time (2 bytes time, 2 bytes date)
26
+ CRC: 14, // uncompressed file crc-32 value
27
+ CMP_SIZE: 18, // compressed size
28
+ UNCMP_SIZE: 22, // uncompressed size
29
+ FNAME_LEN: 26, // filename length
30
+ EXTRA_LEN: 28 // extra field length
31
+ };
32
+ export const ENCRYPT_HDR_SIZE = 12;
33
+
34
+ // Data descriptor
35
+ export const DATA_DESC = {
36
+ SIGNATURE: 0x08074b50, // "PK\007\008"
37
+ SIZE: 16, // EXT header size in bytes
38
+ CRC: 4, // uncompressed file crc-32 value (offset)
39
+ CMP_SIZE: 8, // compressed size (offset)
40
+ UNCMP_SIZE: 12 // uncompressed size
41
+ };
42
+
43
+ // The central directory file header
44
+ export const CENTRAL_DIR = {
45
+ SIZE: 46, // Central directory header size
46
+ SIGNATURE: 0x02014b50, // "PK\001\002"
47
+ VER_MADE: 4, // version made by
48
+ VER_EXT: 6, // version needed to extract
49
+ FLAGS: 8, // encrypt, decrypt flags
50
+ CMP_METHOD: 10, // compression method
51
+ TIMEDATE_DOS: 12, // DOS modification time (2 bytes time, 2 bytes date)
52
+ CRC: 16, // uncompressed file crc-32 value
53
+ CMP_SIZE: 20, // compressed size
54
+ UNCMP_SIZE: 24, // uncompressed size
55
+ FNAME_LEN: 28, // filename length
56
+ EXTRA_LEN: 30, // extra field length
57
+ COMMENT_LEN: 32, // file comment length
58
+ DISK_NUM: 34, // volume number start
59
+ INT_FILE_ATTR: 36, // internal file attributes
60
+ EXT_FILE_ATTR: 38, // external file attributes (host system dependent)
61
+ LOCAL_HDR_OFFSET: 42 // LOC header offset
62
+ };
63
+
64
+ // The Zip central directory Locator
65
+ export const CENTRAL_END = {
66
+ SIZE: 22, // END header size
67
+ SIGNATURE: 0x06054b50, // "PK\005\006"
68
+ VOL_NUM: 4, // number of this disk
69
+ VOLDIR_START: 6, // number of the volume/disk with start of the Central Directory
70
+ VOL_ENTRIES: 8, // number of entries on this volume/disk
71
+ TOTAL_ENTRIES: 10, // total number of entries on this disk
72
+ CENTRAL_DIR_SIZE: 12, // central directory size in bytes
73
+ CENTRAL_DIR_OFFSET: 16, // offset of first CEN header
74
+ ZIP_COMMENT_LEN: 20 // zip file comment length
75
+ };
76
+
77
+ // Zip64 Central Directory Entry
78
+ export const ZIP64_CENTRAL_DIR = {
79
+ SIGNATURE: 0x06064b50, // zip64 signature, "PK\006\006"
80
+ SIZE: 56, // zip64 record minimum size
81
+ LEAD: 12, // leading bytes at the start of the record, not counted by the value stored in ZIP64SIZE
82
+ SIZE_FIELD: 4, // zip64 size of the central directory record
83
+ VER_MADEBY: 12, // zip64 version made by
84
+ VER_NEEDED: 14, // zip64 version needed to extract
85
+ VOL_NUM: 16, // zip64 number of this disk
86
+ VOLDIR_START: 20, // number of the disk with the start of the record directory
87
+ VOL_ENTRIES: 24, // number of entries on this disk
88
+ TOTAL_ENTRIES: 32, // total number of entries
89
+ CENTRAL_DIR_SIZE: 40, // zip64 central directory size in bytes
90
+ CENTRAL_DIR_OFFSET: 48, // offset of start of central directory with respect to the starting disk number
91
+ EXTRA_FIELD: 56 // extensible data sector
92
+ };
93
+
94
+ // Zip64 Central directory locator
95
+ export const ZIP64_CENTRAL_END = {
96
+ SIZE: 20, // zip64 END header size
97
+ SIGNATURE: 0x07064b50, // zip64 Locator signature, "PK\006\007"
98
+ VOL_NUM: 4, // number of the disk with the start of the zip64
99
+ CENTRAL_DIR_OFFSET: 8, // relative offset of the zip64 end of central directory
100
+ TOTAL_DISKS: 16 // total number of disks
101
+ };
102
+
103
+ // Compression methods
104
+ export const CMP_METHOD = {
105
+ STORED: 0, // no compression
106
+ SHRUNK: 1, // shrunk
107
+ REDUCED1: 2, // reduced with compression factor 1
108
+ REDUCED2: 3, // reduced with compression factor 2
109
+ REDUCED3: 4, // reduced with compression factor 3
110
+ REDUCED4: 5, // reduced with compression factor 4
111
+ IMPLODED: 6, // imploded
112
+ DEFLATED: 8, // deflated
113
+ ENHANCED_DEFLATE: 9, // enhanced deflated
114
+ BZIP2: 12, // compressed using BZIP2
115
+ LZMA: 14, // LZMA
116
+ IBM_TERSE: 18, // compressed using IBM TERSE
117
+ IBM_LZ77: 19, // IBM LZ77
118
+ ZSTD: 93, // Zstandard compression
119
+ AES_ENCRYPT: 99 // WinZIP AES encryption method
120
+ };
121
+
122
+ // General purpose bit flag
123
+ export const GP_FLAG = {
124
+ ENCRYPTED: 1, // Bit 0: encrypted file
125
+ COMPRESSION1: 2, // Bit 1, compression option
126
+ COMPRESSION2: 4, // Bit 2, compression option
127
+ DATA_DESC: 8, // Bit 3, data descriptor
128
+ ENHANCED_DEFLATE: 16, // Bit 4, enhanced deflating
129
+ PATCHED: 32, // Bit 5, indicates that the file is compressed patched data.
130
+ STRONG_ENCRYPT: 64, // Bit 6, strong encryption (patented)
131
+ // Bits 7-10: Currently unused.
132
+ EFS: 2048, // Bit 11: Language encoding flag (EFS)
133
+ // Bit 12: Reserved by PKWARE for enhanced compression.
134
+ // Bit 13: encrypted the Central Directory (patented).
135
+ // Bits 14-15: Reserved by PKWARE.
136
+ MASK: 4096, // mask header values
137
+ };
138
+
139
+ // 4.5 Extensible data fields
140
+ export const EXTENSIBLE_DATA_FIELDS = {
141
+ ID: 0,
142
+ SIZE: 2,
143
+ };
144
+
145
+ // Header IDs
146
+ export const HDR_ID = {
147
+ ZIP64: 0x0001, // ZIP64 Extended Information Extra Field
148
+ AVINFO: 0x0007, // AV Info
149
+ PFS: 0x0008, // PFS Extra Field
150
+ OS2: 0x0009, // OS/2 Extra Field
151
+ NTFS: 0x000a, // NTFS Extra Field
152
+ OPENVMS: 0x000c, // OpenVMS Extra Field
153
+ UNIX: 0x000d, // Unix Extra Field
154
+ FORK: 0x000e, // Fork Data Extra Field
155
+ PATCH: 0x000f, // Patch Descriptor Extra Field
156
+ x509PKCS7: 0x0014, // X.509 Certificate Store (PKCS#7)
157
+ x509CERT_IDF: 0x0015, // X.509 Certificate ID and Fingerprint
158
+ x509CERT_IDC: 0x0016, // X.509 Certificate ID and Certificate
159
+ STRONG_ENC: 0x0017, // Strong Encryption Header
160
+ RECORD_MGT: 0x0018, // Record Management Controls
161
+ x509PKCS7RL: 0x0019, // X.509 Certificate Revocation List (PKCS#7)
162
+ IBM1: 0x0065, // IBM S/390 (Z390) - Attribute
163
+ IBM2: 0x0066, // IBM S/390 (Z390) - Attribute
164
+ SHA256: 0x014E, // SHA256 "N\01" with 64 bytes (256 bit) of SHA256 hash data
165
+ POSZIP: 0x4690, // POSZIP 4690
166
+ UNV_TIME: 0x5455, // Universal Time (UT) (32-bit) 5 data bytes
167
+ UID_GID: 0x7875, // Unix UID/GID (any size)
168
+ UNICODE_PATH: 0x7075, // Info-ZIP Unicode Path Extra Field
169
+ SYMLINK: 0x7855, // Unix Symbolic Link Extra Field
170
+ HARDLINK: 0x7865, // Unix Hard Link Extra Field
171
+ };
172
+
173
+ // File System
174
+ export const FILE_SYSTEM = {
175
+ MSDOS: 0, // MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)
176
+ AMIGA: 1, // Amiga
177
+ OPENVMS: 2, // OpenVMS
178
+ UNIX: 3, // UNIX
179
+ VM_CMS: 4, // VM/CMS
180
+ ATARI: 5, // Atari ST
181
+ OS2: 6, // OS/2 H.P.F.S.
182
+ MAC: 7, // Macintosh
183
+ CP_M: 9, // CP/M
184
+ NTFS: 10, // Windows NTFS
185
+ MVS: 11, // MVS (OS/390 - Z/OS)
186
+ VSE: 12, // VSE
187
+ ACORN: 13, // Acorn Risc
188
+ VFAT: 14, // VFAT
189
+ ALTMVS: 15, // Alternate MVS
190
+ BEOS: 16, // BeOS
191
+ TANDEM: 17, // Tandem
192
+ OS400: 18, // OS/400
193
+ DARWIN: 19 // Apple OS/X (Darwin)
194
+ };
195
+
196
+ // DOS File Attributes
197
+ export const DOS_FILE_ATTR = {
198
+ READONLY: 0x01,
199
+ HIDDEN: 0x02,
200
+ SYSTEM: 0x04,
201
+ VOLUME: 0x08,
202
+ DIRECTORY: 0x10,
203
+ ARCHIVE: 0x20
204
+ };
205
+
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Encryption Manager for NeoZipKit
3
+ * Manages different encryption providers and provides a unified interface
4
+ */
5
+
6
+ import { EncryptionProvider, EncryptionOptions, EncryptionResult, DecryptionResult, EncryptionMethod } from './types';
7
+ import { ZipCrypto } from './ZipCrypto';
8
+
9
+ export class EncryptionManager {
10
+ private providers: Map<EncryptionMethod, EncryptionProvider> = new Map();
11
+
12
+ constructor() {
13
+ // Register default encryption providers
14
+ this.registerProvider(new ZipCrypto());
15
+ }
16
+
17
+ /**
18
+ * Register a new encryption provider
19
+ */
20
+ registerProvider(provider: EncryptionProvider): void {
21
+ if (provider.canHandle(EncryptionMethod.ZIP_CRYPTO)) {
22
+ this.providers.set(EncryptionMethod.ZIP_CRYPTO, provider);
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Get available encryption methods
28
+ */
29
+ getAvailableMethods(): EncryptionMethod[] {
30
+ return Array.from(this.providers.keys());
31
+ }
32
+
33
+ /**
34
+ * Get encryption provider for a specific method
35
+ */
36
+ getProvider(method: EncryptionMethod): EncryptionProvider | null {
37
+ return this.providers.get(method) || null;
38
+ }
39
+
40
+ /**
41
+ * Encrypt data using specified method
42
+ */
43
+ async encrypt(data: Buffer, options: EncryptionOptions): Promise<EncryptionResult> {
44
+ const provider = this.getProvider(options.method);
45
+ if (!provider) {
46
+ return {
47
+ success: false,
48
+ error: `No encryption provider available for method ${options.method}`
49
+ };
50
+ }
51
+
52
+ return await provider.encrypt(data, options);
53
+ }
54
+
55
+ /**
56
+ * Decrypt data using specified method
57
+ */
58
+ async decrypt(data: Buffer, options: EncryptionOptions): Promise<DecryptionResult> {
59
+ const provider = this.getProvider(options.method);
60
+ if (!provider) {
61
+ return {
62
+ success: false,
63
+ error: `No decryption provider available for method ${options.method}`
64
+ };
65
+ }
66
+
67
+ return await provider.decrypt(data, options);
68
+ }
69
+
70
+ /**
71
+ * Get recommended encryption method (ZIP_CRYPTO)
72
+ */
73
+ getRecommendedMethod(): EncryptionMethod {
74
+ return EncryptionMethod.ZIP_CRYPTO;
75
+ }
76
+
77
+ /**
78
+ * Validate encryption options
79
+ */
80
+ validateOptions(options: EncryptionOptions): { isValid: boolean; errors: string[] } {
81
+ const errors: string[] = [];
82
+
83
+ if (!options.method) {
84
+ errors.push('Encryption method is required');
85
+ }
86
+
87
+ if (!options.password || options.password.length === 0) {
88
+ errors.push('Password is required');
89
+ }
90
+
91
+ if (options.password && options.password.length < 4) {
92
+ errors.push('Password must be at least 4 characters long');
93
+ }
94
+
95
+ return {
96
+ isValid: errors.length === 0,
97
+ errors: errors
98
+ };
99
+ }
100
+
101
+ /**
102
+ * Get encryption method info
103
+ */
104
+ getMethodInfo(method: EncryptionMethod): { name: string; keyLength: number; secure: boolean } | null {
105
+ const provider = this.getProvider(method);
106
+ if (!provider) {
107
+ return null;
108
+ }
109
+
110
+ return {
111
+ name: provider.getMethodName(),
112
+ keyLength: provider.getKeyLength(),
113
+ secure: false
114
+ };
115
+ }
116
+
117
+ /**
118
+ * List all available encryption methods with their details
119
+ */
120
+ listMethods(): Array<{ method: EncryptionMethod; name: string; keyLength: number; secure: boolean }> {
121
+ const methods: Array<{ method: EncryptionMethod; name: string; keyLength: number; secure: boolean }> = [];
122
+
123
+ for (const [method, provider] of this.providers) {
124
+ methods.push({
125
+ method: method,
126
+ name: provider.getMethodName(),
127
+ keyLength: provider.getKeyLength(),
128
+ secure: false
129
+ });
130
+ }
131
+
132
+ return methods.sort((a, b) => {
133
+ // Sort by name
134
+ return a.name.localeCompare(b.name);
135
+ });
136
+ }
137
+ }