TomSecretsHandover.parse constructor

TomSecretsHandover.parse(
  1. String line
)

From the JSON line.

Implementation

factory TomSecretsHandover.parse(String line) {
  final json = jsonDecode(line);
  if (json is! Map ||
      json['adminKey'] is! String ||
      json['bootstrap'] is! String) {
    throw const FormatException('the handover names adminKey and bootstrap');
  }
  final key = base64.decode(json['adminKey'] as String);
  if (key.length != tomSecretsKeyBytes) {
    throw const FormatException('the admin key is 32 bytes');
  }
  return TomSecretsHandover(
    adminKey: key,
    bootstrap: json['bootstrap'] as String,
    starterPid: json['starterPid'] is int ? json['starterPid'] as int : 0,
  );
}