fix(ssss): Strip all whitespace characters from recovery keys upon decode

Previously we stripped all spaces off of the recovery when decoding it,
so that we could format the recovery key nicely. It turns out, however,
that some element flavours also format with linebreaks, leading to the
user having to manually remove them. We fix this by just stripping *all*
whitespace off of the recovery key.
This commit is contained in:
Sorunome 2021-12-05 12:19:22 +01:00
parent faed64cfde
commit 872bc04674
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 5 additions and 2 deletions

View File

@ -121,7 +121,7 @@ class SSSS {
}
static Uint8List decodeRecoveryKey(String recoveryKey) {
final result = base58.decode(recoveryKey.replaceAll(' ', ''));
final result = base58.decode(recoveryKey.replaceAll(RegExp(r'\s'), ''));
final parity = result.fold<int>(0, (a, b) => a ^ b);
if (parity != 0) {

View File

@ -126,7 +126,10 @@ void main() {
if (!olmEnabled) return;
final key = Uint8List.fromList(secureRandomBytes(32));
final encoded = SSSS.encodeRecoveryKey(key);
final decoded = SSSS.decodeRecoveryKey(encoded);
var decoded = SSSS.decodeRecoveryKey(encoded);
expect(key, decoded);
decoded = SSSS.decodeRecoveryKey(encoded + ' \n\t');
expect(key, decoded);
final handle = client.encryption!.ssss.open();