From ff49ac8f24c7699600e43bdcc2090d50fca171e8 Mon Sep 17 00:00:00 2001 From: LittleChest Date: Wed, 8 Apr 2026 22:23:07 +0800 Subject: [PATCH] Fix SSHFP --- buffer.js | 11 +++++++++++ index.js | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/buffer.js b/buffer.js index ca9382d..616abd6 100644 --- a/buffer.js +++ b/buffer.js @@ -66,6 +66,16 @@ function hexToBuffer (hexStr) { return bytes } +// Convert Uint8Array to hex string +function bufferToHex (buf) { + let hex = '' + for (let i = 0; i < buf.length; i++) { + const byte = buf[i] + hex += (byte < 16 ? '0' : '') + byte.toString(16) + } + return hex.toUpperCase() +} + // Convert Uint8Array to string function bufferToString (buf, encoding, start, end) { encoding = encoding || 'utf-8' @@ -179,6 +189,7 @@ module.exports = { stringToBuffer, base64ToBuffer, hexToBuffer, + bufferToHex, bufferToString, writeString, byteLength, diff --git a/index.js b/index.js index 1a3f3ae..0f4d537 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,8 @@ const { readUInt32BE, writeUInt32BE, bufferCopy, - bufferConcat + bufferConcat, + bufferToHex } = require('./buffer') const types = require('./types') @@ -1368,7 +1369,7 @@ rsshfp.decode = function decode (buf, offset) { offset += 1 const fingerprintLength = rsshfp.getFingerprintLengthForHashType(record.hash) - record.fingerprint = buf.slice(offset, offset + fingerprintLength).toString('hex').toUpperCase() + record.fingerprint = bufferToHex(buf.slice(offset, offset + fingerprintLength)) offset += fingerprintLength rsshfp.decode.bytes = offset - oldOffset return record