flash.moe/src/SSHKeys/SSHKeyInfo.php

77 lines
2 KiB
PHP
Raw Normal View History

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 Carbon\CarbonImmutable;
2024-10-21 20:50:01 +00:00
use Index\Db\DbResult;
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
2024-10-21 20:50:01 +00:00
public function __construct(DbResult $result) {
2023-10-12 19:03:00 +00:00
$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;
}
public function getCreatedAt(): CarbonImmutable {
return CarbonImmutable::createFromTimestampUTC($this->createdAt);
2023-10-12 19:03:00 +00:00
}
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;
}
public function getDeprecatedAt(): ?CarbonImmutable {
return $this->deprecatedAt === null ? null : CarbonImmutable::createFromTimestampUTC($this->deprecatedAt);
2023-10-12 19:03:00 +00:00
}
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);
}
}