Skip to content

Commit

Permalink
Use base64url encoding for encrypted username
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanny committed Mar 14, 2024
1 parent f77f916 commit 09fc0d6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ts/Bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function toBase64(data: Uint8Array): string {
return bytes.toBase64(data);
}

export function toBase64url(data: Uint8Array): string {
return bytes.toBase64url(data);
}

export function toHex(data: Uint8Array): string {
return bytes.toHex(data);
}
Expand Down
4 changes: 4 additions & 0 deletions ts/context/Bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class Bytes {
return Buffer.from(data).toString('base64');
}

public toBase64url(data: Uint8Array): string {
return Buffer.from(data).toString('base64url');
}

public toHex(data: Uint8Array): string {
return Buffer.from(data).toString('hex');
}
Expand Down
2 changes: 1 addition & 1 deletion ts/state/selectors/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const getUsernameLink = createSelector(
const content = Bytes.concatenate([entropy, serverId]);

return contactByEncryptedUsernameRoute
.toWebUrl({ encryptedUsername: Bytes.toBase64(content) })
.toWebUrl({ encryptedUsername: Bytes.toBase64url(content) })
.toString();
}
);
Expand Down
2 changes: 1 addition & 1 deletion ts/test-mock/pnp/username_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ describe('pnp/username', function (this: Mocha.Suite) {
encryptedUsername: Buffer.concat([
entropy,
uuidToBytes(serverId),
]).toString('base64'),
]).toString('base64url'),
})
.toString();

Expand Down

0 comments on commit 09fc0d6

Please sign in to comment.