1 use std
::fmt
::{self, Display}
;
4 use serde
::{Deserialize, Serialize}
;
8 use pbs_tools
::format
::{as_fingerprint, bytes_as_fingerprint}
;
10 #[api(default: "encrypt")]
11 #[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
12 #[serde(rename_all = "kebab-case")]
13 /// Defines whether data is encrypted (using an AEAD cipher), only signed, or neither.
23 #[derive(Debug, Eq, PartialEq, Hash, Clone, Deserialize, Serialize)]
25 /// 32-byte fingerprint, usually calculated with SHA256.
26 pub struct Fingerprint
{
27 #[serde(with = "bytes_as_fingerprint")]
32 pub fn new(bytes
: [u8; 32]) -> Self {
35 pub fn bytes(&self) -> &[u8; 32] {
40 /// Display as short key ID
41 impl Display
for Fingerprint
{
42 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
43 write
!(f
, "{}", as_fingerprint(&self.bytes
[0..8]))
47 impl std
::str::FromStr
for Fingerprint
{
50 fn from_str(s
: &str) -> Result
<Self, Error
> {
51 let mut tmp
= s
.to_string();
52 tmp
.retain(|c
| c
!= '
:'
);
53 let bytes
= proxmox
::tools
::hex_to_digest(&tmp
)?
;
54 Ok(Fingerprint
::new(bytes
))