Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
seahash
seahash
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1
    • Issues 1
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • redox-os
  • seahashseahash
  • Issues
  • #8

Closed
Open
Opened Jul 31, 2020 by jRimbault@jRimbaultContributor

Implement the Write trait ?

Hi,

I've used seahash in the past, and yesterday I was reading this and I thought it would be "neat" to also have the Write trait implemented for the SeaHasher.

I'm copying the example I linked:

use seahash::SeaHasher;
use std::{fs, io};

let mut file = fs::File::open(&path)?;
let mut hasher = SeaHasher::new();
let n = io::copy(&mut file, &mut hasher)?;
let hash = hasher.finish();

I think it would require very little additional code to do:

use core::hash::Hasher;

#[cfg(feature = "std")]
impl std::io::Write for SeaHasher {
    fn write(&mut self, buf: &[u8]) -> st::io::Result<usize> {
        Hasher::write(self, buf);
        Ok(buf.len())
    }
    fn flush(&mut self) -> std::io::Result<()> {
        Ok(())
    }
}

Just an idea. But when I wanted to hash a whole file I ended writing almost the same code as the canonical io::copy. It can be placed behind an "std" feature flag.

Edited Jul 31, 2020 by jRimbault
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: redox-os/seahash#8