diff --git a/lib/modules/datasource/crate/index.ts b/lib/modules/datasource/crate/index.ts index 28535884774f86468e1ba8e5332fe2b4970239df..7fdcf5878187ee573a7fb1c9c3a21694a1dac620 100644 --- a/lib/modules/datasource/crate/index.ts +++ b/lib/modules/datasource/crate/index.ts @@ -1,4 +1,3 @@ -import hasha from 'hasha'; import Git from 'simple-git'; import upath from 'upath'; import { GlobalConfig } from '../../../config/global'; @@ -7,6 +6,7 @@ import * as memCache from '../../../util/cache/memory'; import { cache } from '../../../util/cache/package/decorator'; import { privateCacheDir, readCacheFile } from '../../../util/fs'; import { simpleGitConfig } from '../../../util/git/config'; +import { toSha256 } from '../../../util/hash'; import { newlineRegex, regEx } from '../../../util/regex'; import { joinUrlParts, parseUrl } from '../../../util/url'; import * as cargoVersioning from '../../versioning/cargo'; @@ -214,9 +214,7 @@ export class CrateDatasource extends Datasource { private static cacheDirFromUrl(url: URL): string { const proto = url.protocol.replace(regEx(/:$/), ''); const host = url.hostname; - const hash = hasha(url.pathname, { - algorithm: 'sha256', - }).substring(0, 7); + const hash = toSha256(url.pathname).substring(0, 7); return `crate-registry-${proto}-${host}-${hash}`; } diff --git a/lib/modules/datasource/docker/common.ts b/lib/modules/datasource/docker/common.ts index 5dc02fb40606002d6feebe7f062f70b9850d3f35..57b359f08ccffb9ea864beca553cdc10f46afddd 100644 --- a/lib/modules/datasource/docker/common.ts +++ b/lib/modules/datasource/docker/common.ts @@ -1,6 +1,5 @@ import is from '@sindresorhus/is'; import { parse } from 'auth-header'; -import hasha from 'hasha'; import { HOST_DISABLED, PAGE_NOT_FOUND_ERROR, @@ -8,6 +7,7 @@ import { import { logger } from '../../../logger'; import type { HostRule } from '../../../types'; import { ExternalHostError } from '../../../types/errors/external-host-error'; +import { toSha256 } from '../../../util/hash'; import * as hostRules from '../../../util/host-rules'; import type { Http } from '../../../util/http'; import type { @@ -285,7 +285,7 @@ export function getRegistryRepository( export function extractDigestFromResponseBody( manifestResponse: HttpResponse ): string { - return 'sha256:' + hasha(manifestResponse.body, { algorithm: 'sha256' }); + return 'sha256:' + toSha256(manifestResponse.body); } export function findLatestStable(tags: string[]): string | null { diff --git a/lib/modules/datasource/github-release-attachments/digest.spec.ts b/lib/modules/datasource/github-release-attachments/digest.spec.ts index 19264bc096da19d1189cad7d9cf5f6f9a5fc4c69..40fedd2b1461c92480f62f2a4d5dff30d7d183c0 100644 --- a/lib/modules/datasource/github-release-attachments/digest.spec.ts +++ b/lib/modules/datasource/github-release-attachments/digest.spec.ts @@ -1,6 +1,6 @@ -import hasha from 'hasha'; import * as httpMock from '../../../../test/http-mock'; import type { GithubDigestFile } from '../../../util/github/types'; +import { toSha256 } from '../../../util/hash'; import { GitHubReleaseAttachmentMocker } from './test'; import { GithubReleaseAttachmentsDatasource } from '.'; @@ -55,7 +55,7 @@ describe('modules/datasource/github-release-attachments/digest', () => { 'asset.zip': content, 'smallest.zip': '1'.repeat(8 * 1024), }); - const contentDigest = await hasha.async(content, { algorithm: 'sha256' }); + const contentDigest = toSha256(content); const digestAsset = await githubReleaseAttachments.findDigestAsset( release, @@ -147,9 +147,7 @@ describe('modules/datasource/github-release-attachments/digest', () => { const release = releaseMock.withAssets('v1.0.1', { 'asset.zip': updatedContent, }); - const contentDigest = await hasha.async(updatedContent, { - algorithm: 'sha256', - }); + const contentDigest = toSha256(updatedContent); const digest = await githubReleaseAttachments.mapDigestAssetToRelease( digestAsset, diff --git a/lib/modules/datasource/rubygems/metadata-cache.ts b/lib/modules/datasource/rubygems/metadata-cache.ts index 225522b9b0d08e3e42f2a49b8d71e255cabdb63c..9bae7437cf7fad75a9b8298aebf7aeb9a03aed62 100644 --- a/lib/modules/datasource/rubygems/metadata-cache.ts +++ b/lib/modules/datasource/rubygems/metadata-cache.ts @@ -1,5 +1,5 @@ -import hasha from 'hasha'; import * as packageCache from '../../../util/cache/package'; +import { toSha256 } from '../../../util/hash'; import type { Http } from '../../../util/http'; import { AsyncResult, Result } from '../../../util/result'; import { parseUrl } from '../../../util/url'; @@ -21,7 +21,7 @@ export class MetadataCache { ): Promise<ReleaseResult> { const cacheNs = `datasource-rubygems`; const cacheKey = `metadata-cache:${registryUrl}:${packageName}`; - const hash = hasha(versions, { algorithm: 'sha256' }); + const hash = toSha256(versions.join('')); const loadCache = (): AsyncResult<ReleaseResult, unknown> => Result.wrapNullable( diff --git a/lib/modules/platform/pr-body.spec.ts b/lib/modules/platform/pr-body.spec.ts index 89967f8a31d96fb3e48f31f362eebdfc28a88838..f25cc491c908ab0496528f644c754f60c4f11a37 100644 --- a/lib/modules/platform/pr-body.spec.ts +++ b/lib/modules/platform/pr-body.spec.ts @@ -1,4 +1,4 @@ -import hasha from 'hasha'; +import { toSha256 } from '../../util/hash'; import { getPrBodyStruct, hashBody } from './pr-body'; describe('modules/platform/pr-body', () => { @@ -83,7 +83,7 @@ describe('modules/platform/pr-body', () => { it('returns raw config hash', () => { const config = '{}'; - const rawConfigHash = hasha(config, { algorithm: 'sha256' }); + const rawConfigHash = toSha256(config); const input = `<!--renovate-config-hash:${rawConfigHash}-->`; const hash = hashBody(input); expect(getPrBodyStruct(input)).toEqual({ diff --git a/lib/modules/platform/pr-body.ts b/lib/modules/platform/pr-body.ts index 88f28826bcd73a17b4e58918971f94cf744ee755..97dc74b0282c440a5d9fd0e971b200d0e94064be 100644 --- a/lib/modules/platform/pr-body.ts +++ b/lib/modules/platform/pr-body.ts @@ -1,7 +1,7 @@ import is from '@sindresorhus/is'; -import hasha from 'hasha'; import { logger } from '../../logger'; import { stripEmojis } from '../../util/emoji'; +import { toSha256 } from '../../util/hash'; import { regEx } from '../../util/regex'; import { fromBase64 } from '../../util/string'; import type { PrBodyStruct } from './types'; @@ -31,7 +31,7 @@ export function hashBody(body: string | undefined): string { } result = stripEmojis(result); result = noWhitespaceOrHeadings(result); - result = hasha(result, { algorithm: 'sha256' }); + result = toSha256(result); return result; } diff --git a/lib/util/hasha.ts b/lib/util/hasha.ts deleted file mode 100644 index a9d9f22b3e3c45fb572c3f6b842df923d894723f..0000000000000000000000000000000000000000 --- a/lib/util/hasha.ts +++ /dev/null @@ -1,5 +0,0 @@ -import hasha from 'hasha'; - -export function toSha256(input: string): string { - return hasha(input, { algorithm: 'sha256' }); -} diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index 08b58ea760b2012a4f4de3c44e0982daf5af06b6..f18aa839b20d31b39cc75cb402558c4bc6347bf1 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -9,7 +9,7 @@ import { hashBody } from '../../../../modules/platform/pr-body'; import { scm } from '../../../../modules/platform/scm'; import { emojify } from '../../../../util/emoji'; import { getFile } from '../../../../util/git'; -import { toSha256 } from '../../../../util/hasha'; +import { toSha256 } from '../../../../util/hash'; import * as template from '../../../../util/template'; import type { BranchConfig } from '../../../types'; import {