Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
1b932631
Unverified
Commit
1b932631
authored
1 year ago
by
Adam Setch
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: add hash util (#23524)
parent
68e871e8
No related branches found
Branches containing commit
Tags
38.2.1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/util/hash.spec.ts
+12
-0
12 additions, 0 deletions
lib/util/hash.spec.ts
lib/util/hash.ts
+17
-0
17 additions, 0 deletions
lib/util/hash.ts
with
29 additions
and
0 deletions
lib/util/hash.spec.ts
0 → 100644
+
12
−
0
View file @
1b932631
import
{
hash
,
toSha256
}
from
'
./hash
'
;
describe
(
'
util/hash
'
,
()
=>
{
test
(
'
should hash data with sha256
'
,
()
=>
{
expect
(
hash
(
'
https://example.com/test.txt
'
,
'
sha256
'
)).
toBe
(
'
d1dc63218c42abba594fff6450457dc8c4bfdd7c22acf835a50ca0e5d2693020
'
);
expect
(
toSha256
(
'
https://example.com/test.txt
'
)).
toBe
(
'
d1dc63218c42abba594fff6450457dc8c4bfdd7c22acf835a50ca0e5d2693020
'
);
});
});
This diff is collapsed.
Click to expand it.
lib/util/hash.ts
0 → 100644
+
17
−
0
View file @
1b932631
import
crypto
from
'
node:crypto
'
;
import
type
{
LiteralUnion
}
from
'
type-fest
'
;
export
type
AlgorithmName
=
LiteralUnion
<
'
sha1
'
|
'
sha224
'
|
'
sha256
'
|
'
sha384
'
|
'
sha512
'
,
string
>
;
export
function
hash
(
data
:
string
|
Buffer
,
algorithm
:
AlgorithmName
):
string
{
const
hash
=
crypto
.
createHash
(
algorithm
);
hash
.
update
(
data
);
return
hash
.
digest
(
'
hex
'
);
}
export
function
toSha256
(
input
:
string
):
string
{
return
hash
(
input
,
'
sha256
'
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment