Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Simplify andOTP import to match other importers

Joice M. Josephf4577a08afe6
diff --git a/mobile/apps/auth/lib/l10n/arb/app_en.arb b/mobile/apps/auth/lib/l10n/arb/app_en.arb
index 49fbb50daf..4c76fee3b9 100644
--- a/mobile/apps/auth/lib/l10n/arb/app_en.arb
+++ b/mobile/apps/auth/lib/l10n/arb/app_en.arb
@@ -626,17 +626,5 @@
"todaysLogs": "Today's logs",
"importAndOTPGuide": "Export your backup from andOTP using the \"Backup\" option in Settings.\n\nIf your backup is encrypted, you will need to enter the backup password to decrypt it.",
"enterPasswordToDecryptAndOTP": "Enter password to decrypt andOTP backup",
- "failedToDecryptAndOTPBackup": "Failed to decrypt andOTP backup",
- "andOTPSkippedEntriesTitle": "{count, plural, =1{1 entry skipped} other{{count} entries skipped}}",
- "@andOTPSkippedEntriesTitle": {
- "description": "Title showing how many entries were skipped during andOTP import",
- "placeholders": {
- "count": {
- "description": "Number of entries skipped",
- "type": "int",
- "example": "2"
- }
- }
- },
- "andOTPSkippedEntriesReason": "These entries use unsupported formats (such as MOTP) and could not be imported."
+ "failedToDecryptAndOTPBackup": "Failed to decrypt andOTP backup"
}
diff --git a/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dart
index cd5992eba4..404eea82e0 100644
--- a/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/import/andotp_import.dart
@@ -67,13 +67,10 @@ Future<void> _pickAndOTPFile(BuildContext context) async {
try {
String path = result.files.single.path!;
- final importResult = await _processAndOTPFile(context, path, progressDialog);
+ final count = await _processAndOTPFile(context, path, progressDialog);
await progressDialog.hide();
- if (importResult != null) {
- await importSuccessDialog(context, importResult.importedCount);
- if (importResult.skippedEntries.isNotEmpty) {
- await _showSkippedEntriesDialog(context, importResult.skippedEntries);
- }
+ if (count != null) {
+ await importSuccessDialog(context, count);
}
} catch (e, s) {
_logger.severe('Exception while processing andOTP import', e, s);
@@ -86,13 +83,6 @@ Future<void> _pickAndOTPFile(BuildContext context) async {
}
}
-class _ImportResult {
- final int importedCount;
- final List<String> skippedEntries;
-
- _ImportResult({required this.importedCount, required this.skippedEntries});
-}
-
class _DecryptParams {
final Uint8List fileBytes;
final String password;
@@ -100,7 +90,7 @@ class _DecryptParams {
_DecryptParams({required this.fileBytes, required this.password});
}
-Future<_ImportResult?> _processAndOTPFile(
+Future<int?> _processAndOTPFile(
BuildContext context,
String path,
ProgressDialog dialog,
@@ -154,7 +144,6 @@ Future<_ImportResult?> _processAndOTPFile(
}
final List<Code> parsedCodes = [];
- final List<String> skippedEntries = [];
for (var item in entries) {
final String type = (item['type'] as String).toUpperCase();
@@ -164,16 +153,9 @@ Future<_ImportResult?> _processAndOTPFile(
? (label.isNotEmpty ? '$issuer ($label)' : issuer)
: label;
- // Skip unsupported types (MOTP)
- if (type == 'MOTP') {
- skippedEntries.add(displayName.isNotEmpty ? displayName : 'Unknown MOTP');
- continue;
- }
-
- // Validate supported types
+ // Skip unsupported types (e.g., MOTP)
if (type != 'TOTP' && type != 'HOTP' && type != 'STEAM') {
- skippedEntries
- .add(displayName.isNotEmpty ? displayName : 'Unknown ($type)');
+ _logger.warning('Skipping unsupported OTP type: $type for $displayName');
continue;
}
@@ -208,7 +190,6 @@ Future<_ImportResult?> _processAndOTPFile(
parsedCodes.add(code);
} catch (e, s) {
_logger.warning('Failed to parse andOTP entry: $displayName', e, s);
- skippedEntries.add(displayName.isNotEmpty ? displayName : 'Parse error');
}
}
@@ -217,10 +198,7 @@ Future<_ImportResult?> _processAndOTPFile(
}
unawaited(AuthenticatorService.instance.onlineSync());
- return _ImportResult(
- importedCount: parsedCodes.length,
- skippedEntries: skippedEntries,
- );
+ return parsedCodes.length;
}
/// Top-level function for decrypting andOTP backup in a separate isolate.
@@ -286,25 +264,3 @@ String _decryptAndOTPBackup(_DecryptParams params) {
final Uint8List decryptedBytes = cipher.process(ciphertextWithTag);
return utf8.decode(decryptedBytes);
}
-
-Future<void> _showSkippedEntriesDialog(
- BuildContext context,
- List<String> skippedEntries,
-) async {
- final l10n = context.l10n;
- final String entriesList = skippedEntries.join('\n');
- await showDialogWidget(
- context: context,
- title: l10n.andOTPSkippedEntriesTitle(skippedEntries.length),
- body: '$entriesList\n\n${l10n.andOTPSkippedEntriesReason}',
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.primary,
- labelText: l10n.ok,
- isInAlert: true,
- buttonSize: ButtonSize.large,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
-}