deserializePublicKey function

ASEPublicKey deserializePublicKey(
  1. String path
)

Deserializes the public key from a JSON file The file should contain a JSON object with the keys 'A' and 'b'.

Implementation

ASEPublicKey deserializePublicKey(String path) {
  if (!isPathSafe(path)) {
    throw ArgumentError('Unsafe file path');
  }

  final file = File(path);
  if (!file.existsSync()) {
    throw FileSystemException('File not found', path);
  }

  if (file.lengthSync() > 1024 * 1024) {
    throw FileSystemException('File too large', path);
  }

  var m = jsonDecode(file.readAsStringSync());
  var A = (m['A'] as List)
      .map((pv) => PolyVec(
          (pv as List).map((c) => Poly(List<int>.from(c as List))).toList()))
      .toList();
  var bVec =
      (m['b'] as List).map((c) => Poly(List<int>.from(c as List))).toList();
  return ASEPublicKey(A, PolyVec(bVec));
}