Initial group calling support
This commit is contained in:
31
ts/Crypto.ts
31
ts/Crypto.ts
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import pProps from 'p-props';
|
||||
import { chunk } from 'lodash';
|
||||
|
||||
export function typedArrayToArrayBuffer(typedArray: Uint8Array): ArrayBuffer {
|
||||
const { buffer, byteOffset, byteLength } = typedArray;
|
||||
@@ -706,6 +707,36 @@ export async function encryptCdsDiscoveryRequest(
|
||||
};
|
||||
}
|
||||
|
||||
export function uuidToArrayBuffer(uuid: string): ArrayBuffer {
|
||||
if (uuid.length !== 36) {
|
||||
window.log.warn(
|
||||
'uuidToArrayBuffer: received a string of invalid length. Returning an empty ArrayBuffer'
|
||||
);
|
||||
return new ArrayBuffer(0);
|
||||
}
|
||||
|
||||
return Uint8Array.from(
|
||||
chunk(uuid.replace(/-/g, ''), 2).map(pair => parseInt(pair.join(''), 16))
|
||||
).buffer;
|
||||
}
|
||||
|
||||
export function arrayBufferToUuid(
|
||||
arrayBuffer: ArrayBuffer
|
||||
): undefined | string {
|
||||
if (arrayBuffer.byteLength !== 16) {
|
||||
window.log.warn(
|
||||
'arrayBufferToUuid: received an ArrayBuffer of invalid length. Returning undefined'
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const uuids = splitUuids(arrayBuffer);
|
||||
if (uuids.length === 1) {
|
||||
return uuids[0] || undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function splitUuids(arrayBuffer: ArrayBuffer): Array<string | null> {
|
||||
const uuids = [];
|
||||
for (let i = 0; i < arrayBuffer.byteLength; i += 16) {
|
||||
|
Reference in New Issue
Block a user