Browse Source

default to encoder

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

+ 2
- 5
index.js View File

@@ -16,8 +16,7 @@ function encoder (encryptionKey, opts = {}) {
16 16
   return {
17 17
     encode (message, buffer, offset) {
18 18
       // Run originally provided encoder if any
19
-      if (opts.valueEncoding) message = encoder.encode(message, buffer, offset)
20
-      if (!Buffer.isBuffer(message)) message = Buffer.from(message, 'utf-8')
19
+      message = encoder.encode(message, buffer, offset)
21 20
       const ciphertext = Buffer.alloc(message.length + sodium.crypto_secretbox_MACBYTES)
22 21
       const nonce = Buffer.alloc(sodium.crypto_secretbox_NONCEBYTES)
23 22
       sodium.randombytes_buf(nonce)
@@ -25,7 +24,6 @@ function encoder (encryptionKey, opts = {}) {
25 24
       zero(message)
26 25
       return Buffer.concat([nonce, ciphertext])
27 26
     },
28
-
29 27
     decode (buffer, start, end) {
30 28
       const nonce = buffer.slice(0, sodium.crypto_secretbox_NONCEBYTES)
31 29
       const messageWithMAC = buffer.slice(sodium.crypto_secretbox_NONCEBYTES)
@@ -35,8 +33,7 @@ function encoder (encryptionKey, opts = {}) {
35 33
         'Decryption failed!'
36 34
       )
37 35
       // Run originally provided encoder if any
38
-      if (opts.valueEncoding) return encoder.decode(message, start, end)
39
-      return message
36
+      return encoder.decode(message, start, end)
40 37
     }
41 38
   }
42 39
 }