@@ -82,23 +82,30 @@ func fileExists(filename string) bool {
82
82
return ! info .IsDir ()
83
83
}
84
84
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 )
89
89
}
90
90
}
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 )
94
94
}
95
95
}
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 )
99
99
}
100
100
}
101
101
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
+ }
102
109
return nil
103
110
}
104
111
@@ -175,7 +182,7 @@ func main() {
175
182
subscriberQoS = lvl
176
183
}
177
184
var ca , cert , key []byte
178
- if err := validateTLSFiles (argCafile , argKey , argCert ); err != nil {
185
+ if err := validateTLSFiles (* argCafile , * argKey , * argCert ); err != nil {
179
186
fmt .Fprintln (os .Stderr , err )
180
187
os .Exit (1 )
181
188
} else {
0 commit comments