...

Source file src/github.com/jackc/pgx/v5/pgproto3/authentication_cleartext_password.go

Documentation: github.com/jackc/pgx/v5/pgproto3

     1  package pgproto3
     2  
     3  import (
     4  	"encoding/binary"
     5  	"encoding/json"
     6  	"errors"
     7  
     8  	"github.com/jackc/pgx/v5/internal/pgio"
     9  )
    10  
    11  // AuthenticationCleartextPassword is a message sent from the backend indicating that a clear-text password is required.
    12  type AuthenticationCleartextPassword struct {
    13  }
    14  
    15  // Backend identifies this message as sendable by the PostgreSQL backend.
    16  func (*AuthenticationCleartextPassword) Backend() {}
    17  
    18  // Backend identifies this message as an authentication response.
    19  func (*AuthenticationCleartextPassword) AuthenticationResponse() {}
    20  
    21  // Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
    22  // type identifier and 4 byte message length.
    23  func (dst *AuthenticationCleartextPassword) Decode(src []byte) error {
    24  	if len(src) != 4 {
    25  		return errors.New("bad authentication message size")
    26  	}
    27  
    28  	authType := binary.BigEndian.Uint32(src)
    29  
    30  	if authType != AuthTypeCleartextPassword {
    31  		return errors.New("bad auth type")
    32  	}
    33  
    34  	return nil
    35  }
    36  
    37  // Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
    38  func (src *AuthenticationCleartextPassword) Encode(dst []byte) ([]byte, error) {
    39  	dst, sp := beginMessage(dst, 'R')
    40  	dst = pgio.AppendUint32(dst, AuthTypeCleartextPassword)
    41  	return finishMessage(dst, sp)
    42  }
    43  
    44  // MarshalJSON implements encoding/json.Marshaler.
    45  func (src AuthenticationCleartextPassword) MarshalJSON() ([]byte, error) {
    46  	return json.Marshal(struct {
    47  		Type string
    48  	}{
    49  		Type: "AuthenticationCleartextPassword",
    50  	})
    51  }
    52  

View as plain text