bug fixes

This commit is contained in:
John Smith 2023-01-04 17:02:45 -05:00
parent b773064012
commit 712659e86f
4 changed files with 61 additions and 39 deletions

View File

@ -0,0 +1,15 @@
import 'dart:convert';
import 'dart:typed_data';
String base64UrlNoPadEncode(List<int> bytes) {
var x = base64Url.encode(bytes);
while (x.endsWith('=')) {
x = x.substring(0, x.length - 1);
}
return x;
}
Uint8List base64UrlNoPadDecode(String source) {
source = base64.normalize(source);
return base64.decode(source);
}

View File

@ -8,6 +8,8 @@ import 'veilid_stub.dart'
if (dart.library.io) 'veilid_ffi.dart' if (dart.library.io) 'veilid_ffi.dart'
if (dart.library.js) 'veilid_js.dart'; if (dart.library.js) 'veilid_js.dart';
import 'base64url_no_pad.dart';
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
export 'default_config.dart'; export 'default_config.dart';
@ -1315,7 +1317,7 @@ class VeilidAppMessage implements VeilidUpdate {
return { return {
'kind': "AppMessage", 'kind': "AppMessage",
'sender': sender, 'sender': sender,
'message': base64UrlEncode(message) 'message': base64UrlNoPadEncode(message)
}; };
} }
} }
@ -1337,7 +1339,7 @@ class VeilidAppCall implements VeilidUpdate {
return { return {
'kind': "AppMessage", 'kind': "AppMessage",
'sender': sender, 'sender': sender,
'message': base64UrlEncode(message), 'message': base64UrlNoPadEncode(message),
'id': id, 'id': id,
}; };
} }
@ -1829,10 +1831,10 @@ class KeyBlob {
KeyBlob.fromJson(dynamic json) KeyBlob.fromJson(dynamic json)
: key = json['key'], : key = json['key'],
blob = base64Decode(json['blob']); blob = base64UrlNoPadDecode(json['blob']);
Map<String, dynamic> get json { Map<String, dynamic> get json {
return {'key': key, 'blob': base64UrlEncode(blob)}; return {'key': key, 'blob': base64UrlNoPadEncode(blob)};
} }
} }

View File

@ -8,6 +8,7 @@ import 'dart:typed_data';
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
import 'veilid.dart'; import 'veilid.dart';
import 'base64url_no_pad.dart';
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
@ -425,20 +426,20 @@ class VeilidRoutingContextFFI implements VeilidRoutingContext {
@override @override
Future<Uint8List> appCall(String target, Uint8List request) async { Future<Uint8List> appCall(String target, Uint8List request) async {
var nativeEncodedTarget = target.toNativeUtf8(); var nativeEncodedTarget = target.toNativeUtf8();
var nativeEncodedRequest = base64UrlEncode(request).toNativeUtf8(); var nativeEncodedRequest = base64UrlNoPadEncode(request).toNativeUtf8();
final recvPort = ReceivePort("routing_context_app_call"); final recvPort = ReceivePort("routing_context_app_call");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
_ctx.ffi._routingContextAppCall(sendPort.nativePort, _ctx.id, _ctx.ffi._routingContextAppCall(sendPort.nativePort, _ctx.id,
nativeEncodedTarget, nativeEncodedRequest); nativeEncodedTarget, nativeEncodedRequest);
final out = await processFuturePlain(recvPort.first); final out = await processFuturePlain(recvPort.first);
return base64Decode(out); return base64UrlNoPadDecode(out);
} }
@override @override
Future<void> appMessage(String target, Uint8List message) async { Future<void> appMessage(String target, Uint8List message) async {
final nativeEncodedTarget = target.toNativeUtf8(); final nativeEncodedTarget = target.toNativeUtf8();
final nativeEncodedMessage = base64UrlEncode(message).toNativeUtf8(); final nativeEncodedMessage = base64UrlNoPadEncode(message).toNativeUtf8();
final recvPort = ReceivePort("routing_context_app_message"); final recvPort = ReceivePort("routing_context_app_message");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
@ -490,8 +491,8 @@ class VeilidTableDBTransactionFFI extends VeilidTableDBTransaction {
@override @override
Future<void> store(int col, Uint8List key, Uint8List value) { Future<void> store(int col, Uint8List key, Uint8List value) {
final nativeEncodedKey = base64UrlEncode(key).toNativeUtf8(); final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
final nativeEncodedValue = base64UrlEncode(value).toNativeUtf8(); final nativeEncodedValue = base64UrlNoPadEncode(value).toNativeUtf8();
final recvPort = ReceivePort("veilid_table_db_transaction_store"); final recvPort = ReceivePort("veilid_table_db_transaction_store");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
@ -507,7 +508,7 @@ class VeilidTableDBTransactionFFI extends VeilidTableDBTransaction {
@override @override
Future<bool> delete(int col, Uint8List key) { Future<bool> delete(int col, Uint8List key) {
final nativeEncodedKey = base64UrlEncode(key).toNativeUtf8(); final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
final recvPort = ReceivePort("veilid_table_db_transaction_delete"); final recvPort = ReceivePort("veilid_table_db_transaction_delete");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
@ -551,7 +552,7 @@ class VeilidTableDBFFI extends VeilidTableDB {
String ja = s.toDartString(); String ja = s.toDartString();
_tdb.ffi._freeString(s); _tdb.ffi._freeString(s);
List<dynamic> jarr = jsonDecode(ja); List<dynamic> jarr = jsonDecode(ja);
return jarr.map((e) => base64Decode(e)).toList(); return jarr.map((e) => base64UrlNoPadDecode(e)).toList();
} }
@override @override
@ -562,8 +563,8 @@ class VeilidTableDBFFI extends VeilidTableDB {
@override @override
Future<void> store(int col, Uint8List key, Uint8List value) { Future<void> store(int col, Uint8List key, Uint8List value) {
final nativeEncodedKey = base64UrlEncode(key).toNativeUtf8(); final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
final nativeEncodedValue = base64UrlEncode(value).toNativeUtf8(); final nativeEncodedValue = base64UrlNoPadEncode(value).toNativeUtf8();
final recvPort = ReceivePort("veilid_table_db_store"); final recvPort = ReceivePort("veilid_table_db_store");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
@ -579,7 +580,7 @@ class VeilidTableDBFFI extends VeilidTableDB {
@override @override
Future<Uint8List?> load(int col, Uint8List key) async { Future<Uint8List?> load(int col, Uint8List key) async {
final nativeEncodedKey = base64UrlEncode(key).toNativeUtf8(); final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
final recvPort = ReceivePort("veilid_table_db_load"); final recvPort = ReceivePort("veilid_table_db_load");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
@ -593,12 +594,12 @@ class VeilidTableDBFFI extends VeilidTableDB {
if (out == null) { if (out == null) {
return null; return null;
} }
return base64Decode(out); return base64UrlNoPadDecode(out);
} }
@override @override
Future<bool> delete(int col, Uint8List key) { Future<bool> delete(int col, Uint8List key) {
final nativeEncodedKey = base64UrlEncode(key).toNativeUtf8(); final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
final recvPort = ReceivePort("veilid_table_db_delete"); final recvPort = ReceivePort("veilid_table_db_delete");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
@ -866,7 +867,7 @@ class VeilidFFI implements Veilid {
@override @override
Future<String> importRemotePrivateRoute(Uint8List blob) { Future<String> importRemotePrivateRoute(Uint8List blob) {
final nativeEncodedBlob = base64UrlEncode(blob).toNativeUtf8(); final nativeEncodedBlob = base64UrlNoPadEncode(blob).toNativeUtf8();
final recvPort = ReceivePort("import_remote_private_route"); final recvPort = ReceivePort("import_remote_private_route");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
@ -887,7 +888,7 @@ class VeilidFFI implements Veilid {
@override @override
Future<void> appCallReply(String id, Uint8List message) { Future<void> appCallReply(String id, Uint8List message) {
final nativeId = id.toNativeUtf8(); final nativeId = id.toNativeUtf8();
final nativeEncodedMessage = base64UrlEncode(message).toNativeUtf8(); final nativeEncodedMessage = base64UrlNoPadEncode(message).toNativeUtf8();
final recvPort = ReceivePort("app_call_reply"); final recvPort = ReceivePort("app_call_reply");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
_appCallReply(sendPort.nativePort, nativeId, nativeEncodedMessage); _appCallReply(sendPort.nativePort, nativeId, nativeEncodedMessage);

View File

@ -7,6 +7,8 @@ import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'base64url_no_pad.dart';
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
Veilid getVeilid() => VeilidJS(); Veilid getVeilid() => VeilidJS();
@ -60,15 +62,15 @@ class VeilidRoutingContextJS implements VeilidRoutingContext {
@override @override
Future<Uint8List> appCall(String target, Uint8List request) async { Future<Uint8List> appCall(String target, Uint8List request) async {
var encodedRequest = base64UrlEncode(request); var encodedRequest = base64UrlNoPadEncode(request);
return base64Decode(await _wrapApiPromise(js_util.callMethod( return base64UrlNoPadDecode(await _wrapApiPromise(js_util.callMethod(
wasm, "routing_context_app_call", [_ctx.id, encodedRequest]))); wasm, "routing_context_app_call", [_ctx.id, encodedRequest])));
} }
@override @override
Future<void> appMessage(String target, Uint8List message) { Future<void> appMessage(String target, Uint8List message) {
var encodedMessage = base64UrlEncode(message); var encodedMessage = base64UrlNoPadEncode(message);
return _wrapApiPromise(js_util.callMethod( return _wrapApiPromise(js_util.callMethod(
wasm, "routing_context_app_message", [_ctx.id, encodedMessage])); wasm, "routing_context_app_message", [_ctx.id, encodedMessage]));
@ -108,19 +110,21 @@ class VeilidTableDBTransactionJS extends VeilidTableDBTransaction {
@override @override
Future<void> store(int col, Uint8List key, Uint8List value) { Future<void> store(int col, Uint8List key, Uint8List value) {
final encodedKey = base64UrlEncode(key); final encodedKey = base64UrlNoPadEncode(key);
final encodedValue = base64UrlEncode(value); final encodedValue = base64UrlNoPadEncode(value);
return _wrapApiPromise(js_util.callMethod(wasm, return _wrapApiPromise(js_util.callMethod(
"table_db_transaction_store", [_tdbt.id, encodedKey, encodedValue])); wasm,
"table_db_transaction_store",
[_tdbt.id, col, encodedKey, encodedValue]));
} }
@override @override
Future<bool> delete(int col, Uint8List key) { Future<bool> delete(int col, Uint8List key) {
final encodedKey = base64UrlEncode(key); final encodedKey = base64UrlNoPadEncode(key);
return _wrapApiPromise(js_util.callMethod( return _wrapApiPromise(js_util.callMethod(
wasm, "table_db_transaction_delete", [_tdbt.id, encodedKey])); wasm, "table_db_transaction_delete", [_tdbt.id, col, encodedKey]));
} }
} }
@ -154,7 +158,7 @@ class VeilidTableDBJS extends VeilidTableDB {
throw VeilidAPIExceptionInternal("No db for id"); throw VeilidAPIExceptionInternal("No db for id");
} }
List<dynamic> jarr = jsonDecode(s); List<dynamic> jarr = jsonDecode(s);
return jarr.map((e) => base64Decode(e)).toList(); return jarr.map((e) => base64UrlNoPadDecode(e)).toList();
} }
@override @override
@ -166,31 +170,31 @@ class VeilidTableDBJS extends VeilidTableDB {
@override @override
Future<void> store(int col, Uint8List key, Uint8List value) { Future<void> store(int col, Uint8List key, Uint8List value) {
final encodedKey = base64UrlEncode(key); final encodedKey = base64UrlNoPadEncode(key);
final encodedValue = base64UrlEncode(value); final encodedValue = base64UrlNoPadEncode(value);
return _wrapApiPromise(js_util.callMethod( return _wrapApiPromise(js_util.callMethod(
wasm, "table_db_store", [_tdb.id, encodedKey, encodedValue])); wasm, "table_db_store", [_tdb.id, col, encodedKey, encodedValue]));
} }
@override @override
Future<Uint8List?> load(int col, Uint8List key) async { Future<Uint8List?> load(int col, Uint8List key) async {
final encodedKey = base64UrlEncode(key); final encodedKey = base64UrlNoPadEncode(key);
String? out = await _wrapApiPromise( String? out = await _wrapApiPromise(
js_util.callMethod(wasm, "table_db_load", [_tdb.id, encodedKey])); js_util.callMethod(wasm, "table_db_load", [_tdb.id, col, encodedKey]));
if (out == null) { if (out == null) {
return null; return null;
} }
return base64Decode(out); return base64UrlNoPadDecode(out);
} }
@override @override
Future<bool> delete(int col, Uint8List key) { Future<bool> delete(int col, Uint8List key) {
final encodedKey = base64UrlEncode(key); final encodedKey = base64UrlNoPadEncode(key);
return _wrapApiPromise( return _wrapApiPromise(js_util
js_util.callMethod(wasm, "table_db_delete", [_tdb.id, encodedKey])); .callMethod(wasm, "table_db_delete", [_tdb.id, col, encodedKey]));
} }
} }
@ -285,7 +289,7 @@ class VeilidJS implements Veilid {
@override @override
Future<String> importRemotePrivateRoute(Uint8List blob) { Future<String> importRemotePrivateRoute(Uint8List blob) {
var encodedBlob = base64UrlEncode(blob); var encodedBlob = base64UrlNoPadEncode(blob);
return _wrapApiPromise( return _wrapApiPromise(
js_util.callMethod(wasm, "import_remote_private_route", [encodedBlob])); js_util.callMethod(wasm, "import_remote_private_route", [encodedBlob]));
} }
@ -298,7 +302,7 @@ class VeilidJS implements Veilid {
@override @override
Future<void> appCallReply(String id, Uint8List message) { Future<void> appCallReply(String id, Uint8List message) {
var encodedMessage = base64UrlEncode(message); var encodedMessage = base64UrlNoPadEncode(message);
return _wrapApiPromise( return _wrapApiPromise(
js_util.callMethod(wasm, "app_call_reply", [id, encodedMessage])); js_util.callMethod(wasm, "app_call_reply", [id, encodedMessage]));
} }