Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/revlog/path_encode.rs @ 47380:fad504cfc94b
rust: Use a maintained crate for SHA-1 hashing
https://crates.io/crates/rust-crypto hasn?t been updated in 5 years.
This doesn?t neccesarily mean there?s anything wrong with it, but if
something comes up it?s preferable to rely on libraries that have active
maintainers.
Use https://crates.io/crates/sha-1 from https://github.com/RustCrypto instead
Differential Revision: https://phab.mercurial-scm.org/D10835
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 02 Jun 2021 10:00:50 +0200 |
parents | aebc976fd7d5 |
children | e98fd81bb151 |
comparison
equal
deleted
inserted
replaced
47379:f6bb181c75f8 | 47380:fad504cfc94b |
---|---|
1 use crypto::digest::Digest; | 1 use sha1::{Digest, Sha1}; |
2 use crypto::sha1::Sha1; | |
3 | 2 |
4 #[derive(PartialEq, Debug)] | 3 #[derive(PartialEq, Debug)] |
5 #[allow(non_camel_case_types)] | 4 #[allow(non_camel_case_types)] |
6 enum path_state { | 5 enum path_state { |
7 START, /* first byte of a path component */ | 6 START, /* first byte of a path component */ |
619 let baselen = (src.len() - 5) * 3; | 618 let baselen = (src.len() - 5) * 3; |
620 if baselen >= MAXENCODE { | 619 if baselen >= MAXENCODE { |
621 panic!("path_encode::hash_encore: string too long: {}", baselen) | 620 panic!("path_encode::hash_encore: string too long: {}", baselen) |
622 }; | 621 }; |
623 let dirlen = encode_dir(Some(&mut dired[..]), src); | 622 let dirlen = encode_dir(Some(&mut dired[..]), src); |
624 let sha = { | 623 let sha = Sha1::digest(&dired[..dirlen]); |
625 let mut hasher = Sha1::new(); | |
626 hasher.input(&dired[..dirlen]); | |
627 let mut hash = vec![0; 20]; | |
628 hasher.result(&mut hash); | |
629 hash | |
630 }; | |
631 let lowerlen = lower_encode(Some(&mut lowered[..]), &dired[..dirlen][5..]); | 624 let lowerlen = lower_encode(Some(&mut lowered[..]), &dired[..dirlen][5..]); |
632 let auxlen = aux_encode(Some(&mut auxed[..]), &lowered[..lowerlen]); | 625 let auxlen = aux_encode(Some(&mut auxed[..]), &lowered[..lowerlen]); |
633 hash_mangle(&auxed[..auxlen], &sha) | 626 hash_mangle(&auxed[..auxlen], &sha) |
634 } | 627 } |
635 | 628 |