Skip to content

Commit 8794731

Browse files
committed
use detected version when decrypting
1 parent a8212a8 commit 8794731

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/cipher.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,19 @@ class TuyaCipher {
112112
}
113113

114114
/**
115-
* Decrypts data.
116-
* @param {String|Buffer} data to decrypt
117-
* @returns {Object|String}
118-
* returns object if data is JSON, else returns string
119-
*/
120-
decrypt(data) {
121-
if (this.version === '3.4') {
115+
* Decrypts data.
116+
* @param {String|Buffer} data to decrypt
117+
* @param {String} [version] protocol version
118+
* @returns {Object|String}
119+
* returns object if data is JSON, else returns string
120+
*/
121+
decrypt(data, version) {
122+
version = version || this.version;
123+
if (version === '3.4') {
122124
return this._decrypt34(data);
123125
}
124126

125-
if (this.version === '3.5') {
127+
if (version === '3.5') {
126128
return this._decrypt35(data);
127129
}
128130

lib/message-parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class MessageParser {
250250
throw new Error('Missing key or version in constructor.');
251251
}
252252

253-
data = this.cipher.decrypt(data);
253+
data = this.cipher.decrypt(data, version);
254254
} catch (_) {
255255
data = data.toString('utf8');
256256
}

0 commit comments

Comments
 (0)