| 1 |
package zk |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto/sha1" |
| 5 |
"encoding/base64" |
| 6 |
"fmt" |
| 7 |
"math/rand" |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
func AuthACL(perms int32) []ACL { |
| 14 |
return []ACL{{perms, "auth", ""}} |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
func WorldACL(perms int32) []ACL { |
| 21 |
return []ACL{{perms, "world", "anyone"}} |
| 22 |
} |
| 23 |
|
| 24 |
func DigestACL(perms int32, user, password string) []ACL { |
| 25 |
userPass := []byte(fmt.Sprintf("%s:%s", user, password)) |
| 26 |
h := sha1.New() |
| 27 |
if n, err := h.Write(userPass); err != nil || n != len(userPass) { |
| 28 |
panic("SHA1 failed") |
| 29 |
} |
| 30 |
digest := base64.StdEncoding.EncodeToString(h.Sum(nil)) |
| 31 |
return []ACL{{perms, "digest", fmt.Sprintf("%s:%s", user, digest)}} |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
func stringShuffle(s []string) { |
| 36 |
for i := len(s) - 1; i > 0; i-- { |
| 37 |
j := rand.Intn(i + 1) |
| 38 |
s[i], s[j] = s[j], s[i] |
| 39 |
} |
| 40 |
} |