Use base64url encoding for encrypted username

This commit is contained in:
Brendan Fattig 2024-03-14 13:53:12 -05:00
parent f77f9165e1
commit 09fc0d690b
4 changed files with 10 additions and 2 deletions

View file

@ -26,6 +26,10 @@ export function toBase64(data: Uint8Array): string {
return bytes.toBase64(data); return bytes.toBase64(data);
} }
export function toBase64url(data: Uint8Array): string {
return bytes.toBase64url(data);
}
export function toHex(data: Uint8Array): string { export function toHex(data: Uint8Array): string {
return bytes.toHex(data); return bytes.toHex(data);
} }

View file

@ -25,6 +25,10 @@ export class Bytes {
return Buffer.from(data).toString('base64'); return Buffer.from(data).toString('base64');
} }
public toBase64url(data: Uint8Array): string {
return Buffer.from(data).toString('base64url');
}
public toHex(data: Uint8Array): string { public toHex(data: Uint8Array): string {
return Buffer.from(data).toString('hex'); return Buffer.from(data).toString('hex');
} }

View file

@ -115,7 +115,7 @@ export const getUsernameLink = createSelector(
const content = Bytes.concatenate([entropy, serverId]); const content = Bytes.concatenate([entropy, serverId]);
return contactByEncryptedUsernameRoute return contactByEncryptedUsernameRoute
.toWebUrl({ encryptedUsername: Bytes.toBase64(content) }) .toWebUrl({ encryptedUsername: Bytes.toBase64url(content) })
.toString(); .toString();
} }
); );

View file

@ -345,7 +345,7 @@ describe('pnp/username', function (this: Mocha.Suite) {
encryptedUsername: Buffer.concat([ encryptedUsername: Buffer.concat([
entropy, entropy,
uuidToBytes(serverId), uuidToBytes(serverId),
]).toString('base64'), ]).toString('base64url'),
}) })
.toString(); .toString();