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