Change order of checks

This commit is contained in:
Neil Alexander 2022-10-06 11:21:00 +01:00
parent 9b48180fb5
commit 2c0284fff5
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -233,19 +233,7 @@ func loadConfig(
for _, key := range c.Global.OldVerifyKeys { for _, key := range c.Global.OldVerifyKeys {
switch { switch {
case key.KeyID == "": case key.PrivateKeyPath != "":
return nil, fmt.Errorf("key ID must be specified if public_key is specified")
case len(key.PublicKey) == ed25519.PublicKeySize:
continue
case len(key.PublicKey) > 0:
return nil, fmt.Errorf("the public_key is the wrong length")
case key.PrivateKeyPath == "":
return nil, fmt.Errorf("a private_key path must be specified if public_key isn't")
default:
var oldPrivateKeyData []byte var oldPrivateKeyData []byte
oldPrivateKeyPath := absPath(basePath, key.PrivateKeyPath) oldPrivateKeyPath := absPath(basePath, key.PrivateKeyPath)
oldPrivateKeyData, err = readFile(oldPrivateKeyPath) oldPrivateKeyData, err = readFile(oldPrivateKeyPath)
@ -264,6 +252,18 @@ func loadConfig(
key.KeyID = keyID key.KeyID = keyID
key.PrivateKey = privateKey key.PrivateKey = privateKey
key.PublicKey = privateKey.Public().(gomatrixserverlib.Base64Bytes) key.PublicKey = privateKey.Public().(gomatrixserverlib.Base64Bytes)
case len(key.PublicKey) == ed25519.PublicKeySize:
continue
case len(key.PublicKey) > 0:
return nil, fmt.Errorf("the supplied 'public_key' is the wrong length")
case key.KeyID == "":
return nil, fmt.Errorf("'key_id' must be specified if 'public_key' is specified")
default:
return nil, fmt.Errorf("either specify a 'private_key' path or supply both 'public_key' and 'key_id'")
} }
} }