| 1761 | } |
| 1762 | |
| 1763 | const decodeAuthentication = (reader: Reader): BackendMessage => { |
| 1764 | const method = reader.int32() |
| 1765 | switch (method) { |
| 1766 | case 0: |
| 1767 | return { _tag: "AuthenticationOk" } |
| 1768 | case 3: |
| 1769 | return { _tag: "AuthenticationCleartextPassword" } |
| 1770 | case 5: |
| 1771 | return { _tag: "AuthenticationMD5Password", salt: reader.raw(4) } |
| 1772 | case 10: { |
| 1773 | const mechanisms: Array<string> = [] |
| 1774 | for (;;) { |
| 1775 | const mechanism = reader.cString() |
| 1776 | if (mechanism === "") break |
| 1777 | mechanisms.push(mechanism) |
| 1778 | } |
| 1779 | return { _tag: "AuthenticationSASL", mechanisms } |
| 1780 | } |
| 1781 | case 11: |
| 1782 | return { _tag: "AuthenticationSASLContinue", data: reader.rest() } |
| 1783 | case 12: |
| 1784 | return { _tag: "AuthenticationSASLFinal", data: reader.rest() } |
| 1785 | default: |
| 1786 | return { _tag: "AuthenticationUnsupported", method, payload: reader.rest() } |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | const decodeErrorFields = (reader: Reader): ErrorFields => { |
| 1791 | const fields: Record<string, string> = {} |