##// END OF EJS Templates
rust: Use a maintained crate for SHA-1 hashing...
Simon Sapin -
r48171:fad504cf default
parent child Browse files
Show More
@@ -57,6 +57,15 b' dependencies = ['
57 ]
57 ]
58
58
59 [[package]]
59 [[package]]
60 name = "block-buffer"
61 version = "0.9.0"
62 source = "registry+https://github.com/rust-lang/crates.io-index"
63 checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
64 dependencies = [
65 "generic-array",
66 ]
67
68 [[package]]
60 name = "byteorder"
69 name = "byteorder"
61 version = "1.3.4"
70 version = "1.3.4"
62 source = "registry+https://github.com/rust-lang/crates.io-index"
71 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -138,6 +147,15 b' source = "registry+https://github.com/ru'
138 checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
147 checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
139
148
140 [[package]]
149 [[package]]
150 name = "cpufeatures"
151 version = "0.1.4"
152 source = "registry+https://github.com/rust-lang/crates.io-index"
153 checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8"
154 dependencies = [
155 "libc",
156 ]
157
158 [[package]]
141 name = "cpython"
159 name = "cpython"
142 version = "0.5.2"
160 version = "0.5.2"
143 source = "registry+https://github.com/rust-lang/crates.io-index"
161 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -254,6 +272,15 b' source = "registry+https://github.com/ru'
254 checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
272 checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
255
273
256 [[package]]
274 [[package]]
275 name = "digest"
276 version = "0.9.0"
277 source = "registry+https://github.com/rust-lang/crates.io-index"
278 checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
279 dependencies = [
280 "generic-array",
281 ]
282
283 [[package]]
257 name = "either"
284 name = "either"
258 version = "1.6.1"
285 version = "1.6.1"
259 source = "registry+https://github.com/rust-lang/crates.io-index"
286 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -308,16 +335,14 b' dependencies = ['
308 ]
335 ]
309
336
310 [[package]]
337 [[package]]
311 name = "fuchsia-cprng"
338 name = "generic-array"
312 version = "0.1.1"
339 version = "0.14.4"
313 source = "registry+https://github.com/rust-lang/crates.io-index"
340 source = "registry+https://github.com/rust-lang/crates.io-index"
314 checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
341 checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
315
342 dependencies = [
316 [[package]]
343 "typenum",
317 name = "gcc"
344 "version_check",
318 version = "0.3.55"
345 ]
319 source = "registry+https://github.com/rust-lang/crates.io-index"
320 checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
321
346
322 [[package]]
347 [[package]]
323 name = "getrandom"
348 name = "getrandom"
@@ -364,13 +389,13 b' dependencies = ['
364 "memmap",
389 "memmap",
365 "micro-timer",
390 "micro-timer",
366 "pretty_assertions",
391 "pretty_assertions",
367 "rand 0.7.3",
392 "rand",
368 "rand_distr",
393 "rand_distr",
369 "rand_pcg",
394 "rand_pcg",
370 "rayon",
395 "rayon",
371 "regex",
396 "regex",
372 "rust-crypto",
373 "same-file",
397 "same-file",
398 "sha-1",
374 "tempfile",
399 "tempfile",
375 "twox-hash",
400 "twox-hash",
376 "zstd",
401 "zstd",
@@ -413,7 +438,7 b' source = "registry+https://github.com/ru'
413 checksum = "3ca8957e71f04a205cb162508f9326aea04676c8dfd0711220190d6b83664f3f"
438 checksum = "3ca8957e71f04a205cb162508f9326aea04676c8dfd0711220190d6b83664f3f"
414 dependencies = [
439 dependencies = [
415 "bitmaps",
440 "bitmaps",
416 "rand_core 0.5.1",
441 "rand_core",
417 "rand_xoshiro",
442 "rand_xoshiro",
418 "sized-chunks",
443 "sized-chunks",
419 "typenum",
444 "typenum",
@@ -563,6 +588,12 b' dependencies = ['
563 ]
588 ]
564
589
565 [[package]]
590 [[package]]
591 name = "opaque-debug"
592 version = "0.3.0"
593 source = "registry+https://github.com/rust-lang/crates.io-index"
594 checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
595
596 [[package]]
566 name = "output_vt100"
597 name = "output_vt100"
567 version = "0.1.2"
598 version = "0.1.2"
568 source = "registry+https://github.com/rust-lang/crates.io-index"
599 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -666,29 +697,6 b' dependencies = ['
666
697
667 [[package]]
698 [[package]]
668 name = "rand"
699 name = "rand"
669 version = "0.3.23"
670 source = "registry+https://github.com/rust-lang/crates.io-index"
671 checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
672 dependencies = [
673 "libc",
674 "rand 0.4.6",
675 ]
676
677 [[package]]
678 name = "rand"
679 version = "0.4.6"
680 source = "registry+https://github.com/rust-lang/crates.io-index"
681 checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
682 dependencies = [
683 "fuchsia-cprng",
684 "libc",
685 "rand_core 0.3.1",
686 "rdrand",
687 "winapi",
688 ]
689
690 [[package]]
691 name = "rand"
692 version = "0.7.3"
700 version = "0.7.3"
693 source = "registry+https://github.com/rust-lang/crates.io-index"
701 source = "registry+https://github.com/rust-lang/crates.io-index"
694 checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
702 checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
@@ -696,7 +704,7 b' dependencies = ['
696 "getrandom",
704 "getrandom",
697 "libc",
705 "libc",
698 "rand_chacha",
706 "rand_chacha",
699 "rand_core 0.5.1",
707 "rand_core",
700 "rand_hc",
708 "rand_hc",
701 ]
709 ]
702
710
@@ -707,26 +715,11 b' source = "registry+https://github.com/ru'
707 checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
715 checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
708 dependencies = [
716 dependencies = [
709 "ppv-lite86",
717 "ppv-lite86",
710 "rand_core 0.5.1",
718 "rand_core",
711 ]
719 ]
712
720
713 [[package]]
721 [[package]]
714 name = "rand_core"
722 name = "rand_core"
715 version = "0.3.1"
716 source = "registry+https://github.com/rust-lang/crates.io-index"
717 checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
718 dependencies = [
719 "rand_core 0.4.2",
720 ]
721
722 [[package]]
723 name = "rand_core"
724 version = "0.4.2"
725 source = "registry+https://github.com/rust-lang/crates.io-index"
726 checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
727
728 [[package]]
729 name = "rand_core"
730 version = "0.5.1"
723 version = "0.5.1"
731 source = "registry+https://github.com/rust-lang/crates.io-index"
724 source = "registry+https://github.com/rust-lang/crates.io-index"
732 checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
725 checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
@@ -740,7 +733,7 b' version = "0.2.2"'
740 source = "registry+https://github.com/rust-lang/crates.io-index"
733 source = "registry+https://github.com/rust-lang/crates.io-index"
741 checksum = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2"
734 checksum = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2"
742 dependencies = [
735 dependencies = [
743 "rand 0.7.3",
736 "rand",
744 ]
737 ]
745
738
746 [[package]]
739 [[package]]
@@ -749,7 +742,7 b' version = "0.2.0"'
749 source = "registry+https://github.com/rust-lang/crates.io-index"
742 source = "registry+https://github.com/rust-lang/crates.io-index"
750 checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
743 checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
751 dependencies = [
744 dependencies = [
752 "rand_core 0.5.1",
745 "rand_core",
753 ]
746 ]
754
747
755 [[package]]
748 [[package]]
@@ -758,7 +751,7 b' version = "0.2.1"'
758 source = "registry+https://github.com/rust-lang/crates.io-index"
751 source = "registry+https://github.com/rust-lang/crates.io-index"
759 checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
752 checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
760 dependencies = [
753 dependencies = [
761 "rand_core 0.5.1",
754 "rand_core",
762 ]
755 ]
763
756
764 [[package]]
757 [[package]]
@@ -767,7 +760,7 b' version = "0.4.0"'
767 source = "registry+https://github.com/rust-lang/crates.io-index"
760 source = "registry+https://github.com/rust-lang/crates.io-index"
768 checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004"
761 checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004"
769 dependencies = [
762 dependencies = [
770 "rand_core 0.5.1",
763 "rand_core",
771 ]
764 ]
772
765
773 [[package]]
766 [[package]]
@@ -796,15 +789,6 b' dependencies = ['
796 ]
789 ]
797
790
798 [[package]]
791 [[package]]
799 name = "rdrand"
800 version = "0.4.0"
801 source = "registry+https://github.com/rust-lang/crates.io-index"
802 checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
803 dependencies = [
804 "rand_core 0.3.1",
805 ]
806
807 [[package]]
808 name = "redox_syscall"
792 name = "redox_syscall"
809 version = "0.1.57"
793 version = "0.1.57"
810 source = "registry+https://github.com/rust-lang/crates.io-index"
794 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -855,25 +839,6 b' dependencies = ['
855 ]
839 ]
856
840
857 [[package]]
841 [[package]]
858 name = "rust-crypto"
859 version = "0.2.36"
860 source = "registry+https://github.com/rust-lang/crates.io-index"
861 checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
862 dependencies = [
863 "gcc",
864 "libc",
865 "rand 0.3.23",
866 "rustc-serialize",
867 "time",
868 ]
869
870 [[package]]
871 name = "rustc-serialize"
872 version = "0.3.24"
873 source = "registry+https://github.com/rust-lang/crates.io-index"
874 checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
875
876 [[package]]
877 name = "same-file"
842 name = "same-file"
878 version = "1.0.6"
843 version = "1.0.6"
879 source = "registry+https://github.com/rust-lang/crates.io-index"
844 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -889,6 +854,19 b' source = "registry+https://github.com/ru'
889 checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
854 checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
890
855
891 [[package]]
856 [[package]]
857 name = "sha-1"
858 version = "0.9.6"
859 source = "registry+https://github.com/rust-lang/crates.io-index"
860 checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16"
861 dependencies = [
862 "block-buffer",
863 "cfg-if 1.0.0",
864 "cpufeatures",
865 "digest",
866 "opaque-debug",
867 ]
868
869 [[package]]
892 name = "sized-chunks"
870 name = "sized-chunks"
893 version = "0.6.2"
871 version = "0.6.2"
894 source = "registry+https://github.com/rust-lang/crates.io-index"
872 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -929,7 +907,7 b' checksum = "7a6e24d9338a0a5be79593e2fa15'
929 dependencies = [
907 dependencies = [
930 "cfg-if 0.1.10",
908 "cfg-if 0.1.10",
931 "libc",
909 "libc",
932 "rand 0.7.3",
910 "rand",
933 "redox_syscall",
911 "redox_syscall",
934 "remove_dir_all",
912 "remove_dir_all",
935 "winapi",
913 "winapi",
@@ -980,7 +958,7 b' source = "registry+https://github.com/ru'
980 checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59"
958 checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59"
981 dependencies = [
959 dependencies = [
982 "cfg-if 0.1.10",
960 "cfg-if 0.1.10",
983 "rand 0.7.3",
961 "rand",
984 "static_assertions",
962 "static_assertions",
985 ]
963 ]
986
964
@@ -21,6 +21,7 b' rand_pcg = "0.2.1"'
21 rand_distr = "0.2.2"
21 rand_distr = "0.2.2"
22 rayon = "1.3.0"
22 rayon = "1.3.0"
23 regex = "1.3.9"
23 regex = "1.3.9"
24 sha-1 = "0.9.6"
24 twox-hash = "1.5.0"
25 twox-hash = "1.5.0"
25 same-file = "1.0.6"
26 same-file = "1.0.6"
26 tempfile = "3.1.0"
27 tempfile = "3.1.0"
@@ -29,7 +30,6 b' micro-timer = "0.3.0"'
29 log = "0.4.8"
30 log = "0.4.8"
30 memmap = "0.7.0"
31 memmap = "0.7.0"
31 zstd = "0.5.3"
32 zstd = "0.5.3"
32 rust-crypto = "0.2.36"
33 format-bytes = "0.2.2"
33 format-bytes = "0.2.2"
34
34
35 # We don't use the `miniz-oxide` backend to not change rhg benchmarks and until
35 # We don't use the `miniz-oxide` backend to not change rhg benchmarks and until
@@ -1,5 +1,4 b''
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)]
@@ -621,13 +620,7 b' fn hash_encode(src: &[u8]) -> Vec<u8> {'
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)
@@ -4,10 +4,9 b' use std::ops::Deref;'
4 use std::path::Path;
4 use std::path::Path;
5
5
6 use byteorder::{BigEndian, ByteOrder};
6 use byteorder::{BigEndian, ByteOrder};
7 use crypto::digest::Digest;
8 use crypto::sha1::Sha1;
9 use flate2::read::ZlibDecoder;
7 use flate2::read::ZlibDecoder;
10 use micro_timer::timed;
8 use micro_timer::timed;
9 use sha1::{Digest, Sha1};
11 use zstd;
10 use zstd;
12
11
13 use super::index::Index;
12 use super::index::Index;
@@ -221,7 +220,7 b' impl Revlog {'
221 None => &NULL_NODE,
220 None => &NULL_NODE,
222 };
221 };
223
222
224 hash(data, h1.as_bytes(), h2.as_bytes()).as_slice() == expected
223 &hash(data, h1.as_bytes(), h2.as_bytes()) == expected
225 }
224 }
226
225
227 /// Build the full data of a revision out its snapshot
226 /// Build the full data of a revision out its snapshot
@@ -361,20 +360,22 b' pub fn get_version(index_bytes: &[u8]) -'
361 }
360 }
362
361
363 /// Calculate the hash of a revision given its data and its parents.
362 /// Calculate the hash of a revision given its data and its parents.
364 fn hash(data: &[u8], p1_hash: &[u8], p2_hash: &[u8]) -> Vec<u8> {
363 fn hash(
364 data: &[u8],
365 p1_hash: &[u8],
366 p2_hash: &[u8],
367 ) -> [u8; NODE_BYTES_LENGTH] {
365 let mut hasher = Sha1::new();
368 let mut hasher = Sha1::new();
366 let (a, b) = (p1_hash, p2_hash);
369 let (a, b) = (p1_hash, p2_hash);
367 if a > b {
370 if a > b {
368 hasher.input(b);
371 hasher.update(b);
369 hasher.input(a);
372 hasher.update(a);
370 } else {
373 } else {
371 hasher.input(a);
374 hasher.update(a);
372 hasher.input(b);
375 hasher.update(b);
373 }
376 }
374 hasher.input(data);
377 hasher.update(data);
375 let mut hash = vec![0; NODE_BYTES_LENGTH];
378 *hasher.finalize().as_ref()
376 hasher.result(&mut hash);
377 hash
378 }
379 }
379
380
380 #[cfg(test)]
381 #[cfg(test)]
General Comments 0
You need to be logged in to leave comments. Login now