Skip to content

Commit

Permalink
Better function name
Browse files Browse the repository at this point in the history
  • Loading branch information
dbkr committed Oct 30, 2023
1 parent 2fe0828 commit bf40656
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { EventType } from "../@types/event";
import { CallMembership, CallMembershipData } from "./CallMembership";
import { Focus } from "./focus";
import { MatrixError, MatrixEvent } from "../matrix";
import { randomString, secureRandomBase64 } from "../randomstring";
import { randomString, secureRandomBase64Url } from "../randomstring";
import { EncryptionKeysEventContent } from "./types";
import { decodeBase64, encodeUnpaddedBase64 } from "../base64";
import { isNumber } from "../utils";
Expand Down Expand Up @@ -325,7 +325,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
if (!userId) throw new Error("No userId");
if (!deviceId) throw new Error("No deviceId");

const encryptionKey = secureRandomBase64(16);
const encryptionKey = secureRandomBase64Url(16);
const encryptionKeyIndex = this.getNewEncryptionKeyIndex();
logger.info("Generated new key at index " + encryptionKeyIndex);
this.setEncryptionKey(userId, deviceId, encryptionKeyIndex, encryptionKey);
Expand Down
3 changes: 1 addition & 2 deletions src/randomstring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ const LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
const UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const DIGITS = "0123456789";

export function secureRandomBase64(len: number): string {
export function secureRandomBase64Url(len: number): string {
const key = new Uint8Array(len);
crypto.getRandomValues(key);

// encode to base64url as this value goes into URLs
return encodeUnpaddedBase64Url(key);
}

Expand Down

0 comments on commit bf40656

Please sign in to comment.