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

Treat newtypes as passthrough containers when encoding/decoding #85

Closed
orthecreedence opened this issue Mar 17, 2022 · 3 comments
Closed

Comments

@orthecreedence
Copy link
Contributor

Hello! I'm just starting to use this project and it's everything I want in a DER encoder/decoder (especially the derive macros, which are incredibly helpful). One thing I'm wondering if is there's a built-in way to have something like this:

#[derive(Debug, AsnType, Encode, Decode)]
struct SignatureWrapper(Bytes);

#[derive(Debug, AsnType, Encode, Decode)]
#[rasn(choice)]
enum Signature {
    #[rasn(tag(0))]
    Ed25519(SignatureWrapper),
}

And encode it as if SignatureWrapper was just a Bytes. Right now, it seems to wrap it. Is there a #[rasn(...)] attribute that can do this, or would this be something I'd need to open a PR for? Thank you!

@orthecreedence
Copy link
Contributor Author

You know what, I don't think I need this actually. Since rust got [u8; N] const generic support I can just manually implement Encode/Decode for one type that covers everything. I'll leave it open in case you find it useful still, but if not, feel free to close.

@XAMPPRocky
Copy link
Collaborator

XAMPPRocky commented Mar 18, 2022

Thank you for your issue! This functionality is already available in rasn. Simply add #[rasn(delegate)] to the newtype, and then it will be transparently encoded and decoded.

@orthecreedence
Copy link
Contributor Author

Oh, well how about that. That's great to know. Thanks!

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

2 participants