google / webcrypto.dart

Cross-platform implementation of Web Cryptography APIs
https://pub.dev/packages/webcrypto
Apache License 2.0
71 stars 43 forks source link

Avoid @sealed annotation, using `final class` for everything #105

Open jonasfj opened 1 month ago

jonasfj commented 1 month ago

We should use final class for everything in the public API.

Motiviation:

In practice, we might have to do something that we export from src/webcrypto/webcrypto.dart and something we only export to other libraries inside this package.

// This is exported from lib/webcrypto.dart
// This means that in lib/webcrypto we have to use "show"
// to avoid exporting KeyPairBase.
// Example:
//   export src/webcrypto.dart show KeyPair;
abstract final class KeyPair<S, T> {
  /// Private key for [publicKey].
  S get privateKey;

  /// Public key matching [privateKey].
  T get publicKey;
}

// This is not exported from lib/webcrypto.dart
// but implementations for different platforms can import this from
// src/webcrypto/webcrypto.dart
// and extend it inorder to implement KeyPair
abstract base class KeyPairBase<S, T> extends KeyPair<S, T> {}
devenderbutani21 commented 1 month ago

Hello! I would like to work in this issue.

jonasfj commented 1 month ago

Assigned to you.

This is mostly a bit of refactoring and making sure the public API is pretty, while also making sure people accessing it can't implement our classes :D

jonasfj commented 1 month ago

Might I suggest trying it out on something simple like HmacSecretKey, making a WIP (draft) PR, so that we can decide if we like that pattern before we apply the same pattern consistently across all public classes.

side note. we'll probably also need to bump the version number and write an entry in CHANGELOG.md.