Skip to content

Conversation

@newpavlov
Copy link
Member

@newpavlov newpavlov commented Jul 15, 2020

  • Add FromBlockCipher trait and respective NewMac blanket implementation
  • Bump blobby to v0.3
  • Remove impl_write! macro, since it's useless for generic types

I couldn't make code generic over From<BlockCipher> trait due to the "unconstrained type parameter" error, so I had to introduce a new non-polymorphic trait instead. Any ideas how this problem can be worked around?

@newpavlov newpavlov requested a review from tarcieri July 15, 2020 00:34
@tarcieri
Copy link
Member

I couldn't make code generic over From trait due to the "unconstrained type parameter" error, so I had to introduce a new non-polymorphic trait instead. Any ideas how this problem can be worked around?

What's the concrete error? Do you have a full example?

@newpavlov
Copy link
Member Author

newpavlov commented Jul 15, 2020

I've tried the following code:

impl<T, C> NewMac for T
where
    T: From<C>,
    C: BlockCipher + NewBlockCipher,
{
    type KeySize = C::KeySize;

    fn new(key: &Key<Self>) -> Self {
        C::new(key).into()
    }

    fn new_varkey(key: &[u8]) -> Result<Self, InvalidKeyLength> {
        C::new_varkey(key).map_err(|_| InvalidKeyLength)?.into()
    }
}

And I get this compilation error:

error[E0207]: the type parameter `C` is not constrained by the impl trait, self
type, or predicates
   --> crypto-mac/src/lib.rs:124:9
    |
124 | impl<T, C> NewMac for T
    |         ^ unconstrained type parameter

error: aborting due to previous error

Which in hindsight should've been expected. Right now I have no idea how to properly structure code and if it's even possible in principle.

@tarcieri
Copy link
Member

@newpavlov aah yeah, that looks similar to what I was running into with signature. I ended up solving it with custom derive.

@newpavlov
Copy link
Member Author

So what do you think? Should we go ahead with the current code for the time being?

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Seems fine to me

@newpavlov newpavlov merged commit 18346fd into master Aug 10, 2020
@newpavlov newpavlov deleted the crypto_mac_0.9 branch August 10, 2020 17:55
@tarcieri tarcieri mentioned this pull request Aug 10, 2020
dns2utf8 pushed a commit to dns2utf8/traits that referenced this pull request Jan 24, 2023
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.

3 participants