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

digest: implement Update for Vec<u8> #1630

Closed
wants to merge 1 commit into from

Conversation

baloo
Copy link
Member

@baloo baloo commented Jul 27, 2024

In use-cases like https://github.com/RustCrypto/SSH/blob/a6f33709d6a48d82c818a9bdec87fe3a96b027ca/ssh-encoding/src/writer.rs#L19 it is not currently possible to write things like;

impl<D> Writer for D
where
    D: digest::Update,
{
    fn write(&mut self, bytes: &[u8]) -> Result<()> {
        self.update(bytes);
        Ok(())
    }
}

to get a writer implementation for T: Digest.

This isn't currently possible because of the following error:

error[E0119]: conflicting implementations of trait `Writer` for type `Vec<u8>`
   |
21 |   impl Writer for Vec<u8> {
   |   ----------------------- first implementation here
...
44 | / impl<D> Writer for D
45 | | where
46 | |     D: Update,
   | |______________^ conflicting implementation for `Vec<u8>`
   |
   = note: upstream crates may add a new impl of trait `digest::Update` for type `alloc::vec::Vec<u8>` in future versions

Although this is technically incorrect, as Vec isn't a digest, an Update implementation still seems relevant.

In use-cases like https://github.com/RustCrypto/SSH/blob/a6f33709d6a48d82c818a9bdec87fe3a96b027ca/ssh-encoding/src/writer.rs#L19
it is not currently possible to write things like;
``` rust
impl<D> Writer for D
where
    D: digest::Update,
{
    fn write(&mut self, bytes: &[u8]) -> Result<()> {
        self.update(bytes);
        Ok(())
    }
}
```

This isn't currently possible because of the following error:
```
error[E0119]: conflicting implementations of trait `Writer` for type `Vec<u8>`
   |
21 |   impl Writer for Vec<u8> {
   |   ----------------------- first implementation here
...
44 | / impl<D> Writer for D
45 | | where
46 | |     D: Update,
   | |______________^ conflicting implementation for `Vec<u8>`
   |
   = note: upstream crates may add a new impl of trait `digest::Update` for type `alloc::vec::Vec<u8>` in future versions
```

Although this is technically incorrect, as Vec isn't a digest,
an `Update` implementation still seems relevant.
@baloo baloo changed the title digest: implement Update for Vec<u8> digest: implement Update for Vec<u8> Jul 27, 2024
@newpavlov
Copy link
Member

This looks like too much of a hack to me. I think a better solution will be to introduce a DigestWriter wrapper struct.

@baloo
Copy link
Member Author

baloo commented Jul 29, 2024

that's a fair point.

@baloo baloo closed this Jul 29, 2024
@baloo baloo deleted the baloo/digest/vec-update branch July 29, 2024 17:19
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.

2 participants