Skip to content

Commit 1317bed

Browse files
author
Fernando
committed
Updated license on one file.
Throwing error when payload cannot be decrypted.
1 parent 50c8ed7 commit 1317bed

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/core/crypto/Crypto.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ export class Crypto {
178178
const decoded = Crypto._decode(recipientPrivate, senderPublic, payloadBuffer, tagAndIv);
179179
return decoded.toUpperCase();
180180
} catch (e) {
181-
// To return empty string rather than error throwing if authentication failed
182-
return '';
181+
throw new Error(`Cannot decrypt payload. Error: ${e.message}`);
183182
}
184183
};
185184

test/core/crypto/crypto.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ describe('crypto tests', () => {
3737
const encryptedMessage = Crypto.encode(Convert.uint8ToHex(sender.privateKey), Convert.uint8ToHex(recipient.publicKey), message);
3838
const senderPublic = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
3939
const recipientPriv = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
40-
const expectedMessage = 'NEM is awesome !';
41-
const decrypted = Crypto.decode(recipientPriv, senderPublic, encryptedMessage);
4240

43-
expect(decrypted).not.equal(convert.utf8ToHex(expectedMessage));
41+
expect(() => Crypto.decode(recipientPriv, senderPublic, encryptedMessage)).to.throw(
42+
'Cannot decrypt payload. Error: Unsupported state or unable to authenticate data',
43+
);
4444
});
4545

4646
describe('Encode & decode message edge-cases', () => {

test/model/message/RawMessage.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 NEM
2+
* (C) Symbol Contributors 2021
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)