(aesKeyBase64: string)
| 40 | } |
| 41 | |
| 42 | export function parseAesKey(aesKeyBase64: string): Buffer { |
| 43 | const decoded = Buffer.from(aesKeyBase64, 'base64') |
| 44 | if (decoded.length === 16) { |
| 45 | return decoded |
| 46 | } |
| 47 | if ( |
| 48 | decoded.length === 32 && |
| 49 | /^[0-9a-fA-F]{32}$/.test(decoded.toString('ascii')) |
| 50 | ) { |
| 51 | return Buffer.from(decoded.toString('ascii'), 'hex') |
| 52 | } |
| 53 | throw new Error( |
| 54 | `Invalid aes_key: expected 16 raw bytes or 32 hex chars, got ${decoded.length} bytes`, |
| 55 | ) |
| 56 | } |
| 57 | |
| 58 | export async function downloadAndDecrypt(params: { |
| 59 | encryptQueryParam: string |
no test coverage detected