Skip to content

Request for Examples: Clarifying Generic Type Constraints for Multi-Algorithm Abstraction #725

@SyntaxError6666

Description

@SyntaxError6666

Description
Hello,
Thank you for developing and maintaining the aead-stream crate. I am currently working on integrating it into a project and have run into some challenges with the type system that I hope you could help clarify.

My Goal:
I am attempting to write a thin abstraction layer on top of aead-stream to handle more complex operations, such as file encryption. A key requirement for this layer is to be generic, allowing it to work with different underlying algorithms (specifically, ChaCha20Poly1305 and AES-256-GCM).

The Problem:
I have opted to use EncryptorLE31, one of the primary tasks of my abstraction layer is to simultaneously accommodate both the AES-256-GCM and ChaCha20Poly1305 algorithms.
Limitations of my own technical abilities, the number of interrelated generic parameters and associated types (A, S, StreamPrimitive, NewStream, NonceSize, etc.) has made it difficult to correctly express the necessary trait bounds. My attempts to define a struct or function that is generic over both the AEAD cipher and the STREAM primitive have repeatedly failed to compile, with errors often relating to unsatisfied trait bounds or mismatched associated types.

Request:
Could one or more practical examples be added to the documentation to demonstrate how to correctly define generic data structures and functions that can simultaneously accommodate multiple AEAD algorithms (A) (in my case, AES-256-GCM and ChaCha20Poly1305) and STREAM types (S)?

Specifically, the following examples would be significantly helpful:

  • Demonstrating how to correctly express the limitations of AEAD algorithms in high-level encapsulation (i.e., how to design a struct or other structure compatible with various AEAD algorithms).

  • Demonstrating how to securely and correctly generate a Key and Nonce compatible with this crate.

Thank you for your time and consideration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions