Skip to content

Commit

Permalink
use detected version when decrypting
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Jan 29, 2025
1 parent a8212a8 commit 8794731
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions lib/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ class TuyaCipher {
}

/**
* Decrypts data.
* @param {String|Buffer} data to decrypt
* @returns {Object|String}
* returns object if data is JSON, else returns string
*/
decrypt(data) {
if (this.version === '3.4') {
* Decrypts data.
* @param {String|Buffer} data to decrypt
* @param {String} [version] protocol version
* @returns {Object|String}
* returns object if data is JSON, else returns string
*/
decrypt(data, version) {
version = version || this.version;
if (version === '3.4') {
return this._decrypt34(data);
}

if (this.version === '3.5') {
if (version === '3.5') {
return this._decrypt35(data);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/message-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class MessageParser {
throw new Error('Missing key or version in constructor.');
}

data = this.cipher.decrypt(data);
data = this.cipher.decrypt(data, version);
} catch (_) {
data = data.toString('utf8');
}
Expand Down

0 comments on commit 8794731

Please # to comment.