ttlock-sdk-js icon indicating copy to clipboard operation
ttlock-sdk-js copied to clipboard

CodecUtils.decodeWithEncrypt not correct for null key

Open ddv2005 opened this issue 4 years ago • 1 comments

Hello,

If key is null then p0.length for initial crc should be 1 less in CodecUtils.decodeWithEncrypt

===========================================

diff --git a/src/util/CodecUtils.ts b/src/util/CodecUtils.ts
index 67b410b..5748cbf 100644
--- a/src/util/CodecUtils.ts
+++ b/src/util/CodecUtils.ts
@@ -40,7 +40,7 @@ export class CodecUtils {
     }

     var decoded = [];
-    const crc = dscrc_table[p0.length & 0xff];
+    const crc = dscrc_table[(p0.length - (key ? 0 : 1)) & 0xff];

     for (var i = 0; i < p0.length - (key ? 0 : 1); i++) {

ddv2005 avatar Jun 24 '21 01:06 ddv2005

Hi, thanks for the correction

Can you PR this so @kind3r can take a look at it easier?

Fusseldieb avatar Jul 12 '21 19:07 Fusseldieb