Skip to content

Commit 2aed581

Browse files
committed
[jwt] improve config validation
1 parent 9a89acb commit 2aed581

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/sms-gateway/jwt/config.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"time"
66
)
77

8+
const (
9+
minSecretLength = 32
10+
)
11+
812
type Config struct {
913
Secret string
1014
TTL time.Duration
@@ -16,7 +20,11 @@ func (c Config) Validate() error {
1620
return fmt.Errorf("%w: secret is required", ErrInvalidConfig)
1721
}
1822

19-
if c.TTL == 0 {
23+
if len(c.Secret) < minSecretLength {
24+
return fmt.Errorf("%w: secret must be at least %d bytes", ErrInvalidConfig, minSecretLength)
25+
}
26+
27+
if c.TTL <= 0 {
2028
return fmt.Errorf("%w: ttl must be positive", ErrInvalidConfig)
2129
}
2230

0 commit comments

Comments
 (0)