lib/request: allow string profile.salt

This commit is contained in:
Jannis R 2021-01-14 20:30:48 +01:00
parent 3df3a7b73d
commit 4ee062a19d
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -50,13 +50,16 @@ const request = (ctx, userAgent, reqData) => {
}) })
if (profile.addChecksum || profile.addMicMac) { if (profile.addChecksum || profile.addMicMac) {
if (!Buffer.isBuffer(profile.salt)) { if (!Buffer.isBuffer(profile.salt) && 'string' !== typeof profile.salt) {
throw new TypeError('profile.salt must be a Buffer.') throw new TypeError('profile.salt must be a Buffer or a string.')
} }
// Buffer.from(buf, 'hex') just returns buf
const salt = Buffer.from(profile.salt, 'hex')
if (profile.addChecksum) { if (profile.addChecksum) {
const checksum = md5(Buffer.concat([ const checksum = md5(Buffer.concat([
Buffer.from(req.body, 'utf8'), Buffer.from(req.body, 'utf8'),
profile.salt salt,
])) ]))
req.query.checksum = checksum.toString('hex') req.query.checksum = checksum.toString('hex')
} }
@ -65,7 +68,7 @@ const request = (ctx, userAgent, reqData) => {
req.query.mic = mic.toString('hex') req.query.mic = mic.toString('hex')
const micAsHex = Buffer.from(mic.toString('hex'), 'utf8') const micAsHex = Buffer.from(mic.toString('hex'), 'utf8')
const mac = md5(Buffer.concat([micAsHex, profile.salt])) const mac = md5(Buffer.concat([micAsHex, salt]))
req.query.mac = mac.toString('hex') req.query.mac = mac.toString('hex')
} }
} }