mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-10 19:07:02 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
32 lines
942 B
Dart
32 lines
942 B
Dart
import 'dart:io';
|
|
|
|
import 'package:crdt_sync/crdt_sync.dart';
|
|
|
|
/// sha256 hex of [token] (crdt_sync's `revisionOf` is exactly that).
|
|
String tokenHash(String token) => revisionOf(token);
|
|
|
|
Set<String> _hashes(File tokens) {
|
|
final String text;
|
|
try {
|
|
text = tokens.readAsStringSync();
|
|
} on FileSystemException {
|
|
return const {};
|
|
}
|
|
return {
|
|
for (final line in text.split('\n'))
|
|
if (line.trim() case final t when t.isNotEmpty && !t.startsWith('#'))
|
|
t.split(RegExp(r'\s+')).first.toLowerCase(),
|
|
};
|
|
}
|
|
|
|
/// Whether [authorization] bears a token hashed in [tokens], read per call.
|
|
bool tokenAccepted(File tokens, String? authorization) {
|
|
const scheme = 'bearer ';
|
|
if (authorization == null ||
|
|
!authorization.toLowerCase().startsWith(scheme)) {
|
|
return false;
|
|
}
|
|
final token = authorization.substring(scheme.length).trim();
|
|
return token.isNotEmpty && _hashes(tokens).contains(tokenHash(token));
|
|
}
|