Skip to content

Commit

Permalink
Merge pull request #1236 from matrix-org/travis/unpadded-qr-codes
Browse files Browse the repository at this point in the history
Use unpadded base64 for QR code secrets
  • Loading branch information
turt2live authored Feb 28, 2020
2 parents 7203542 + 4510eb6 commit 03752ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/crypto/olmlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ export function encodeBase64(uint8Array) {
return Buffer.from(uint8Array).toString("base64");
}

/**
* Encode a typed array of uint8 as unpadded base64.
* @param {Uint8Array} uint8Array The data to encode.
* @return {string} The unpadded base64.
*/
export function encodeUnpaddedBase64(uint8Array) {
return encodeBase64(uint8Array).replace(/=+$/g, '');
}

/**
* Decode a base64 string to a typed array of uint8.
* @param {string} base64 The base64 to decode.
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/verification/request/VerificationRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export class VerificationRequest extends EventEmitter {
_generateSharedSecret() {
const secretBytes = new Uint8Array(8);
global.crypto.getRandomValues(secretBytes);
this._sharedSecret = olmlib.encodeBase64(secretBytes);
this._sharedSecret = olmlib.encodeUnpaddedBase64(secretBytes);
}

/**
Expand Down

0 comments on commit 03752ab

Please sign in to comment.