Skip to content

Commit ed0ea52

Browse files
committed
Update: harmonize output from JWE.decrypt and JWS.verify
1 parent 71d382e commit ed0ea52

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ jose.JWE.createDecrypt(keystore).
461461
// {result} is a Object with:
462462
// * header: the combined 'protected' and 'unprotected' header members
463463
// * key: Key used to decrypt
464-
// * plaintext: Buffer of the decrypted content
464+
// * payload: Buffer of the decrypted content
465+
// * plaintext: Buffer of the decrypted content (alternate)
465466
});
466467
```
467468

lib/jwe/decrypt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function JWEDecrypter(ks) {
164164
then(function(enkKey) {
165165
return enkKey.decrypt(jwe.header.enc, cdata, params).
166166
then(function(pdata) {
167-
jwe.plaintext = pdata;
167+
jwe.payload = jwe.plaintext = pdata;
168168
return jwe;
169169
});
170170
});
@@ -179,7 +179,7 @@ function JWEDecrypter(ks) {
179179
reject(err);
180180
}
181181
else {
182-
jwe.plaintext = data;
182+
jwe.payload = jwe.plaintext = data;
183183
resolve(jwe);
184184
}
185185
});

test/jwe/jwe-test.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,15 @@ describe("jwe", function() {
163163
.then(function(result) {
164164
// result.plaintext is a buffer, assert.equal will invoke its
165165
// toString() method implicitly
166-
assert.equal(result.plaintext, input.plaintext);
166+
assert.equal(result.payload, input.plaintext);
167167

168168
// But let's make it clear that result.plaintext needs to be
169169
// converted before actually being a string.
170-
var plaintext = result.plaintext.toString();
170+
var plaintext = result.payload.toString();
171171
assert.deepEqual(plaintext, input.plaintext);
172+
173+
// Verify that plaintext and payload are the same thing
174+
assert.equal(result.plaintext, result.payload);
172175
});
173176
});
174177
}
@@ -185,6 +188,9 @@ describe("jwe", function() {
185188
// converted before actually being a string.
186189
var plaintext = result.plaintext.toString();
187190
assert.deepEqual(plaintext, input.plaintext);
191+
192+
// Verify that plaintext and payload are the same thing
193+
assert.equal(result.plaintext, result.payload);
188194
});
189195
});
190196
}
@@ -201,6 +207,9 @@ describe("jwe", function() {
201207
// converted before actually being a string.
202208
var plaintext = result.plaintext.toString();
203209
assert.deepEqual(plaintext, input.plaintext);
210+
211+
// Verify that plaintext and payload are the same thing
212+
assert.equal(result.plaintext, result.payload);
204213
});
205214
});
206215
}

0 commit comments

Comments
 (0)