mirror of
https://github.com/danbulant/jose
synced 2026-05-24 12:35:36 +00:00
refactor: sign.js PROCESS_RECIPIENT
This commit is contained in:
parent
ce6836af88
commit
e0a2d57926
1 changed files with 12 additions and 17 deletions
|
|
@ -87,9 +87,7 @@ class Sign {
|
||||||
recipient.header = unprotectedHeader
|
recipient.header = unprotectedHeader
|
||||||
recipient.protected = Object.keys(joseHeader.protected).length ? base64url.JSON.encode(joseHeader.protected) : ''
|
recipient.protected = Object.keys(joseHeader.protected).length ? base64url.JSON.encode(joseHeader.protected) : ''
|
||||||
|
|
||||||
let toBeSigned
|
if (first && joseHeader.protected.crit && joseHeader.protected.crit.includes('b64') && joseHeader.protected.b64 === false) {
|
||||||
if (joseHeader.protected.crit && joseHeader.protected.crit.includes('b64')) {
|
|
||||||
if (first && !joseHeader.protected.b64) {
|
|
||||||
if (this._binary) {
|
if (this._binary) {
|
||||||
this._payload = base64url.decodeToBuffer(this._payload)
|
this._payload = base64url.decodeToBuffer(this._payload)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -97,16 +95,13 @@ class Sign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toBeSigned = Buffer.concat([
|
const data = Buffer.concat([
|
||||||
Buffer.from(recipient.protected || ''),
|
Buffer.from(recipient.protected || ''),
|
||||||
Buffer.from('.'),
|
Buffer.from('.'),
|
||||||
Buffer.isBuffer(this._payload) ? this._payload : Buffer.from(this._payload)
|
Buffer.from(this._payload)
|
||||||
])
|
])
|
||||||
} else {
|
|
||||||
toBeSigned = `${recipient.protected || ''}.${this._payload}`
|
|
||||||
}
|
|
||||||
|
|
||||||
recipient.signature = base64url.encodeBuffer(sign(alg, key, toBeSigned))
|
recipient.signature = base64url.encodeBuffer(sign(alg, key, data))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue