File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,33 @@ 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
305+ {
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 ];
310+ } else {
311+ $ keyNoComment = $ key ;
312+ }
313+ 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 ) {
324+ return true ;
325+ }
326+ }
327+ return false ;
328+ }
329+
303330 /**
304331 * Sets the login shell for the account
305332 */
You can’t perform that action at this time.
0 commit comments