Skip to content

Add a Base.SHA256 struct into Base#61555

Draft
DilumAluthge wants to merge 1 commit intomasterfrom
dpa/sha256-struct-in-base
Draft

Add a Base.SHA256 struct into Base#61555
DilumAluthge wants to merge 1 commit intomasterfrom
dpa/sha256-struct-in-base

Conversation

@DilumAluthge
Copy link
Copy Markdown
Member

@DilumAluthge DilumAluthge commented Apr 10, 2026

We're going to start recording git-tree-sha256 in the General registry, which means that we should eventually also start tracking git-tree-sha256 in manifests. And so eventually we'll want to use it in code loading, which will require it to be in Base.

I'd like to use this in the following places:

  1. Code loading (Base)
  2. Pkg.Artifacts (stdlib)
  3. Various packages (RegistryTools, Registrator, LocalRegistry)

@DilumAluthge DilumAluthge force-pushed the dpa/sha256-struct-in-base branch from 15c1af8 to 1f448d9 Compare April 10, 2026 22:32
for (name, namestr, numbytes) in [(:SHA1, "SHA1", 20), (:SHA256, "SHA256", 32)]
@eval Base begin
struct $name
bytes::NTuple{20, UInt8}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
bytes::NTuple{20, UInt8}
bytes::NTuple{$(numbytes), UInt8}

end
function $name(bytes::Vector{UInt8})
length(bytes) == $numbytes ||
throw(ArgumentError("wrong number of bytes for " * string($namestr) * ": $(length(bytes))"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
throw(ArgumentError("wrong number of bytes for " * string($namestr) * ": $(length(bytes))"))
throw(ArgumentError("wrong number of bytes for " * string($namestr) * ": Expected $(numbytes) bytes, got $(length(bytes))"))

show(io::IO, hash::SHA1) = print(io, "SHA1(\"", hash, "\")")
string(hash::$name) = bytes2hex(hash.bytes)
print(io::IO, hash::$name) = bytes2hex(io, hash.bytes)
show(io::IO, hash::$name) = print(io, string($namestr) * "(\"", hash, "\")")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
show(io::IO, hash::$name) = print(io, string($namestr) * "(\"", hash, "\")")
show(io::IO, hash::$name) = print(io, namestr * "(\"", hash, "\")")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants