google preperation 1

This commit is contained in:
2026-10-26 20:48:16 +01:00
parent 9a65ff7ad4
commit 3b50cb0fe9
47 changed files with 4969 additions and 4580 deletions
+51
View File
@@ -0,0 +1,51 @@
// Encrypts tool/club_data.json into assets/club.enc using the club code.
//
// dart run tool/encrypt_club_data.dart
//
// The code is asked interactively (not echoed, not saved in shell history).
// tool/club_data.json holds the plain contacts and is gitignored — keep it private.
// Re-run after editing contacts or to change the club code, then rebuild the app.
import 'dart:convert';
import 'dart:io';
import 'package:test1/services/club_crypto.dart';
const _input = 'tool/club_data.json';
const _output = 'assets/club.enc';
Future<void> main() async {
final source = File(_input);
if (!source.existsSync()) {
stderr.writeln('Missing $_input');
exit(1);
}
final plaintext = source.readAsStringSync();
final contacts = (jsonDecode(plaintext) as Map<String, dynamic>)['contacts'] as List;
final code = _ask('Club code: ');
if (ClubCrypto.normalize(code).length < 8) {
stderr.writeln('Use at least 8 characters — short codes can be guessed by brute force.');
exit(1);
}
if (_ask('Repeat club code: ') != code) {
stderr.writeln('Codes do not match.');
exit(1);
}
final encrypted = await ClubCrypto.encrypt(plaintext, code);
if (await ClubCrypto.decrypt(encrypted, code) != plaintext) {
stderr.writeln('Self-check failed, nothing written.');
exit(1);
}
File(_output).writeAsStringSync(encrypted);
stdout.writeln('Wrote $_output with ${contacts.length} contacts.');
}
String _ask(String prompt) {
stdout.write(prompt);
final terminal = stdin.hasTerminal;
if (terminal) stdin.echoMode = false;
final value = stdin.readLineSync() ?? '';
if (terminal) stdin.echoMode = true;
stdout.writeln();
return value;
}