Skip to content

Commit

Permalink
Update: harmonize output from JWE.decrypt and JWS.verify
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxwolf committed Dec 12, 2015
1 parent 71d382e commit ed0ea52
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
```

Expand Down
4 changes: 2 additions & 2 deletions lib/jwe/decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
Expand All @@ -179,7 +179,7 @@ function JWEDecrypter(ks) {
reject(err);
}
else {
jwe.plaintext = data;
jwe.payload = jwe.plaintext = data;
resolve(jwe);
}
});
Expand Down
13 changes: 11 additions & 2 deletions test/jwe/jwe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
Expand All @@ -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);
});
});
}
Expand All @@ -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);
});
});
}
Expand Down

0 comments on commit ed0ea52

Please sign in to comment.