Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case of encryption key for an index to be undefined #2646

Open
wants to merge 1 commit into
base: livekit
Choose a base branch
from

Conversation

hughns
Copy link
Member

@hughns hughns commented Sep 23, 2024

As per matrix-org/matrix-js-sdk#4423 the key can be undefined and so we should handle this rather than waiting for SubtleCrypto.importKey() to fail.

As per matrix-org/matrix-js-sdk#4423 the key can be undefined and so we should handle this rather than waiting for SubtleCrypto.importKey() to fail.
@@ -41,7 +41,9 @@ export class MatrixKeyProvider extends BaseKeyProvider {
encryptionKeys,
] of this.rtcSession.getEncryptionKeys()) {
for (const [index, encryptionKey] of encryptionKeys.entries()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is currently written (and is sufficiently captured in type hints), the array returned by getEncryptionKeys is a sparse array, which contains empty slots that are skipped by array iteration methods.

Thus, instead of using a for...of loop and having to check for undefined, this could simply use forEach:

Suggested change
for (const [index, encryptionKey] of encryptionKeys.entries()) {
encryptionKeys.forEach((encryptionKey, index) => {

Note that this will work only if the array returned by getEncryptionKeys remains typed as Array<Uint8Array> instead of Array<Uint8Array | undefined>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants