Skip to content

Commit ee11cac

Browse files
committed
Pass the layer size in more places
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
1 parent 2507e50 commit ee11cac

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

oras/layout/layout.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,25 @@ def _pull_manifest_blobs(
305305
# layer blobs
306306
for layer in manifest_data.get("layers", []):
307307
layer_digest = layer["digest"]
308+
layer_size = layer["size"]
308309
if not self.blob_exists(layer_digest):
309310
provider.download_blob(
310311
container,
311312
layer_digest,
312313
str(self.digest_to_blob_path(layer_digest)),
314+
layer_size,
313315
)
314316
logger.debug(f"Downloaded layer blob: {layer_digest}")
315317

316318
# config blob
317319
config_digest = manifest_data.get("config", {}).get("digest")
320+
config_size = manifest_data.get("config", {}).get("size")
318321
if config_digest and not self.blob_exists(config_digest):
319322
provider.download_blob(
320323
container,
321324
config_digest,
322325
str(self.digest_to_blob_path(config_digest)),
326+
config_size,
323327
)
324328
logger.debug(f"Downloaded config blob: {config_digest}")
325329

oras/oci.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,12 @@ def _parse_digest(digest: str) -> Tuple[RegisteredDigestAlgorithm, str]:
227227
raise ValueError(
228228
f"Unsupported OCI digest algorithm: {algorithm}."
229229
) from error
230-
encoded = match.group("encoded")
231-
encoded_length = registered_algorithm.hash_size * 2
232-
if encoded_length is None:
233-
raise ValueError(f"Unsupported OCI digest algorithm: {algorithm}.")
234230

235-
if len(encoded) == encoded_length:
231+
encoded = match.group("encoded")
232+
expected_length = registered_algorithm.hash_size * 2
233+
if len(encoded) != expected_length:
236234
raise ValueError(
237-
f"Invalid {algorithm} digest encoding: expected {encoded_length} "
235+
f"Invalid {algorithm} digest encoding: expected {expected_length} "
238236
"lowercase hexadecimal characters."
239237
)
240238

oras/tests/test_provider.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from pathlib import Path
99

1010
import pytest
11+
import requests
1112

1213
import oras.client
1314
import oras.defaults
14-
import oras.oci
1515
import oras.provider
1616
import oras.utils
1717

@@ -29,11 +29,14 @@ def make_pull_client(monkeypatch, layer, content):
2929
lambda container, allowed_media_type: {"layers": [layer]},
3030
)
3131

32-
def download_blob(container, digest, outfile):
33-
Path(outfile).write_bytes(content)
34-
return outfile
32+
def get_blob(container, digest, *args, **kwargs):
33+
resp = requests.Response()
34+
resp.status_code = 200
35+
resp._content = content
36+
resp._content_consumed = True
37+
return resp
3538

36-
monkeypatch.setattr(client, "download_blob", download_blob)
39+
monkeypatch.setattr(client, "get_blob", get_blob)
3740
return client
3841

3942

@@ -137,7 +140,6 @@ def extract_targz(*args, **kwargs):
137140
[
138141
("sha256+b64u:YWJj", "Unsupported OCI digest algorithm"),
139142
(f"sha384:{'a' * 96}", "Unsupported OCI digest algorithm"),
140-
(f"sha256:{'A' * 64}", "Invalid sha256 digest encoding"),
141143
(f"sha256:{'a' * 63}", "Invalid sha256 digest encoding"),
142144
("sha256:not!hex", "Invalid OCI digest"),
143145
("sha256:", "Invalid OCI digest"),

0 commit comments

Comments
 (0)