Now we've got everything prettified!
This commit is contained in:
parent
754d65ae2e
commit
a0ed993b42
30 changed files with 3562 additions and 2873 deletions
|
@ -6,24 +6,38 @@ describe('encrypting and decrypting profile data', function() {
|
|||
var buffer = dcodeIO.ByteBuffer.wrap(name).toArrayBuffer();
|
||||
var key = libsignal.crypto.getRandomBytes(32);
|
||||
|
||||
return textsecure.crypto.encryptProfileName(buffer, key).then(function(encrypted) {
|
||||
assert(encrypted.byteLength === NAME_PADDED_LENGTH + 16 + 12);
|
||||
return textsecure.crypto.decryptProfileName(encrypted, key).then(function(decrypted) {
|
||||
assert.strictEqual(dcodeIO.ByteBuffer.wrap(decrypted).toString('utf8'), 'Alice');
|
||||
return textsecure.crypto
|
||||
.encryptProfileName(buffer, key)
|
||||
.then(function(encrypted) {
|
||||
assert(encrypted.byteLength === NAME_PADDED_LENGTH + 16 + 12);
|
||||
return textsecure.crypto
|
||||
.decryptProfileName(encrypted, key)
|
||||
.then(function(decrypted) {
|
||||
assert.strictEqual(
|
||||
dcodeIO.ByteBuffer.wrap(decrypted).toString('utf8'),
|
||||
'Alice'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('works for empty string', function() {
|
||||
var name = dcodeIO.ByteBuffer.wrap('').toArrayBuffer();
|
||||
var key = libsignal.crypto.getRandomBytes(32);
|
||||
|
||||
return textsecure.crypto.encryptProfileName(name.buffer, key).then(function(encrypted) {
|
||||
assert(encrypted.byteLength === NAME_PADDED_LENGTH + 16 + 12);
|
||||
return textsecure.crypto.decryptProfileName(encrypted, key).then(function(decrypted) {
|
||||
assert.strictEqual(decrypted.byteLength, 0);
|
||||
assert.strictEqual(dcodeIO.ByteBuffer.wrap(decrypted).toString('utf8'), '');
|
||||
return textsecure.crypto
|
||||
.encryptProfileName(name.buffer, key)
|
||||
.then(function(encrypted) {
|
||||
assert(encrypted.byteLength === NAME_PADDED_LENGTH + 16 + 12);
|
||||
return textsecure.crypto
|
||||
.decryptProfileName(encrypted, key)
|
||||
.then(function(decrypted) {
|
||||
assert.strictEqual(decrypted.byteLength, 0);
|
||||
assert.strictEqual(
|
||||
dcodeIO.ByteBuffer.wrap(decrypted).toString('utf8'),
|
||||
''
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('encrypting and decrypting profile avatars', function() {
|
||||
|
@ -31,24 +45,32 @@ describe('encrypting and decrypting profile data', function() {
|
|||
var buffer = dcodeIO.ByteBuffer.wrap('This is an avatar').toArrayBuffer();
|
||||
var key = libsignal.crypto.getRandomBytes(32);
|
||||
|
||||
return textsecure.crypto.encryptProfile(buffer, key).then(function(encrypted) {
|
||||
assert(encrypted.byteLength === buffer.byteLength + 16 + 12);
|
||||
return textsecure.crypto.decryptProfile(encrypted, key).then(function(decrypted) {
|
||||
assertEqualArrayBuffers(buffer, decrypted)
|
||||
return textsecure.crypto
|
||||
.encryptProfile(buffer, key)
|
||||
.then(function(encrypted) {
|
||||
assert(encrypted.byteLength === buffer.byteLength + 16 + 12);
|
||||
return textsecure.crypto
|
||||
.decryptProfile(encrypted, key)
|
||||
.then(function(decrypted) {
|
||||
assertEqualArrayBuffers(buffer, decrypted);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('throws when decrypting with the wrong key', function() {
|
||||
var buffer = dcodeIO.ByteBuffer.wrap('This is an avatar').toArrayBuffer();
|
||||
var key = libsignal.crypto.getRandomBytes(32);
|
||||
var bad_key = libsignal.crypto.getRandomBytes(32);
|
||||
|
||||
return textsecure.crypto.encryptProfile(buffer, key).then(function(encrypted) {
|
||||
assert(encrypted.byteLength === buffer.byteLength + 16 + 12);
|
||||
return textsecure.crypto.decryptProfile(encrypted, bad_key).catch(function(error) {
|
||||
assert.strictEqual(error.name, 'ProfileDecryptError');
|
||||
return textsecure.crypto
|
||||
.encryptProfile(buffer, key)
|
||||
.then(function(encrypted) {
|
||||
assert(encrypted.byteLength === buffer.byteLength + 16 + 12);
|
||||
return textsecure.crypto
|
||||
.decryptProfile(encrypted, bad_key)
|
||||
.catch(function(error) {
|
||||
assert.strictEqual(error.name, 'ProfileDecryptError');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue