MCPcopy Index your code
hub / github.com/brianc/node-postgres / parseServerFirstMessage

Function parseServerFirstMessage

packages/pg/lib/crypto/sasl.js:192–220  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

190}
191
192function 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
222function parseServerFinalMessage(serverData) {
223 const attrPairs = parseAttributePairs(serverData)

Callers 1

continueSessionFunction · 0.85

Calls 4

parseAttributePairsFunction · 0.85
isPrintableCharsFunction · 0.85
isBase64Function · 0.85
testMethod · 0.80

Tested by

no test coverage detected