Skip to content

Commit

Permalink
Use WebCrypto by default and only use software as a fallback if enabl…
Browse files Browse the repository at this point in the history
…ed (#6015)

Fixes use of  `enableSoftwareAES` to match the docs and the intended behavior when added in #99
  • Loading branch information
robwalch authored Jan 22, 2024
1 parent fdfbb81 commit de29d91
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/crypt/decrypter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export default class Decrypter {
private currentIV: ArrayBuffer | null = null;
private currentResult: ArrayBuffer | null = null;
private useSoftware: boolean;
private enableSoftwareAES: boolean;

constructor(config: HlsConfig, { removePKCS7Padding = true } = {}) {
this.useSoftware = config.enableSoftwareAES;
this.enableSoftwareAES = config.enableSoftwareAES;
this.removePKCS7Padding = removePKCS7Padding;
// built in decryptor expects PKCS7 padding
if (removePKCS7Padding) {
Expand All @@ -36,9 +37,7 @@ export default class Decrypter {
/* no-op */
}
}
if (this.subtle === null) {
this.useSoftware = true;
}
this.useSoftware = this.subtle === null;
}

destroy() {
Expand Down Expand Up @@ -174,14 +173,21 @@ export default class Decrypter {
}

private onWebCryptoError(data, key, iv): ArrayBuffer | never {
this.useSoftware = true;
this.logEnabled = true;
this.softwareDecrypt(data, key, iv);
const decryptResult = this.flush();
if (decryptResult) {
return decryptResult.buffer;
const enableSoftwareAES = this.enableSoftwareAES;
if (enableSoftwareAES) {
this.useSoftware = true;
this.logEnabled = true;
this.softwareDecrypt(data, key, iv);
const decryptResult = this.flush();
if (decryptResult) {
return decryptResult.buffer;
}
}
throw new Error('WebCrypto and softwareDecrypt: failed to decrypt data');
throw new Error(
'WebCrypto' +
(enableSoftwareAES ? ' and softwareDecrypt' : '') +
': failed to decrypt data',
);
}

private getValidChunk(data: Uint8Array): Uint8Array {
Expand Down

0 comments on commit de29d91

Please sign in to comment.