Skip to content

Commit

Permalink
Fix to allow key ring size of 256 and not 255 (#1268)
Browse files Browse the repository at this point in the history
* Fix to allow key ring size of 256 and not 255

* Changeset

* Add unit test

* Lint

* Fix tests

* Lint
  • Loading branch information
hughns authored Oct 2, 2024
1 parent a5a5fc4 commit df3ea82
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/breezy-glasses-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Actually allow E2EE keyring size of 256
37 changes: 37 additions & 0 deletions src/e2ee/worker/ParticipantKeyHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, expect, it } from 'vitest';
import { KEY_PROVIDER_DEFAULTS } from '../constants';
import { createKeyMaterialFromString } from '../utils';
import { ParticipantKeyHandler } from './ParticipantKeyHandler';

describe('ParticipantKeyHandler', () => {
const participantIdentity = 'testParticipant';

it('keyringSize must be greater than 0', () => {
expect(() => {
new ParticipantKeyHandler(participantIdentity, { ...KEY_PROVIDER_DEFAULTS, keyringSize: 0 });
}).toThrowError(TypeError);
});

it('keyringSize must be max 256', () => {
expect(() => {
new ParticipantKeyHandler(participantIdentity, {
...KEY_PROVIDER_DEFAULTS,
keyringSize: 257,
});
}).toThrowError(TypeError);
});

it('get and sets keys at an index', async () => {
const keyHandler = new ParticipantKeyHandler(participantIdentity, {
...KEY_PROVIDER_DEFAULTS,
keyringSize: 128,
});
const materialA = await createKeyMaterialFromString('passwordA');
const materialB = await createKeyMaterialFromString('passwordB');
await keyHandler.setKey(materialA, 0);
expect(keyHandler.getKeySet(0)).toBeDefined();
expect(keyHandler.getKeySet(0)?.material).toEqual(materialA);
await keyHandler.setKey(materialB, 0);
expect(keyHandler.getKeySet(0)?.material).toEqual(materialB);
});
});
2 changes: 1 addition & 1 deletion src/e2ee/worker/ParticipantKeyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ParticipantKeyHandler extends (EventEmitter as new () => TypedEvent
constructor(participantIdentity: string, keyProviderOptions: KeyProviderOptions) {
super();
this.currentKeyIndex = 0;
if (keyProviderOptions.keyringSize < 1 || keyProviderOptions.keyringSize > 255) {
if (keyProviderOptions.keyringSize < 1 || keyProviderOptions.keyringSize > 256) {
throw new TypeError('Keyring size needs to be between 1 and 256');
}
this.cryptoKeyRing = new Array(keyProviderOptions.keyringSize).fill(undefined);
Expand Down

0 comments on commit df3ea82

Please sign in to comment.