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

async-signature: move to AFIT #1419

Closed
wants to merge 3 commits into from

Conversation

baloo
Copy link
Member

@baloo baloo commented Dec 14, 2023

AFIT is expected in the upcoming rust-1.75 release (scheduled for 2023/12/28).

#[allow(async_fn_in_trait)] is required until a solution to RPITIT is merged in rust.
This put responsability on the implementor of async_signature::AsyncSigner to make sure their future is Sendable.
see rust-lang/rust#115822 (comment) for more context.

`AFIT` is expected in the upcoming rust-1.75 release (scheduled for
2023/12/28).

`#[allow(async_fn_in_trait)]` is required until a solution to RPITIT is
merged in rust.
This put responsability on the implementor of `async_signature::AsyncSigner`
to make sure their future is `Send`able.
see rust-lang/rust#115822 (comment)
for more context.
@tarcieri
Copy link
Member

You'll need to bump the rustc version used in CI under .github/workflows/async-signature.yml

@baloo
Copy link
Member Author

baloo commented Dec 14, 2023

yeah, but when 1.75 is released right?
I guess I can run that on beta for now until it's released.

I mostly pushed here to get that on a branch (and opened the PR for visibility), so I could pull it from another project (x509-cert).

@tarcieri
Copy link
Member

Yeah, you should be able to switch to beta and it should work (in theory!)

@tarcieri
Copy link
Member

Woohoo, it works(-ish)!

@@ -33,7 +34,6 @@ pub trait AsyncSigner<S: 'static> {
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error>;
}

#[async_trait(?Send)]
impl<S, T> AsyncSigner<S> for T
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much rather have a impl<D, S, T> AsyncSigner<S> for T where T: AsyncDigestSigner<D, S> instead of this blanket.

Copy link
Member

@tarcieri tarcieri Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, you cannot write such a blanket impl, because D is unconstrained (and indeed working around that issue is the whole purpose of the signature-derive:

error[E0207]: the type parameter `D` is not constrained by the impl trait, self type, or predicates

(And though PrehashSignature can define a default digest to use with a particular S, you still won't be able to write a valid blanket impl with it, because it still won't be constrained)

Second, these traits are intended to correspond 1:1 with the traits in signature. If there isn't a blanket impl between Signer and DigestSigner, it doesn't make sense to have one here because that would be inconsistent.

Third, these blanket impls exist so that you can use a Signer as an AsyncSigner, i.e. if you have an API that accepts AsyncSigner, anyone can plug in a Signer, and the same goes for all of the other traits, eliminating the need to duplicate APIs everywhere just for async.

Copy link
Member Author

@baloo baloo Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I oversimplified the previous comment a bit, but yeah I intended:

impl<S, T> AsyncSigner<S> for T
where
    S: PrehashSignature + 'static,
    T: AsyncDigestSigner<S::Digest, S>,
{
    async fn sign_async(&self, msg: &[u8]) -> Result<S, Error> {
        self.sign_digest_async(S::Digest::new_with_prefix(msg))
            .await
    }
}

This is essentially what's in the #[derive(signature::Signer)] I guess I could add that to signature_derive then (should be in the dependency tree, given the proper feature-flags)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does indeed seem to work, but signature has no such blanket impl, so I think it'd be weird for them to be inconsistent.

It could potentially be included in a hypothetical future signature 3.0, although the devil is in the details for these sort of blanket impls, and they may preclude overlapping impls with a valid use case.

@tarcieri
Copy link
Member

Rust 1.75 is out 🎉

@tarcieri
Copy link
Member

Merged in #1428

@tarcieri tarcieri closed this Dec 29, 2023
@baloo
Copy link
Member Author

baloo commented Dec 29, 2023

Thanks!

I was in a plane yesterday and couldn't follow up.

@baloo baloo deleted the baloo/async-signature/afit branch December 29, 2023 21:41
@tarcieri
Copy link
Member

@baloo let me know if v0.5.0-pre.0 works for you and I can cut a final release

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

Successfully merging this pull request may close these issues.

None yet

2 participants