mirror of
				https://gitlab.com/veilid/veilidchat.git
				synced 2025-10-31 14:18:57 -04:00 
			
		
		
		
	xfer
This commit is contained in:
		
							parent
							
								
									fb93e07ef2
								
							
						
					
					
						commit
						fe49beba9f
					
				
					 3 changed files with 25 additions and 6 deletions
				
			
		|  | @ -7,22 +7,29 @@ class DHTRecord { | |||
|   final VeilidRoutingContext _dhtctx; | ||||
|   final DHTRecordDescriptor _recordDescriptor; | ||||
|   final int _defaultSubkey; | ||||
|   final KeyPair? _writer; | ||||
|   late final DHTRecordEncryption _encryption; | ||||
| 
 | ||||
|   static Future<DHTRecord> create(VeilidRoutingContext dhtctx, | ||||
|       {DHTSchema schema = const DHTSchema.dflt(oCnt: 1), | ||||
|       int defaultSubkey = 0, | ||||
|       DHTRecordEncryption encrypt = DHTRecordEncryption.private}) async { | ||||
|       KeyPair? writer, | ||||
|       DHTRecordEncryptionFactory crypto = DHTRecordEncryption.private}) async { | ||||
|     DHTRecordDescriptor recordDescriptor = await dhtctx.createDHTRecord(schema); | ||||
|     return DHTRecord( | ||||
| 
 | ||||
|     final rec = DHTRecord( | ||||
|         dhtctx: dhtctx, | ||||
|         recordDescriptor: recordDescriptor, | ||||
|         defaultSubkey: defaultSubkey); | ||||
|         defaultSubkey: defaultSubkey, | ||||
|         writer: writer); | ||||
|     final encryption = crypto) | ||||
|   } | ||||
| 
 | ||||
|   static Future<DHTRecord> open( | ||||
|       VeilidRoutingContext dhtctx, TypedKey recordKey, KeyPair? writer, | ||||
|       {int defaultSubkey = 0, | ||||
|       DHTRecordEncryption encrypt = DHTRecordEncryption.private}) async { | ||||
|       KeyPair? writer, | ||||
|       DHTRecordEncryptionFactory encrypt = DHTRecordEncryption.private}) async { | ||||
|     DHTRecordDescriptor recordDescriptor = | ||||
|         await dhtctx.openDHTRecord(recordKey, writer); | ||||
|     return DHTRecord( | ||||
|  | @ -34,10 +41,11 @@ class DHTRecord { | |||
|   DHTRecord( | ||||
|       {required VeilidRoutingContext dhtctx, | ||||
|       required DHTRecordDescriptor recordDescriptor, | ||||
|       int defaultSubkey = 0}) | ||||
|       int defaultSubkey = 0, KeyPair? writer}) | ||||
|       : _dhtctx = dhtctx, | ||||
|         _recordDescriptor = recordDescriptor, | ||||
|         _defaultSubkey = defaultSubkey; | ||||
|         _defaultSubkey = defaultSubkey, | ||||
|         _writer = writer; | ||||
| 
 | ||||
|   int _subkey(int subkey) => (subkey == -1) ? _defaultSubkey : subkey; | ||||
| 
 | ||||
|  | @ -57,6 +65,10 @@ class DHTRecord { | |||
|     return KeyPair(key: _recordDescriptor.owner, secret: ownerSecret); | ||||
|   } | ||||
| 
 | ||||
|   KeyPair? writer() { | ||||
|     return _writer; | ||||
|   } | ||||
| 
 | ||||
|   Future<void> close() async { | ||||
|     await _dhtctx.closeDHTRecord(_recordDescriptor.key); | ||||
|   } | ||||
|  |  | |||
|  | @ -4,6 +4,8 @@ import 'package:veilid/veilid.dart'; | |||
| import 'dart:typed_data'; | ||||
| import 'tools.dart'; | ||||
| 
 | ||||
| typedef DHTRecordEncryptionFactory = DHTRecordEncryption Function(); | ||||
| 
 | ||||
| abstract class DHTRecordEncryption { | ||||
|   factory DHTRecordEncryption.private() { | ||||
|     return DHTRecordEncryptionPrivate(); | ||||
|  | @ -16,6 +18,8 @@ abstract class DHTRecordEncryption { | |||
|   FutureOr<Uint8List> decrypt(Uint8List data); | ||||
| } | ||||
| 
 | ||||
| //////////////////////////////////// | ||||
| /// Private DHT Record: Encrypted with the owner's secret key | ||||
| class DHTRecordEncryptionPrivate implements DHTRecordEncryption { | ||||
|   DHTRecordEncryptionPrivate() { | ||||
|     // | ||||
|  | @ -32,6 +36,8 @@ class DHTRecordEncryptionPrivate implements DHTRecordEncryption { | |||
|   } | ||||
| } | ||||
| 
 | ||||
| //////////////////////////////////// | ||||
| /// Public DHT Record: No encryption | ||||
| class DHTRecordEncryptionPublic implements DHTRecordEncryption { | ||||
|   DHTRecordEncryptionPublic() { | ||||
|     // | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| export 'external_stream_state.dart'; | ||||
| export 'dht_record.dart'; | ||||
| export 'dht_record_encryption.dart'; | ||||
| export 'json_tools.dart'; | ||||
| export 'phono_byte.dart'; | ||||
| export 'protobuf_tools.dart'; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Christien Rioux
						Christien Rioux