From ed0ea52e4fc4cc70920f2ce39bda11b09c45f214 Mon Sep 17 00:00:00 2001 From: "Matthew A. Miller" Date: Mon, 16 Nov 2015 09:02:36 -0700 Subject: [PATCH] Update: harmonize output from JWE.decrypt and JWS.verify --- README.md | 3 ++- lib/jwe/decrypt.js | 4 ++-- test/jwe/jwe-test.js | 13 +++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3f26fb9..f2a8b40 100644 --- a/README.md +++ b/README.md @@ -461,7 +461,8 @@ jose.JWE.createDecrypt(keystore). // {result} is a Object with: // * header: the combined 'protected' and 'unprotected' header members // * key: Key used to decrypt - // * plaintext: Buffer of the decrypted content + // * payload: Buffer of the decrypted content + // * plaintext: Buffer of the decrypted content (alternate) }); ``` diff --git a/lib/jwe/decrypt.js b/lib/jwe/decrypt.js index c8c9cd0..18b30b4 100644 --- a/lib/jwe/decrypt.js +++ b/lib/jwe/decrypt.js @@ -164,7 +164,7 @@ function JWEDecrypter(ks) { then(function(enkKey) { return enkKey.decrypt(jwe.header.enc, cdata, params). then(function(pdata) { - jwe.plaintext = pdata; + jwe.payload = jwe.plaintext = pdata; return jwe; }); }); @@ -179,7 +179,7 @@ function JWEDecrypter(ks) { reject(err); } else { - jwe.plaintext = data; + jwe.payload = jwe.plaintext = data; resolve(jwe); } }); diff --git a/test/jwe/jwe-test.js b/test/jwe/jwe-test.js index 0e318a4..949944e 100644 --- a/test/jwe/jwe-test.js +++ b/test/jwe/jwe-test.js @@ -163,12 +163,15 @@ describe("jwe", function() { .then(function(result) { // result.plaintext is a buffer, assert.equal will invoke its // toString() method implicitly - assert.equal(result.plaintext, input.plaintext); + assert.equal(result.payload, input.plaintext); // But let's make it clear that result.plaintext needs to be // converted before actually being a string. - var plaintext = result.plaintext.toString(); + var plaintext = result.payload.toString(); assert.deepEqual(plaintext, input.plaintext); + + // Verify that plaintext and payload are the same thing + assert.equal(result.plaintext, result.payload); }); }); } @@ -185,6 +188,9 @@ describe("jwe", function() { // converted before actually being a string. var plaintext = result.plaintext.toString(); assert.deepEqual(plaintext, input.plaintext); + + // Verify that plaintext and payload are the same thing + assert.equal(result.plaintext, result.payload); }); }); } @@ -201,6 +207,9 @@ describe("jwe", function() { // converted before actually being a string. var plaintext = result.plaintext.toString(); assert.deepEqual(plaintext, input.plaintext); + + // Verify that plaintext and payload are the same thing + assert.equal(result.plaintext, result.payload); }); }); }