Browse Source

check key type before length

Kieran Gibb 3 years ago
parent
commit
589cc47bdc
No account linked to committer's email address
1 changed files with 2 additions and 2 deletions
  1. 2
    2
      index.js

+ 2
- 2
index.js View File

@@ -39,9 +39,9 @@ class Crypto {
39 39
   }
40 40
 
41 41
   isKey (key) {
42
+    if (!(key instanceof Buffer) || typeof key !== 'string') return
42 43
     const length = Buffer.from(key, 'hex').length
43
-    return typeof key === 'string' &&
44
-      length === sodium.crypto_sign_PUBLICKEYBYTES ||
44
+    return length === sodium.crypto_sign_PUBLICKEYBYTES ||
45 45
       length === sodium.crypto_sign_PUBLICKEYBYTES + sodium.crypto_secretbox_KEYBYTES
46 46
   }
47 47