flash.moe/src/SSHKeyInfo.php

76 lines
1.8 KiB
PHP
Raw Normal View History

2022-02-06 01:36:05 +00:00
<?php
namespace Makai;
use Index\DateTime;
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;
2022-02-06 01:36:05 +00:00
private DateTime $createdAt;
private ?DateTime $deprecatedAt;
public function __construct(
string $id,
int $level,
string $algo,
string $body,
2023-10-12 18:52:24 +00:00
string $comment,
2022-02-06 01:36:05 +00:00
int $createdAt,
?int $deprecatedAt
) {
$this->id = $id;
$this->level = $level;
$this->algo = $algo;
$this->body = $body;
$this->comment = $comment;
$this->createdAt = DateTime::fromUnixTimeSeconds($createdAt);
$this->deprecatedAt = $deprecatedAt === null ? null : DateTime::fromUnixTimeSeconds($deprecatedAt);
}
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;
}
public function getCreatedAt(): DateTime {
return $this->createdAt;
}
public function isDeprecated(): bool {
return $this->deprecatedAt !== null;
}
public function getDeprecatedAt(): ?DateTime {
return $this->deprecatedAt;
}
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);
}
}