File tree Expand file tree Collapse file tree 1 file changed +13
-17
lines changed
Expand file tree Collapse file tree 1 file changed +13
-17
lines changed Original file line number Diff line number Diff line change @@ -300,27 +300,23 @@ public function getSSHKeys(): array
300300 return $ result ;
301301 }
302302
303- /* checks if key exists, ignoring the optional comment suffix */
304- public function SSHKeyExists (string $ key ): bool
303+ private static function removeSSHKeyOptionalCommentSuffix (string $ key ): string
305304 {
306- // if a key is 3 words, assume the 3rd word is the optional comment suffix
307- $ keyMatches = [];
308- if (preg_match ("/^\s*(\S+\s+\S+)\s+(\S+)\s*$/ " , $ key , $ keyMatches )) {
309- $ keyNoComment = $ keyMatches [1 ];
305+ $ matches = [];
306+ if (preg_match ("/^\s*(\S+\s+\S+)\s+(\S+)\s*$/ " , $ key , $ matches )) {
307+ return $ matches [1 ];
310308 } else {
311- $ keyNoComment = $ key ;
309+ return $ key ;
312310 }
311+ }
312+
313+ /* checks if key exists, ignoring the optional comment suffix */
314+ public function SSHKeyExists (string $ key ): bool
315+ {
316+ $ keyNoSuffix = self ::removeSSHKeyOptionalCommentSuffix ($ key );
313317 foreach ($ this ->getSSHKeys () as $ foundKey ) {
314- if ($ key === $ foundKey ) {
315- return true ;
316- }
317- $ foundKeyMatches = [];
318- if (preg_match ("/^\s*(\S+\s+\S+)\s+(\S+)\s*$/ " , $ foundKey , $ foundKeyMatches )) {
319- $ foundKeyNoComment = $ foundKeyMatches [1 ];
320- } else {
321- $ foundKeyNoComment = $ foundKey ;
322- }
323- if ($ keyNoComment === $ foundKeyNoComment ) {
318+ $ foundKeyNoSuffix = self ::removeSSHKeyOptionalCommentSuffix ($ foundKey );
319+ if ($ key === $ foundKey || $ keyNoSuffix === $ foundKeyNoSuffix ) {
324320 return true ;
325321 }
326322 }
You can’t perform that action at this time.
0 commit comments