diff --git a/veilid-flutter/lib/veilid_crypto.dart b/veilid-flutter/lib/veilid_crypto.dart index 647d368b..6801f6e5 100644 --- a/veilid-flutter/lib/veilid_crypto.dart +++ b/veilid-flutter/lib/veilid_crypto.dart @@ -21,6 +21,15 @@ String cryptoKindToString(CryptoKind kind) { return "${String.fromCharCode(kind & 0xFF)}${String.fromCharCode((kind >> 8) & 0xFF)}${String.fromCharCode((kind >> 16) & 0xFF)}${String.fromCharCode((kind >> 24) & 0xFF)}"; } +Uint8List cryptoKindToBytes(CryptoKind kind) { + var b = Uint8List(4); + b[0] = kind & 0xFF; + b[1] = (kind >> 8) & 0xFF; + b[2] = (kind >> 16) & 0xFF; + b[3] = (kind >> 24) & 0xFF; + return b; +} + CryptoKind cryptoKindFromString(String s) { if (s.codeUnits.length != 4) { throw const FormatException("malformed string"); @@ -59,6 +68,12 @@ class Typed extends Equatable { return Typed(kind: kind, value: value); } + Uint8List decode() { + var b = cryptoKindToBytes(kind); + b.addAll(value.decode()); + return b; + } + String toJson() => toString(); factory Typed.fromJson(dynamic json) => Typed.fromString(json as String); }