github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/lorry/engines/kafka/scram_client.go (about) 1 /* 2 Copyright 2021 The Dapr Authors 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 http://www.apache.org/licenses/LICENSE-2.0 7 Unless required by applicable law or agreed to in writing, software 8 distributed under the License is distributed on an "AS IS" BASIS, 9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 See the License for the specific language governing permissions and 11 limitations under the License. 12 */ 13 14 package kafka 15 16 import ( 17 "crypto/sha256" 18 "crypto/sha512" 19 20 "github.com/xdg-go/scram" 21 ) 22 23 var ( 24 SHA256 scram.HashGeneratorFcn = sha256.New 25 SHA512 scram.HashGeneratorFcn = sha512.New 26 ) 27 28 type XDGSCRAMClient struct { 29 *scram.Client 30 *scram.ClientConversation 31 scram.HashGeneratorFcn 32 } 33 34 func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) { 35 x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID) 36 if err != nil { 37 return err 38 } 39 x.ClientConversation = x.Client.NewConversation() 40 return nil 41 } 42 43 func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) { 44 response, err = x.ClientConversation.Step(challenge) 45 return 46 } 47 48 func (x *XDGSCRAMClient) Done() bool { 49 return x.ClientConversation.Done() 50 }