mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Fixes web build (sha1 issues)
This commit is contained in:
@@ -8,13 +8,15 @@
|
||||
const textDecoder = new TextDecoder();
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
declare const WEBWORKER: boolean;
|
||||
|
||||
export async function sha1(s: string | Uint8Array): Promise<string> {
|
||||
if (process?.release.name === 'node') {
|
||||
return (await import('crypto')).createHash('sha1').update(s).digest('base64');
|
||||
if (WEBWORKER) {
|
||||
const hash = await globalThis.crypto.subtle.digest({ name: 'sha-1' }, typeof s === 'string' ? textEncoder.encode(s) : s);
|
||||
// Use encodeURIComponent to avoid issues with btoa and Latin-1 characters
|
||||
return globalThis.btoa(encodeURIComponent(textDecoder.decode(hash)));
|
||||
}
|
||||
else {
|
||||
const hash = await crypto.subtle.digest({ name: 'sha-1' }, typeof s === 'string' ? textEncoder.encode(s) : s);
|
||||
// Use encodeURIComponent to avoid issues with btoa and Latin-1 characters
|
||||
return btoa(encodeURIComponent(textDecoder.decode(hash)));
|
||||
return (await import('crypto')).createHash('sha1').update(s).digest('base64');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user