Skip to content

Commit cd4b1a4

Browse files
committed
Add support for BLAKE2b-256
1 parent 990c59d commit cd4b1a4

File tree

8 files changed

+121
-20
lines changed

8 files changed

+121
-20
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ axoupdater = { version = "0.9.0", default-features = false }
8484
backon = { version = "1.3.0" }
8585
base64 = { version = "0.22.1" }
8686
bitflags = { version = "2.6.0" }
87+
blake2 = { version = "0.10.6" }
8788
boxcar = { version = "0.2.5" }
8889
bytecheck = { version = "0.8.0" }
8990
cargo-util = { version = "0.2.14" }

crates/uv-client/src/html.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ mod tests {
305305
),
306306
sha384: None,
307307
sha512: None,
308+
blake2b: None,
308309
},
309310
requires_python: None,
310311
size: None,
@@ -361,6 +362,7 @@ mod tests {
361362
sha256: None,
362363
sha384: None,
363364
sha512: None,
365+
blake2b: None,
364366
},
365367
requires_python: None,
366368
size: None,
@@ -420,6 +422,7 @@ mod tests {
420422
),
421423
sha384: None,
422424
sha512: None,
425+
blake2b: None,
423426
},
424427
requires_python: None,
425428
size: None,
@@ -476,6 +479,7 @@ mod tests {
476479
),
477480
sha384: None,
478481
sha512: None,
482+
blake2b: None,
479483
},
480484
requires_python: None,
481485
size: None,
@@ -532,6 +536,7 @@ mod tests {
532536
),
533537
sha384: None,
534538
sha512: None,
539+
blake2b: None,
535540
},
536541
requires_python: None,
537542
size: None,
@@ -558,7 +563,7 @@ mod tests {
558563
"#;
559564
let base = Url::parse("https://download.pytorch.org/whl/jinja2/").unwrap();
560565
let result = SimpleHtml::parse(text, &base).unwrap();
561-
insta::assert_debug_snapshot!(result, @r###"
566+
insta::assert_debug_snapshot!(result, @r#"
562567
SimpleHtml {
563568
base: BaseUrl(
564569
Url {
@@ -586,6 +591,7 @@ mod tests {
586591
sha256: None,
587592
sha384: None,
588593
sha512: None,
594+
blake2b: None,
589595
},
590596
requires_python: None,
591597
size: None,
@@ -595,7 +601,7 @@ mod tests {
595601
},
596602
],
597603
}
598-
"###);
604+
"#);
599605
}
600606

601607
#[test]
@@ -612,7 +618,7 @@ mod tests {
612618
"#;
613619
let base = Url::parse("https://download.pytorch.org/whl/jinja2/").unwrap();
614620
let result = SimpleHtml::parse(text, &base).unwrap();
615-
insta::assert_debug_snapshot!(result, @r###"
621+
insta::assert_debug_snapshot!(result, @r#"
616622
SimpleHtml {
617623
base: BaseUrl(
618624
Url {
@@ -640,6 +646,7 @@ mod tests {
640646
sha256: None,
641647
sha384: None,
642648
sha512: None,
649+
blake2b: None,
643650
},
644651
requires_python: None,
645652
size: None,
@@ -649,7 +656,7 @@ mod tests {
649656
},
650657
],
651658
}
652-
"###);
659+
"#);
653660
}
654661

655662
#[test]
@@ -770,6 +777,7 @@ mod tests {
770777
sha256: None,
771778
sha384: None,
772779
sha512: None,
780+
blake2b: None,
773781
},
774782
requires_python: None,
775783
size: None,
@@ -796,7 +804,7 @@ mod tests {
796804
"#;
797805
let base = Url::parse("https://download.pytorch.org/whl/jinja2/").unwrap();
798806
let result = SimpleHtml::parse(text, &base).unwrap();
799-
insta::assert_debug_snapshot!(result, @r###"
807+
insta::assert_debug_snapshot!(result, @r#"
800808
SimpleHtml {
801809
base: BaseUrl(
802810
Url {
@@ -824,6 +832,7 @@ mod tests {
824832
sha256: None,
825833
sha384: None,
826834
sha512: None,
835+
blake2b: None,
827836
},
828837
requires_python: None,
829838
size: None,
@@ -833,7 +842,7 @@ mod tests {
833842
},
834843
],
835844
}
836-
"###);
845+
"#);
837846
}
838847

839848
#[test]
@@ -879,6 +888,7 @@ mod tests {
879888
sha256: None,
880889
sha384: None,
881890
sha512: None,
891+
blake2b: None,
882892
},
883893
requires_python: None,
884894
size: None,
@@ -935,6 +945,7 @@ mod tests {
935945
sha256: None,
936946
sha384: None,
937947
sha512: None,
948+
blake2b: None,
938949
},
939950
requires_python: None,
940951
size: None,
@@ -962,7 +973,7 @@ mod tests {
962973
"#;
963974
let base = Url::parse("https://download.pytorch.org/whl/jinja2/").unwrap();
964975
let result = SimpleHtml::parse(text, &base).unwrap_err();
965-
insta::assert_snapshot!(result, @"Unsupported hash algorithm (expected one of: `md5`, `sha256`, `sha384`, or `sha512`) on: `blake2=6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61`");
976+
insta::assert_snapshot!(result, @"Unsupported hash algorithm (expected one of: `md5`, `sha256`, `sha384`, `sha512`, or `blake2b`) on: `blake2=6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61`");
966977
}
967978

968979
#[test]
@@ -980,7 +991,7 @@ mod tests {
980991
let base = Url::parse("https://storage.googleapis.com/jax-releases/jax_cuda_releases.html")
981992
.unwrap();
982993
let result = SimpleHtml::parse(text, &base).unwrap();
983-
insta::assert_debug_snapshot!(result, @r###"
994+
insta::assert_debug_snapshot!(result, @r#"
984995
SimpleHtml {
985996
base: BaseUrl(
986997
Url {
@@ -1008,6 +1019,7 @@ mod tests {
10081019
sha256: None,
10091020
sha384: None,
10101021
sha512: None,
1022+
blake2b: None,
10111023
},
10121024
requires_python: None,
10131025
size: None,
@@ -1023,6 +1035,7 @@ mod tests {
10231035
sha256: None,
10241036
sha384: None,
10251037
sha512: None,
1038+
blake2b: None,
10261039
},
10271040
requires_python: None,
10281041
size: None,
@@ -1032,7 +1045,7 @@ mod tests {
10321045
},
10331046
],
10341047
}
1035-
"###);
1048+
"#);
10361049
}
10371050

10381051
/// Test for AWS Code Artifact
@@ -1090,6 +1103,7 @@ mod tests {
10901103
),
10911104
sha384: None,
10921105
sha512: None,
1106+
blake2b: None,
10931107
},
10941108
requires_python: None,
10951109
size: None,
@@ -1107,6 +1121,7 @@ mod tests {
11071121
),
11081122
sha384: None,
11091123
sha512: None,
1124+
blake2b: None,
11101125
},
11111126
requires_python: None,
11121127
size: None,
@@ -1124,6 +1139,7 @@ mod tests {
11241139
),
11251140
sha384: None,
11261141
sha512: None,
1142+
blake2b: None,
11271143
},
11281144
requires_python: Some(
11291145
Ok(
@@ -1190,6 +1206,7 @@ mod tests {
11901206
),
11911207
sha384: None,
11921208
sha512: None,
1209+
blake2b: None,
11931210
},
11941211
requires_python: Some(
11951212
Ok(
@@ -1232,7 +1249,7 @@ mod tests {
12321249
let base = Url::parse("https://account.d.codeartifact.us-west-2.amazonaws.com/pypi/shared-packages-pypi/simple/flask/")
12331250
.unwrap();
12341251
let result = SimpleHtml::parse(text, &base).unwrap();
1235-
insta::assert_debug_snapshot!(result, @r###"
1252+
insta::assert_debug_snapshot!(result, @r#"
12361253
SimpleHtml {
12371254
base: BaseUrl(
12381255
Url {
@@ -1264,6 +1281,7 @@ mod tests {
12641281
sha256: None,
12651282
sha384: None,
12661283
sha512: None,
1284+
blake2b: None,
12671285
},
12681286
requires_python: None,
12691287
size: None,
@@ -1283,6 +1301,7 @@ mod tests {
12831301
sha256: None,
12841302
sha384: None,
12851303
sha512: None,
1304+
blake2b: None,
12861305
},
12871306
requires_python: None,
12881307
size: None,
@@ -1302,6 +1321,7 @@ mod tests {
13021321
sha256: None,
13031322
sha384: None,
13041323
sha512: None,
1324+
blake2b: None,
13051325
},
13061326
requires_python: None,
13071327
size: None,
@@ -1321,6 +1341,7 @@ mod tests {
13211341
sha256: None,
13221342
sha384: None,
13231343
sha512: None,
1344+
blake2b: None,
13241345
},
13251346
requires_python: None,
13261347
size: None,
@@ -1340,6 +1361,7 @@ mod tests {
13401361
sha256: None,
13411362
sha384: None,
13421363
sha512: None,
1364+
blake2b: None,
13431365
},
13441366
requires_python: None,
13451367
size: None,
@@ -1349,6 +1371,6 @@ mod tests {
13491371
},
13501372
],
13511373
}
1352-
"###);
1374+
"#);
13531375
}
13541376
}

crates/uv-extract/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ uv-pypi-types = { workspace = true }
2323
astral-tokio-tar = { workspace = true }
2424
async-compression = { workspace = true, features = ["bzip2", "gzip", "zstd", "xz"] }
2525
async_zip = { workspace = true }
26+
blake2 = { workspace = true }
2627
fs-err = { workspace = true, features = ["tokio"] }
2728
futures = { workspace = true }
2829
md-5 = { workspace = true }

crates/uv-extract/src/hash.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use blake2::digest::consts::U32;
2+
use sha2::Digest;
13
use std::pin::Pin;
24
use std::task::{Context, Poll};
3-
4-
use sha2::Digest;
55
use tokio::io::{AsyncReadExt, ReadBuf};
66

77
use uv_pypi_types::{HashAlgorithm, HashDigest};
@@ -12,6 +12,7 @@ pub enum Hasher {
1212
Sha256(sha2::Sha256),
1313
Sha384(sha2::Sha384),
1414
Sha512(sha2::Sha512),
15+
Blake2b(blake2::Blake2b<U32>),
1516
}
1617

1718
impl Hasher {
@@ -21,6 +22,7 @@ impl Hasher {
2122
Hasher::Sha256(hasher) => hasher.update(data),
2223
Hasher::Sha384(hasher) => hasher.update(data),
2324
Hasher::Sha512(hasher) => hasher.update(data),
25+
Hasher::Blake2b(hasher) => hasher.update(data),
2426
}
2527
}
2628
}
@@ -32,6 +34,7 @@ impl From<HashAlgorithm> for Hasher {
3234
HashAlgorithm::Sha256 => Hasher::Sha256(sha2::Sha256::new()),
3335
HashAlgorithm::Sha384 => Hasher::Sha384(sha2::Sha384::new()),
3436
HashAlgorithm::Sha512 => Hasher::Sha512(sha2::Sha512::new()),
37+
HashAlgorithm::Blake2b => Hasher::Blake2b(blake2::Blake2b::new()),
3538
}
3639
}
3740
}
@@ -55,6 +58,10 @@ impl From<Hasher> for HashDigest {
5558
algorithm: HashAlgorithm::Sha512,
5659
digest: format!("{:x}", hasher.finalize()).into(),
5760
},
61+
Hasher::Blake2b(hasher) => HashDigest {
62+
algorithm: HashAlgorithm::Blake2b,
63+
digest: format!("{:x}", hasher.finalize()).into(),
64+
},
5865
}
5966
}
6067
}

0 commit comments

Comments
 (0)