-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmulti.go
51 lines (41 loc) · 1.25 KB
/
multi.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
49
50
51
package tsig
import (
"errors"
"github.com/miekg/dns"
)
type multiProvider struct {
providers []dns.TsigProvider
}
func (mp *multiProvider) Generate(msg []byte, t *dns.TSIG) (b []byte, err error) {
for _, p := range mp.providers {
if b, err = p.Generate(msg, t); err == nil || !errors.Is(err, dns.ErrKeyAlg) {
return
}
}
return nil, dns.ErrKeyAlg
}
func (mp *multiProvider) Verify(msg []byte, t *dns.TSIG) (err error) {
for _, p := range mp.providers {
if err = p.Verify(msg, t); err == nil || !errors.Is(err, dns.ErrKeyAlg) {
return
}
}
return dns.ErrKeyAlg
}
// MultiProvider creates a dns.TsigProvider that chains the provided input
// providers. This allows multiple TSIG algorithms.
//
// Each provider is called in turn and if it returns dns.ErrKeyAlg the next
// provider in the list is tried. On success or any other error, the result is
// returned; it does not continue down the list.
func MultiProvider(providers ...dns.TsigProvider) dns.TsigProvider {
allProviders := make([]dns.TsigProvider, 0, len(providers))
for _, p := range providers {
if mp, ok := p.(*multiProvider); ok {
allProviders = append(allProviders, mp.providers...)
} else {
allProviders = append(allProviders, p)
}
}
return &multiProvider{allProviders}
}