| 368 | } |
| 369 | |
| 370 | #parseAuthenticationResponse( |
| 371 | offset: number, |
| 372 | length: number, |
| 373 | bytes: ArrayBuffer, |
| 374 | ): AuthenticationMessage { |
| 375 | this.#reader.setBuffer(offset, bytes) |
| 376 | const code = this.#reader.int32() |
| 377 | switch (code) { |
| 378 | case 0: |
| 379 | return new AuthenticationOk(length) |
| 380 | case 3: |
| 381 | return new AuthenticationCleartextPassword(length) |
| 382 | |
| 383 | case 5: |
| 384 | return new AuthenticationMD5Password(length, this.#reader.bytes(4)) |
| 385 | |
| 386 | case 10: { |
| 387 | const mechanisms: string[] = [] |
| 388 | while (true) { |
| 389 | const mechanism = this.#reader.cstring() |
| 390 | if (mechanism.length === 0) { |
| 391 | return new AuthenticationSASL(length, mechanisms) |
| 392 | } |
| 393 | mechanisms.push(mechanism) |
| 394 | } |
| 395 | } |
| 396 | case 11: |
| 397 | return new AuthenticationSASLContinue( |
| 398 | length, |
| 399 | this.#reader.string(length - 8), |
| 400 | ) |
| 401 | |
| 402 | case 12: |
| 403 | return new AuthenticationSASLFinal( |
| 404 | length, |
| 405 | this.#reader.string(length - 8), |
| 406 | ) |
| 407 | |
| 408 | default: |
| 409 | throw new Error('Unknown authenticationOk message type ' + code) |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | #parseErrorMessage( |
| 414 | offset: number, |