github.com/datastax/go-cassandra-native-protocol@v0.0.0-20220706104457-5e8aad05cf90/message/auth_challenge.go (about) 1 // Copyright 2020 DataStax 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package message 16 17 import ( 18 "errors" 19 "fmt" 20 "io" 21 22 "github.com/datastax/go-cassandra-native-protocol/primitive" 23 ) 24 25 // AuthChallenge is a response sent in reply to an AuthResponse request, when the server requires additional 26 // authentication data. It must be followed by an AuthResponse request message. 27 // +k8s:deepcopy-gen=true 28 // +k8s:deepcopy-gen:interfaces=github.com/datastax/go-cassandra-native-protocol/message.Message 29 type AuthChallenge struct { 30 Token []byte 31 } 32 33 func (m *AuthChallenge) IsResponse() bool { 34 return true 35 } 36 37 func (m *AuthChallenge) GetOpCode() primitive.OpCode { 38 return primitive.OpCodeAuthChallenge 39 } 40 41 func (m *AuthChallenge) String() string { 42 return "AUTH_CHALLENGE" 43 } 44 45 type authChallengeCodec struct{} 46 47 func (c *authChallengeCodec) Encode(msg Message, dest io.Writer, _ primitive.ProtocolVersion) error { 48 authChallenge, ok := msg.(*AuthChallenge) 49 if !ok { 50 return errors.New(fmt.Sprintf("expected *message.AuthChallenge, got %T", msg)) 51 } 52 return primitive.WriteBytes(authChallenge.Token, dest) 53 } 54 55 func (c *authChallengeCodec) EncodedLength(msg Message, _ primitive.ProtocolVersion) (int, error) { 56 authChallenge, ok := msg.(*AuthChallenge) 57 if !ok { 58 return -1, errors.New(fmt.Sprintf("expected *message.AuthChallenge, got %T", msg)) 59 } 60 return primitive.LengthOfBytes(authChallenge.Token), nil 61 } 62 63 func (c *authChallengeCodec) Decode(source io.Reader, _ primitive.ProtocolVersion) (Message, error) { 64 if token, err := primitive.ReadBytes(source); err != nil { 65 return nil, err 66 } else { 67 return &AuthChallenge{Token: token}, nil 68 } 69 } 70 71 func (c *authChallengeCodec) GetOpCode() primitive.OpCode { 72 return primitive.OpCodeAuthChallenge 73 }