* Determine the encryption algorithm from version and revision.
( version: EncryptionVersion, revision: EncryptionRevision, cryptFilters?: Map<string, CryptFilter>, streamFilter?: string, )
| 125 | * Determine the encryption algorithm from version and revision. |
| 126 | */ |
| 127 | function determineAlgorithm( |
| 128 | version: EncryptionVersion, |
| 129 | revision: EncryptionRevision, |
| 130 | cryptFilters?: Map<string, CryptFilter>, |
| 131 | streamFilter?: string, |
| 132 | ): EncryptionAlgorithm { |
| 133 | // R5-R6 always use AES-256 |
| 134 | if (revision >= 5) { |
| 135 | return "AES-256"; |
| 136 | } |
| 137 | |
| 138 | // V4 with crypt filters - check the stream filter |
| 139 | if (version === 4 && cryptFilters && streamFilter) { |
| 140 | const filter = cryptFilters.get(streamFilter); |
| 141 | |
| 142 | if (filter) { |
| 143 | switch (filter.cfm) { |
| 144 | case "AESV3": |
| 145 | return "AES-256"; |
| 146 | case "AESV2": |
| 147 | return "AES-128"; |
| 148 | case "V2": |
| 149 | return "RC4"; |
| 150 | case "None": |
| 151 | return "RC4"; // Identity, but we still need a default |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // V4 without explicit filter typically means AES-128 |
| 157 | if (version === 4) { |
| 158 | return "AES-128"; |
| 159 | } |
| 160 | |
| 161 | // V1-V3 use RC4 |
| 162 | return "RC4"; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Parse and validate the encryption version. |
no test coverage detected