encodeBundle method
Encode key data
bundle is the encrypted key data with targets (ID terminals).
receiver is the user ID.
Returns encoded key data with targets (ID + terminals).
Implementation
@override
Map<String, Object> encodeBundle(EncryptedBundle bundle, ID receiver) {
//
// 0. ID string without terminal
//
assert(receiver.terminal == null, 'ID should not contain terminal here: $receiver');
final String identifier = receiver.withoutTerminal().toString();
final Map<String, Object> encodedKeys = {};
String target;
final Map<String, Uint8List> map = bundle.toMap();
map.forEach((key, value) {
target = key;
//
// 1. check target
//
if (target.isEmpty || target == '/') {
// Naked ID
target = identifier;
} else if (target.startsWith('/')) {
assert(false, 'entry error: $key -> $value');
target = identifier + target;
} else {
// Dressed ID
target = '$identifier/$target';
}
//
// 2. encode data (base64)
//
final ted = TransportableData.create(value);
assert(ted.isNotEmpty, 'failed to encode data: $value');
//
// 3. insert to 'message.keys' with ID + terminal
//
encodedKeys[target] = ted.serialize();
});
// OK
return encodedKeys;
}