refactor(crypto): use IV as a constant

This commit is contained in:
Mathis Maquenne
2025-05-07 20:57:12 +02:00
parent 67af80403b
commit ebfb312718
4 changed files with 13 additions and 26 deletions
+1 -8
View File
@@ -11,7 +11,6 @@ import (
type Config struct {
ArlCookie string `mapstructure:"arl_cookie"`
SecretKey string `mapstructure:"secret_key"`
IV string `mapstructure:"iv"`
}
func New(cfgPath, cfgDir string) (*Config, error) {
@@ -22,7 +21,7 @@ func New(cfgPath, cfgDir string) (*Config, error) {
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
fmt.Printf("Config file not found, creating one at %s\n", cfgPath)
content := []byte("arl_cookie = ''\nsecret_key = ''\niv = '0001020304050607'\n")
content := []byte("arl_cookie = ''\nsecret_key = ''\n")
if err := os.WriteFile(cfgPath, content, 0644); err != nil {
return nil, fmt.Errorf("failed to create config file: %w", err)
}
@@ -52,12 +51,6 @@ func New(cfgPath, cfgDir string) (*Config, error) {
if len(cfg.SecretKey) != 16 {
return nil, fmt.Errorf("secret_key must be 16 bytes long")
}
if cfg.IV == "" {
return nil, fmt.Errorf("iv is not set in config file")
}
if len(cfg.IV) != 16 {
return nil, fmt.Errorf("iv must be 16 bytes long")
}
return cfg, nil
}