(data)
| 190 | } |
| 191 | |
| 192 | function parseServerFirstMessage(data) { |
| 193 | const attrPairs = parseAttributePairs(data) |
| 194 | |
| 195 | const nonce = attrPairs.get('r') |
| 196 | if (!nonce) { |
| 197 | throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing') |
| 198 | } else if (!isPrintableChars(nonce)) { |
| 199 | throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce must only contain printable characters') |
| 200 | } |
| 201 | const salt = attrPairs.get('s') |
| 202 | if (!salt) { |
| 203 | throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing') |
| 204 | } else if (!isBase64(salt)) { |
| 205 | throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: salt must be base64') |
| 206 | } |
| 207 | const iterationText = attrPairs.get('i') |
| 208 | if (!iterationText) { |
| 209 | throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing') |
| 210 | } else if (!/^[1-9][0-9]*$/.test(iterationText)) { |
| 211 | throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: invalid iteration count') |
| 212 | } |
| 213 | const iteration = parseInt(iterationText, 10) |
| 214 | |
| 215 | return { |
| 216 | nonce, |
| 217 | salt, |
| 218 | iteration, |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | function parseServerFinalMessage(serverData) { |
| 223 | const attrPairs = parseAttributePairs(serverData) |
no test coverage detected