veilidchat/lib/tools/dht_record_encryption.dart

54 lines
1.3 KiB
Dart
Raw Normal View History

2023-07-20 15:48:55 -04:00
import 'dart:async';
import 'package:veilid/veilid.dart';
import 'dart:typed_data';
import 'tools.dart';
2023-07-20 23:35:02 -04:00
typedef DHTRecordEncryptionFactory = DHTRecordEncryption Function(DHTRecord);
2023-07-20 20:57:36 -04:00
2023-07-20 15:48:55 -04:00
abstract class DHTRecordEncryption {
2023-07-20 23:35:02 -04:00
factory DHTRecordEncryption.private(DHTRecord record) {
return _DHTRecordEncryptionPrivate(record);
2023-07-20 15:48:55 -04:00
}
2023-07-20 23:35:02 -04:00
factory DHTRecordEncryption.public(DHTRecord record) {
return _DHTRecordEncryptionPublic(record);
2023-07-20 15:48:55 -04:00
}
2023-07-20 23:35:02 -04:00
FutureOr<Uint8List> encrypt(Uint8List data, int subkey);
FutureOr<Uint8List> decrypt(Uint8List data, int subkey);
2023-07-20 15:48:55 -04:00
}
2023-07-20 20:57:36 -04:00
////////////////////////////////////
/// Private DHT Record: Encrypted with the owner's secret key
2023-07-20 23:35:02 -04:00
class _DHTRecordEncryptionPrivate implements DHTRecordEncryption {
_DHTRecordEncryptionPrivate(DHTRecord record) {
// xxx derive key from record
2023-07-20 15:48:55 -04:00
}
@override
2023-07-20 23:35:02 -04:00
FutureOr<Uint8List> encrypt(Uint8List data, int subkey) {}
2023-07-20 15:48:55 -04:00
@override
2023-07-20 23:35:02 -04:00
FutureOr<Uint8List> decrypt(Uint8List data, int subkey) {
2023-07-20 15:48:55 -04:00
//
}
}
2023-07-20 20:57:36 -04:00
////////////////////////////////////
/// Public DHT Record: No encryption
2023-07-20 23:35:02 -04:00
class _DHTRecordEncryptionPublic implements DHTRecordEncryption {
_DHTRecordEncryptionPublic(DHTRecord record) {
2023-07-20 15:48:55 -04:00
//
}
@override
2023-07-20 23:35:02 -04:00
FutureOr<Uint8List> encrypt(Uint8List data, int subkey) {
2023-07-20 15:48:55 -04:00
return data;
}
@override
2023-07-20 23:35:02 -04:00
FutureOr<Uint8List> decrypt(Uint8List data, int subkey) {
2023-07-20 15:48:55 -04:00
return data;
}
}