Skip to content

Commit 1643f46

Browse files
authored
Merge pull request #38 from inovex/refactor-tls-checking
Refactor tls checking
2 parents 5ad0273 + 62d3a52 commit 1643f46

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

main.go

+18-11
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,30 @@ func fileExists(filename string) bool {
8282
return !info.IsDir()
8383
}
8484

85-
func validateTLSFiles(argCafile, argKey, argCert *string) error {
86-
if len(*argCafile) > 0 {
87-
if !fileExists(*argCafile) {
88-
return fmt.Errorf("CA file '%s' does not exist", *argCafile)
85+
func validateTLSFiles(argCafile, argKey, argCert string) error {
86+
if len(argCafile) > 0 {
87+
if !fileExists(argCafile) {
88+
return fmt.Errorf("CA file '%s' does not exist", argCafile)
8989
}
9090
}
91-
if len(*argKey) > 0 {
92-
if !fileExists(*argKey) {
93-
return fmt.Errorf("key file '%s' does not exist", *argKey)
91+
if len(argKey) > 0 {
92+
if !fileExists(argKey) {
93+
return fmt.Errorf("key file '%s' does not exist", argKey)
9494
}
9595
}
96-
if len(*argCert) > 0 {
97-
if !fileExists(*argCert) {
98-
return fmt.Errorf("cert file '%s' does not exist", *argCert)
96+
if len(argCert) > 0 {
97+
if !fileExists(argCert) {
98+
return fmt.Errorf("cert file '%s' does not exist", argCert)
9999
}
100100
}
101101

102+
if len(argKey) > 0 && len(argCert) < 1 {
103+
return fmt.Errorf("A key file is specified but no certificate file")
104+
}
105+
106+
if len(argKey) < 1 && len(argCert) > 0 {
107+
return fmt.Errorf("A cert file is specified but no key file")
108+
}
102109
return nil
103110
}
104111

@@ -175,7 +182,7 @@ func main() {
175182
subscriberQoS = lvl
176183
}
177184
var ca, cert, key []byte
178-
if err := validateTLSFiles(argCafile, argKey, argCert); err != nil {
185+
if err := validateTLSFiles(*argCafile, *argKey, *argCert); err != nil {
179186
fmt.Fprintln(os.Stderr, err)
180187
os.Exit(1)
181188
} else {

0 commit comments

Comments
 (0)