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

Function parseAuthenticationResponse

packages/pg-protocol/src/parser.ts:331–379  ·  view source on GitHub ↗
(reader: BufferReader, length: number)

Source from the content-addressed store, hash-verified

329}
330
331const parseAuthenticationResponse = (reader: BufferReader, length: number) => {
332 const code = reader.int32()
333 // TODO(bmc): maybe better types here
334 const message: BackendMessage & any = {
335 name: 'authenticationOk',
336 length,
337 }
338
339 switch (code) {
340 case 0: // AuthenticationOk
341 break
342 case 3: // AuthenticationCleartextPassword
343 if (message.length === 8) {
344 message.name = 'authenticationCleartextPassword'
345 }
346 break
347 case 5: // AuthenticationMD5Password
348 if (message.length === 12) {
349 message.name = 'authenticationMD5Password'
350 const salt = reader.bytes(4)
351 return new AuthenticationMD5Password(LATEINIT_LENGTH, salt)
352 }
353 break
354 case 10: // AuthenticationSASL
355 {
356 message.name = 'authenticationSASL'
357 message.mechanisms = []
358 let mechanism: string
359 do {
360 mechanism = reader.cstring()
361 if (mechanism) {
362 message.mechanisms.push(mechanism)
363 }
364 } while (mechanism)
365 }
366 break
367 case 11: // AuthenticationSASLContinue
368 message.name = 'authenticationSASLContinue'
369 message.data = reader.string(length - 8)
370 break
371 case 12: // AuthenticationSASLFinal
372 message.name = 'authenticationSASLFinal'
373 message.data = reader.string(length - 8)
374 break
375 default:
376 throw new Error('Unknown authenticationOk message type ' + code)
377 }
378 return message
379}
380
381const parseErrorMessage = (reader: BufferReader, name: MessageName) => {
382 const fields: Record<string, string> = {}

Callers 1

handlePacketMethod · 0.85

Calls 4

int32Method · 0.80
bytesMethod · 0.80
cstringMethod · 0.80
stringMethod · 0.80

Tested by

no test coverage detected