-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.go
48 lines (36 loc) · 995 Bytes
/
strings.go
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
package kmsdecrypt
// DecryptStringSlice will decrypt values from []string s.
// Returns a []string of decrypted strings.
func (d *KmsDecrypter) DecryptStringSlice(s []string) ([]string, error) {
resultChannel := make(chan resultString)
count := len(s)
for _, str := range s {
go d.decryptString(&str, resultChannel)
}
// Wait for all go-routines to finish.
result := []string{}
for i := 0; i < count; i++ {
res := <-resultChannel
if res.err != nil {
return result, res.err
}
result = append(result, res.str)
}
return result, nil
}
// DecryptString will string s. Returns a decrypted string.
func (d *KmsDecrypter) DecryptString(s string) (string, error) {
resultChannel := make(chan resultString)
count := 1
go d.decryptString(&s, resultChannel)
// Wait for the channel to send it's result.
result := ""
for i := 0; i < count; i++ {
res := <-resultChannel
if res.err != nil {
return result, res.err
}
result = res.str
}
return result, nil
}