(reader: BufferReader, length: number)
| 329 | } |
| 330 | |
| 331 | const 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 | |
| 381 | const parseErrorMessage = (reader: BufferReader, name: MessageName) => { |
| 382 | const fields: Record<string, string> = {} |
no test coverage detected