decodeKeychain function
Implementation
Keychain decodeKeychain(Uint8List binary) {
var pos = 0;
final version = binary.sublist(pos, 4).buffer.asByteData().getInt32(0);
pos = pos + 4;
final seedSize = binary.sublist(pos, pos + 1)[0];
pos++;
final seed = binary.sublist(pos, pos + seedSize);
pos = pos + seedSize;
final nbServices = binary.sublist(pos, pos + 1)[0];
pos++;
final keychain = Keychain(seed, version: version);
for (var i = 0; i < nbServices; i++) {
final serviceNameLength = binary.sublist(pos, pos + 1)[0];
pos++;
final serviceName = binary.sublist(pos, pos + serviceNameLength);
pos = pos + serviceNameLength;
final derivationPathLength = binary.sublist(pos, pos + 1)[0];
pos++;
final derivationPath = binary.sublist(pos, pos + derivationPathLength);
pos = pos + derivationPathLength;
final curveId = binary.sublist(pos, pos + 1)[0];
pos++;
final hashAlgoId = binary.sublist(pos, pos + 1)[0];
pos++;
keychain.addService(utf8.decode(serviceName), utf8.decode(derivationPath),
curve: crypto.idToCurve(curveId),
hashAlgo: crypto.idToHashAlgo(hashAlgoId),);
}
return keychain;
}