2022-02-06 01:36:05 +00:00
|
|
|
<?php
|
2023-10-12 22:09:04 +00:00
|
|
|
namespace Makai\SSHKeys;
|
2022-02-06 01:36:05 +00:00
|
|
|
|
|
|
|
use Index\DateTime;
|
2023-10-12 19:03:00 +00:00
|
|
|
use Index\Data\IDbResult;
|
2022-02-06 01:36:05 +00:00
|
|
|
|
|
|
|
class SSHKeyInfo {
|
|
|
|
private string $id;
|
|
|
|
private int $level;
|
|
|
|
private string $algo;
|
|
|
|
private string $body;
|
2023-10-12 18:52:24 +00:00
|
|
|
private string $comment;
|
2023-10-12 19:03:00 +00:00
|
|
|
private int $createdAt;
|
|
|
|
private ?int $deprecatedAt;
|
2022-02-06 01:36:05 +00:00
|
|
|
|
2023-10-12 19:03:00 +00:00
|
|
|
public function __construct(IDbResult $result) {
|
|
|
|
$this->id = $result->getString(0);
|
|
|
|
$this->level = $result->getInteger(1);
|
|
|
|
$this->algo = $result->getString(2);
|
|
|
|
$this->body = $result->getString(3);
|
|
|
|
$this->comment = $result->getString(4);
|
|
|
|
$this->createdAt = $result->getInteger(5);
|
|
|
|
$this->deprecatedAt = $result->isNull(6) ? null : $result->getInteger(6);
|
2022-02-06 01:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getId(): string {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLevel(): int {
|
|
|
|
return $this->level;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAlgorithm(): string {
|
|
|
|
return $this->algo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBody(): string {
|
|
|
|
return $this->body;
|
|
|
|
}
|
|
|
|
|
2023-10-12 18:52:24 +00:00
|
|
|
public function getComment(): string {
|
2022-02-06 01:36:05 +00:00
|
|
|
return $this->comment;
|
|
|
|
}
|
|
|
|
|
2023-10-12 19:03:00 +00:00
|
|
|
public function getCreatedTime(): int {
|
2022-02-06 01:36:05 +00:00
|
|
|
return $this->createdAt;
|
|
|
|
}
|
|
|
|
|
2023-10-12 19:03:00 +00:00
|
|
|
public function getCreatedAt(): DateTime {
|
|
|
|
return DateTime::fromUnixTimeSeconds($this->createdAt);
|
|
|
|
}
|
|
|
|
|
2022-02-06 01:36:05 +00:00
|
|
|
public function isDeprecated(): bool {
|
|
|
|
return $this->deprecatedAt !== null;
|
|
|
|
}
|
|
|
|
|
2023-10-12 19:03:00 +00:00
|
|
|
public function getDeprecatedTime(): ?int {
|
2022-02-06 01:36:05 +00:00
|
|
|
return $this->deprecatedAt;
|
|
|
|
}
|
|
|
|
|
2023-10-12 19:03:00 +00:00
|
|
|
public function getDeprecatedAt(): ?DateTime {
|
|
|
|
return $this->deprecatedAt === null ? null : DateTime::fromUnixTimeSeconds($this->deprecatedAt);
|
|
|
|
}
|
|
|
|
|
2022-02-06 01:36:05 +00:00
|
|
|
public function toString(bool $includeComment): string {
|
|
|
|
$line = sprintf('ssh-%s %s', $this->getAlgorithm(), $this->getBody());
|
|
|
|
if($includeComment)
|
|
|
|
$line .= sprintf(' %s (%s)', (string)$this->getComment(), $this->getCreatedAt()->format('M Y'));
|
|
|
|
return $line;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString(): string {
|
|
|
|
return $this->toString(true);
|
|
|
|
}
|
|
|
|
}
|