scram_client.go 822 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "crypto/sha256"
  4. "crypto/sha512"
  5. "hash"
  6. "github.com/xdg/scram"
  7. )
  8. var SHA256 scram.HashGeneratorFcn = func() hash.Hash { return sha256.New() }
  9. var SHA512 scram.HashGeneratorFcn = func() hash.Hash { return sha512.New() }
  10. type XDGSCRAMClient struct {
  11. *scram.Client
  12. *scram.ClientConversation
  13. scram.HashGeneratorFcn
  14. }
  15. func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) {
  16. x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID)
  17. if err != nil {
  18. return err
  19. }
  20. x.ClientConversation = x.Client.NewConversation()
  21. return nil
  22. }
  23. func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) {
  24. response, err = x.ClientConversation.Step(challenge)
  25. return
  26. }
  27. func (x *XDGSCRAMClient) Done() bool {
  28. return x.ClientConversation.Done()
  29. }