(params map[string][]string, token string)
| 98 | } |
| 99 | |
| 100 | func checkTelegramAuthorization(params map[string][]string, token string) bool { |
| 101 | strs := []string{} |
| 102 | var hash = "" |
| 103 | for k, v := range params { |
| 104 | if k == "hash" { |
| 105 | hash = v[0] |
| 106 | continue |
| 107 | } |
| 108 | strs = append(strs, k+"="+v[0]) |
| 109 | } |
| 110 | sort.Strings(strs) |
| 111 | var imploded = "" |
| 112 | for _, s := range strs { |
| 113 | if imploded != "" { |
| 114 | imploded += "\n" |
| 115 | } |
| 116 | imploded += s |
| 117 | } |
| 118 | sha256hash := sha256.New() |
| 119 | io.WriteString(sha256hash, token) |
| 120 | hmachash := hmac.New(sha256.New, sha256hash.Sum(nil)) |
| 121 | io.WriteString(hmachash, imploded) |
| 122 | ss := hex.EncodeToString(hmachash.Sum(nil)) |
| 123 | return hash == ss |
| 124 | } |
no outgoing calls
no test coverage detected