Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use the correct header collection for Docker-Content-Digest #135

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/OrasProject.Oras/Content/Digest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ namespace OrasProject.Oras.Content;

internal static class Digest
{
private const string digestRegexPattern = @"[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+";
private static readonly Regex digestRegex = new Regex(digestRegexPattern, RegexOptions.Compiled);
private const string _digestRegexPattern = @"[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+";
private static readonly Regex _digestRegex = new Regex(_digestRegexPattern, RegexOptions.Compiled);

/// <summary>
/// Verifies the digest header and throws an exception if it is invalid.
/// </summary>
/// <param name="digest"></param>
internal static string Validate(string? digest)
{
if (string.IsNullOrEmpty(digest) || !digestRegex.IsMatch(digest))
if (string.IsNullOrEmpty(digest) || !_digestRegex.IsMatch(digest))
{
throw new InvalidDigestException($"Invalid digest: {digest}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace OrasProject.Oras.Registry.Remote;

internal static class HttpResponseMessageExtensions
{
private const string _dockerContentDigestHeader = "Docker-Content-Digest";

/// <summary>
/// Parses the error returned by the remote registry.
/// </summary>
Expand Down Expand Up @@ -75,7 +77,7 @@ public static async Task<Exception> ParseErrorResponseAsync(this HttpResponseMes
/// <exception cref="NotImplementedException"></exception>
public static void VerifyContentDigest(this HttpResponseMessage response, string expected)
{
if (!response.Content.Headers.TryGetValues("Docker-Content-Digest", out var digestValues))
if (!response.Headers.TryGetValues(_dockerContentDigestHeader, out var digestValues))
{
return;
}
Expand Down Expand Up @@ -154,7 +156,7 @@ public static async Task<Descriptor> GenerateDescriptorAsync(this HttpResponseMe

// 4. Validate Server Digest (if present)
string? serverDigest = null;
if (response.Content.Headers.TryGetValues("Docker-Content-Digest", out var serverHeaderDigest))
if (response.Headers.TryGetValues(_dockerContentDigestHeader, out var serverHeaderDigest))
{
serverDigest = serverHeaderDigest.FirstOrDefault();
if (!string.IsNullOrEmpty(serverDigest))
Expand Down
Loading
Loading