diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-13 15:06:22 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-13 15:11:17 +0100 |
commit | a1d6524dce0a382fbcaff5da125363bdebe3ded4 (patch) | |
tree | bd19eecb8e834ed713038844e51249838d07d918 /src/package | |
parent | 1b30ed76539c83f58cf3c3929b991e1360842623 (diff) |
Revert "Reimplement hash verification"
This reverts commit c3fc1281142ec10414197a31070cc45930a859e3
and commit 18b256e040881ac674463913b2a7e290125ea738.
The problem here is that we introduced "ring" to our dependencies, which has a
unappropriate license (ISC and openssl thing).
We should not depend on such a library, because it may conflict with our own EPL
2.0 (IANAL).
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/package')
-rw-r--r-- | src/package/source.rs | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/package/source.rs b/src/package/source.rs index 8312f1f..9584803 100644 --- a/src/package/source.rs +++ b/src/package/source.rs @@ -8,8 +8,6 @@ // SPDX-License-Identifier: EPL-2.0 // -use std::io::Read; - use anyhow::Result; use anyhow::anyhow; use getset::Getters; @@ -45,9 +43,9 @@ pub struct SourceHash { } impl SourceHash { - pub fn matches_hash_of<R: Read>(&self, reader: R) -> Result<()> { + pub fn matches_hash_of(&self, buf: &[u8]) -> Result<()> { trace!("Hashing buffer with: {:?}", self.hashtype); - let h = self.hashtype.hash_from_reader(reader)?; + let h = self.hashtype.hash_buffer(&buf)?; trace!("Hashing buffer with: {} finished", self.hashtype); if h == self.value { @@ -82,24 +80,29 @@ pub enum HashType { } impl HashType { - fn hash_from_reader<R: Read>(&self, mut reader: R) -> Result<HashValue> { - use ring::digest::{Context, SHA1_FOR_LEGACY_USE_ONLY, SHA256, SHA512}; - let mut context = match self { - HashType::Sha1 => Context::new(&SHA1_FOR_LEGACY_USE_ONLY), - HashType::Sha256 => Context::new(&SHA256), - HashType::Sha512 => Context::new(&SHA512), - }; - let mut buffer = [0; 1024]; - - loop { - let count = reader.read(&mut buffer)?; - if count == 0 { - break; - } - context.update(&buffer[..count]); + fn hash_buffer(&self, buffer: &[u8]) -> Result<HashValue> { + match self { + HashType::Sha1 => { + trace!("SHA1 hashing buffer"); + let mut m = sha1::Sha1::new(); + m.update(buffer); + Ok(HashValue(m.digest().to_string())) + }, + HashType::Sha256 => { + trace!("SHA256 hashing buffer"); + //let mut m = sha2::Sha256::new(); + //m.update(buffer); + //Ok(HashValue(String::from(m.finalize()))) + unimplemented!() + }, + HashType::Sha512 => { + trace!("SHA512 hashing buffer"); + //let mut m = sha2::Sha512::new(); + //m.update(buffer); + //Ok(HashValue(String::from(m.finalize()))) + unimplemented!() + }, } - - Ok(HashValue(data_encoding::HEXLOWER.encode(context.finish().as_ref()))) } } |