awslabs / mls-rs

An implementation of Messaging Layer Security (RFC 9420)
Apache License 2.0
105 stars 19 forks source link

Private `Config` type system complicates storing `Client<C: MlsConfig>` in container structs #181

Closed mcginty closed 2 months ago

mcginty commented 3 months ago

I've been playing around with mls-rs, and as my code gets more complex, I tend to find it helpful to write higher-level wrappers around a lower level API like Client offers.

This pattern with the current accessibility of the internal Config types seems to complicate this as you use a builder that ends up straying from the publicly exposed BaseSqlConfig, for example.

Example problem that shows the private type that I can't specify in a struct definition:

error[E0308]: mismatched types
  --> mls-test/src/mls_wrapper.rs:89:19
   = note: expected struct `Client<C>`
              found struct `Client<client_builder::private::Config<SqLiteKeyPackageStorage, SqLitePreSharedKeyStorage, SqLiteGroupStateStorage, BasicIdentityProvider, DefaultMlsRules, OpensslCryptoProvider>>`

Is there a recommended way to accomplish this with the current API and/or would you consider making the Config trait public to allow this pattern to be used?

mulmarta commented 3 months ago

You can create the same type as Client<client_builder::private::Config<SqLiteKeyPackageStorage, SqLitePreSharedKeyStorage, SqLiteGroupStateStorage, BasicIdentityProvider, DefaultMlsRules, OpensslCryptoProvider>> using Client<WithIdentityProvider<BasicIdentityProvider, WithCryptoProvider<OpensslCryptoProvider, BaseSqlConfig>>>

Would this help? Basically WithIdentityProvider<X, Config> overwrites anything Config has for the identity provider with X