Uint8Array migration

This commit is contained in:
Fedor Indutny 2021-09-23 17:49:05 -07:00 committed by GitHub
parent daf75190b8
commit 4ef0bf96cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
137 changed files with 2202 additions and 3170 deletions

View file

@ -5,11 +5,11 @@
import { assert } from 'chai';
import * as Bytes from '../../Bytes';
import {
LocalUserDataType,
sessionRecordToProtobuf,
} from '../../util/sessionTranslation';
import { base64ToArrayBuffer } from '../../Crypto';
const getRecordCopy = (record: any): any => JSON.parse(JSON.stringify(record));
@ -18,7 +18,7 @@ describe('sessionTranslation', () => {
beforeEach(() => {
ourData = {
identityKeyPublic: base64ToArrayBuffer(
identityKeyPublic: Bytes.fromBase64(
'Baioqfzc/5JD6b+GNqapPouf6eHK7xr9ynLJHnvl+444'
),
registrationId: 3554,

View file

@ -1,57 +0,0 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import crypto from 'crypto';
import { typedArrayToArrayBuffer as toArrayBuffer } from '../../Crypto';
import {
HashType,
hash,
sign,
encrypt,
decrypt,
} from '../../util/synchronousCrypto';
describe('synchronousCrypto', () => {
describe('hash', () => {
it('returns SHA512 hash of the input', () => {
const result = hash(
HashType.size512,
toArrayBuffer(Buffer.from('signal'))
);
assert.strictEqual(
Buffer.from(result).toString('base64'),
'WxneQjrfSlY95Bi+SAzDAr2cf3mxUXePeNYn6DILN4a8NFr9VelTbP5tGHdthi+' +
'mrJLqMZd1I6w8CxCnmJ/OFw=='
);
});
});
describe('sign', () => {
it('returns hmac SHA256 hash of the input', () => {
const result = sign(
toArrayBuffer(Buffer.from('secret')),
toArrayBuffer(Buffer.from('signal'))
);
assert.strictEqual(
Buffer.from(result).toString('base64'),
'5ewbITW27c1F7dluF9KwGcVQSxmZp6mpVhPj3ww1Sh8='
);
});
});
describe('encrypt+decrypt', () => {
it('returns original input', () => {
const iv = toArrayBuffer(crypto.randomBytes(16));
const key = toArrayBuffer(crypto.randomBytes(32));
const input = toArrayBuffer(Buffer.from('plaintext'));
const ciphertext = encrypt(key, input, iv);
const plaintext = decrypt(key, ciphertext, iv);
assert.strictEqual(Buffer.from(plaintext).toString(), 'plaintext');
});
});
});