Fix SSHFP

This commit is contained in:
LittleChest 2026-04-08 22:23:07 +08:00
parent a16cd9dd21
commit ff49ac8f24
2 changed files with 14 additions and 2 deletions

View File

@ -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,

View File

@ -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