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

chore(model): Introduce and overload of Hash.create() for convenience #8904

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
5 changes: 5 additions & 0 deletions model/src/main/kotlin/Hash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ data class Hash(
"'$value' is not a $algorithm hash."
}
}

/**
* Create a [Hash] instance similar to [create](String,String).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware that we refer to other functions that way, and I'd avoid it to not expose any implementation details, but just describe the [algorithm] parameter in the usual way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the question here (even more than for the above overload) is: Why not use the Hash() constructor directly. For both cases below, it's clear from the property name that the hash is always a SHA256, so I'd simply call the Hash() constructor instead of introducing this overload.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #8905, we maybe could even drop the above original overload and instead verify in an init block that value.length == algorithm.size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the question here (even more than for the above overload) is: Why not use the Hash() constructor directly. For both cases below, it's clear from the property name that the hash is always a SHA256, so I'd simply call the Hash() constructor instead of introducing this overload.

I guess there has to be a reason for these sanity checks, which is why I went for this overload.
This way it remains a non-functional change as it keeps that sanity check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there has to be a reason for these sanity checks

I don't think so. Maybe it was just over-cautiousness, or simply an oversight. But I really do not see an issue with using the Hash() constructor, esp. if it's init block would introduce basically the same sanity check on the hash string value size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll close this PR then.

*/
fun create(value: String, algorithm: HashAlgorithm): Hash = create(value, algorithm.name)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/conan/src/main/kotlin/Conan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class Conan(
(urlNode.takeIf { it.isTextual } ?: urlNode.first()).textValueOrEmpty()
}

val hash = Hash.create(artifactEntry["sha256"].textValueOrEmpty(), HashAlgorithm.SHA256.name)
val hash = Hash.create(artifactEntry["sha256"].textValueOrEmpty(), HashAlgorithm.SHA256)

RemoteArtifact(url, hash)
}.getOrElse {
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/pub/src/main/kotlin/Pub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ class Pub(

RemoteArtifact(
url = "$hostUrl/packages/$rawName/versions/$version.tar.gz",
hash = Hash.create(sha256, HashAlgorithm.SHA256.name)
hash = Hash.create(sha256, HashAlgorithm.SHA256)
)
} else {
RemoteArtifact.EMPTY
Expand Down
Loading