Skip to content

Commit c61f449

Browse files
committed
move function
1 parent 1fb3332 commit c61f449

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

resources/lib/UnityUser.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,26 +299,12 @@ public function getSSHKeys(): array
299299
return $result;
300300
}
301301

302-
/*
303-
key must take the form "KEY_TYPE KEY_DATA OPTIONAL_COMMENT"
304-
https://github.com/phpseclib/phpseclib/issues/2117
305-
*/
306-
private static function removeSSHKeyOptionalCommentSuffix(string $key): string
307-
{
308-
$matches = [];
309-
if (preg_match("/^(\S+ \S+)/", $key, $matches)) {
310-
return $matches[1];
311-
} else {
312-
throw new \ValueError("invalid SSH key: $key");
313-
}
314-
}
315-
316302
/* checks if key exists, ignoring the optional comment suffix */
317303
public function SSHKeyExists(string $key): bool
318304
{
319-
$keyNoSuffix = self::removeSSHKeyOptionalCommentSuffix($key);
305+
$keyNoSuffix = removeSSHKeyOptionalCommentSuffix($key);
320306
foreach ($this->getSSHKeys() as $foundKey) {
321-
$foundKeyNoSuffix = self::removeSSHKeyOptionalCommentSuffix($foundKey);
307+
$foundKeyNoSuffix = removeSSHKeyOptionalCommentSuffix($foundKey);
322308
if ($key === $foundKey || $keyNoSuffix === $foundKeyNoSuffix) {
323309
return true;
324310
}

resources/lib/utils.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ function ensure(bool $condition, ?string $message = null): void
1515
}
1616
}
1717

18+
/*
19+
key must take the form "KEY_TYPE KEY_DATA OPTIONAL_COMMENT"
20+
*/
21+
function removeSSHKeyOptionalCommentSuffix(string $key): string
22+
{
23+
$matches = [];
24+
if (preg_match("/^(\S+ \S+)/", $key, $matches)) {
25+
return $matches[1];
26+
} else {
27+
throw new \ValueError("invalid SSH key: $key");
28+
}
29+
}
30+
1831
/**
1932
* @return array of length 2: boolean is_valid, string invalid_explanation
2033
*/

0 commit comments

Comments
 (0)