fix: sha256 hash calculation for oid
This commit is contained in:
parent
0945e2659b
commit
7c79ad6857
2 changed files with 5 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
||||||
|
// This is Node-only code due to use of crypto.
|
||||||
|
import crypto from 'crypto';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { SPEC_URL, toHex } from './util';
|
import { SPEC_URL } from './util';
|
||||||
|
|
||||||
|
|
||||||
export interface PointerInfo {
|
export interface PointerInfo {
|
||||||
|
@ -74,6 +76,6 @@ export function formatPointerInfo(info: PointerInfo): Buffer {
|
||||||
|
|
||||||
export async function buildPointerInfo(content: Buffer): Promise<PointerInfo> {
|
export async function buildPointerInfo(content: Buffer): Promise<PointerInfo> {
|
||||||
const size = Buffer.byteLength(content);
|
const size = Buffer.byteLength(content);
|
||||||
const hash = await crypto.subtle.digest('SHA-1', content);
|
const hash = crypto.createHash('sha256').update(content).digest('hex');
|
||||||
return { oid: toHex(hash), size };
|
return { oid: hash, size };
|
||||||
}
|
}
|
||||||
|
|
11
src/util.ts
11
src/util.ts
|
@ -77,14 +77,3 @@ export async function bodyToBuffer(body: Uint8Array[]): Promise<Buffer> {
|
||||||
}
|
}
|
||||||
return Buffer.from(result.buffer);
|
return Buffer.from(result.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Borrowed from Isomorphic Git core, it is not importable.
|
|
||||||
export function toHex(buffer: ArrayBuffer): string {
|
|
||||||
let hex = ''
|
|
||||||
for (const byte of new Uint8Array(buffer)) {
|
|
||||||
if (byte < 16) hex += '0'
|
|
||||||
hex += byte.toString(16)
|
|
||||||
}
|
|
||||||
return hex
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue