This commit is contained in:
Christien Rioux 2023-07-09 10:55:43 -04:00
parent 19f384ab33
commit d48ce521b2

View File

@ -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)}"; 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) { CryptoKind cryptoKindFromString(String s) {
if (s.codeUnits.length != 4) { if (s.codeUnits.length != 4) {
throw const FormatException("malformed string"); throw const FormatException("malformed string");
@ -59,6 +68,12 @@ class Typed<V extends EncodedString> extends Equatable {
return Typed(kind: kind, value: value); return Typed(kind: kind, value: value);
} }
Uint8List decode() {
var b = cryptoKindToBytes(kind);
b.addAll(value.decode());
return b;
}
String toJson() => toString(); String toJson() => toString();
factory Typed.fromJson(dynamic json) => Typed.fromString(json as String); factory Typed.fromJson(dynamic json) => Typed.fromString(json as String);
} }