Move httpsig algs constant slice to modules/setting/federation.go

This commit is contained in:
Anthony Wang 2022-06-14 12:16:32 -05:00
parent e60158c70b
commit a4403e4e80
No known key found for this signature in database
GPG key ID: BC96B00AEC5F2D76
2 changed files with 9 additions and 10 deletions

View file

@ -55,15 +55,6 @@ type Client struct {
pubID string pubID string
} }
var algos []httpsig.Algorithm
func init() {
algos = make([]httpsig.Algorithm, len(setting.Federation.Algorithms))
for i, algo := range setting.Federation.Algorithms {
algos[i] = httpsig.Algorithm(algo)
}
}
// NewClient function // NewClient function
func NewClient(user *user_model.User, pubID string) (c *Client, err error) { func NewClient(user *user_model.User, pubID string) (c *Client, err error) {
if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil { if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil {
@ -88,7 +79,7 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) {
Proxy: proxy.Proxy(), Proxy: proxy.Proxy(),
}, },
}, },
algs: algos, algs: setting.HttpsigAlgs,
digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm), digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm),
getHeaders: setting.Federation.GetHeaders, getHeaders: setting.Federation.GetHeaders,
postHeaders: setting.Federation.PostHeaders, postHeaders: setting.Federation.PostHeaders,

View file

@ -29,6 +29,9 @@ var (
} }
) )
// Constant slice of httpsig algorithm objects
var HttpsigAlgs []httpsig.Algorithm
func newFederationService() { func newFederationService() {
if err := Cfg.Section("federation").MapTo(&Federation); err != nil { if err := Cfg.Section("federation").MapTo(&Federation); err != nil {
log.Fatal("Failed to map Federation settings: %v", err) log.Fatal("Failed to map Federation settings: %v", err)
@ -36,4 +39,9 @@ func newFederationService() {
log.Fatal("unsupported digest algorithm: %s", Federation.DigestAlgorithm) log.Fatal("unsupported digest algorithm: %s", Federation.DigestAlgorithm)
return return
} }
HttpsigAlgs = make([]httpsig.Algorithm, len(Federation.Algorithms))
for i, alg := range Federation.Algorithms {
HttpsigAlgs[i] = httpsig.Algorithm(alg)
}
} }