refactor
This commit is contained in:
parent
19f384ab33
commit
d48ce521b2
@ -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<V extends EncodedString> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user