mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
lib/request: allow string profile.salt
This commit is contained in:
parent
3df3a7b73d
commit
4ee062a19d
1 changed files with 7 additions and 4 deletions
|
@ -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')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue