config.go 950 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package hysteria2
  2. import (
  3. "crypto/sha256"
  4. "encoding/hex"
  5. "fmt"
  6. "github.com/v2fly/v2ray-core/v5/common"
  7. "github.com/v2fly/v2ray-core/v5/common/protocol"
  8. )
  9. // MemoryAccount is an account type converted from Account.
  10. type MemoryAccount struct {
  11. Password string
  12. Key []byte
  13. }
  14. // AsAccount implements protocol.AsAccount.
  15. func (a *Account) AsAccount() (protocol.Account, error) {
  16. return &MemoryAccount{}, nil
  17. }
  18. // Equals implements protocol.Account.Equals().
  19. func (a *MemoryAccount) Equals(another protocol.Account) bool {
  20. if account, ok := another.(*MemoryAccount); ok {
  21. return a.Password == account.Password
  22. }
  23. return false
  24. }
  25. func hexSha224(password string) []byte {
  26. buf := make([]byte, 56)
  27. hash := sha256.New224()
  28. common.Must2(hash.Write([]byte(password)))
  29. hex.Encode(buf, hash.Sum(nil))
  30. return buf
  31. }
  32. func hexString(data []byte) string {
  33. str := ""
  34. for _, v := range data {
  35. str += fmt.Sprintf("%02x", v)
  36. }
  37. return str
  38. }