Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecesary async/Future? #166

Open
busslina opened this issue Nov 2, 2023 · 3 comments
Open

Unnecesary async/Future? #166

busslina opened this issue Nov 2, 2023 · 3 comments

Comments

@busslina
Copy link

busslina commented Nov 2, 2023

/// Constructs a new [SecretKey] from the bytes.
///
/// Throws [ArgumentError] if the argument length is not [secretKeyLength].
Future<SecretKey> newSecretKeyFromBytes(List<int> bytes) async {
  if (bytes.length != secretKeyLength) {
    throw ArgumentError('Invalid secret key length');
  }
  return SecretKeyData(
    Uint8List.fromList(bytes),
    overwriteWhenDestroyed: true, // We copied the bytes so overwriting is ok.
  );
}
@justkawal
Copy link

I think because of the parallel web-support which enforces usage as Future<>.

@busslina
Copy link
Author

busslina commented Nov 5, 2023

You can use this design:

abstract interface class Interface {
  FutureOr<SecretKey> newSecretKeyFromBytes(List<int> bytes);
}

class ImplementationWeb extends Interface {
  @override
  Future<SecretKey> newSecretKeyFromBytes(List<int> bytes) =>
      throw ('Not implemented');
}

class ImplementationNative extends Interface {
  @override
  SecretKey newSecretKeyFromBytes(List<int> bytes) => throw ('Not implemented');
}

This async is make me changing too much method signatures

@daegalus
Copy link

daegalus commented Feb 8, 2024

I would have to agree with this. I want to use cryptography in the uuid library, but it being async, would require me to change my entire library to async functions, which would not only break everyone using the library, but is unnecessary.

The above design would go a long way to solving that for those that don't need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants