Skip to content

Commit 2b13ad0

Browse files
committed
Vendor uuid5
1 parent ace920e commit 2b13ad0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44

55
[deps]
66
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
7+
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
78
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
89

910
[compat]

src/ProgressLogging.jl

+25-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,33 @@ module ProgressLogging
66
export @progress, @progressid, @withprogress, @logprogress
77

88
using Base.Meta: isexpr
9-
using UUIDs: UUID, uuid4, uuid5
9+
using UUIDs: UUID, uuid4
1010
using Logging: Logging, @logmsg, LogLevel
1111

12+
if VERSION >= v"1.1-"
13+
using UUIDs: uuid5
14+
else
15+
import SHA
16+
function uuid5(ns::UUID, name::String)
17+
nsbytes = zeros(UInt8, 16)
18+
nsv = ns.value
19+
for idx in Base.OneTo(16)
20+
nsbytes[idx] = nsv >> 120
21+
nsv = nsv << 8
22+
end
23+
hash_result = SHA.sha1(append!(nsbytes, convert(Vector{UInt8}, codeunits(unescape_string(name)))))
24+
# set version number to 5
25+
hash_result[7] = (hash_result[7] & 0x0F) | (0x50)
26+
hash_result[9] = (hash_result[9] & 0x3F) | (0x80)
27+
v = zero(UInt128)
28+
#use only the first 16 bytes of the SHA1 hash
29+
for idx in Base.OneTo(16)
30+
v = (v << 0x08) | hash_result[idx]
31+
end
32+
return UUID(v)
33+
end
34+
end
35+
1236
const ProgressLevel = LogLevel(-1)
1337

1438
"""

0 commit comments

Comments
 (0)