Skip to content

Commit

Permalink
AsymetrticKey: add getComment() method
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Apr 19, 2021
1 parent 701881d commit d9615a6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions phpseclib/Crypt/Common/AsymmetricKey.php
Expand Up @@ -115,6 +115,14 @@ abstract class AsymmetricKey
*/
protected static $engines = [];

/**
* Key Comment
*
* @var null|string
* @access private
*/
private $comment;

/**
* The constructor
*/
Expand Down Expand Up @@ -173,8 +181,10 @@ public static function load($key, $password = false)
}

$components['format'] = $format;
$comment = isset($components['comment']) ? $components['comment'] : null;
$new = static::onLoad($components);
$new->format = $format;
$new->comment = $comment;
return $new instanceof PrivateKey ?
$new->withPassword($password) :
$new;
Expand Down Expand Up @@ -425,6 +435,19 @@ public function getLoadedFormat()
return $meta->getShortName();
}

/**
* Returns the key's comment
*
* Not all key formats support comments. If you want to set a comment use toString()
*
* @access public
* @return null|string
*/
public function getComment()
{
return $this->comment;
}

/**
* Tests engine validity
*
Expand Down

1 comment on commit d9615a6

@terrafrost
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1638

Please sign in to comment.