diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-02-22 12:02:51 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-02-22 14:12:27 +0100 |
commit | 4c08524c42fb2967be03f463236236c6a4d7cc3e (patch) | |
tree | 0fa38fc3e902c874034d2251a2b6b186f4bf41b2 | |
parent | 3bae25b173da467c0ab3b6bb8ec6538fce20c6f0 (diff) |
openpgp: Generalize fingerprint formatting.
-rw-r--r-- | openpgp/src/fingerprint.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs index cdb37ca2..eb411923 100644 --- a/openpgp/src/fingerprint.rs +++ b/openpgp/src/fingerprint.rs @@ -232,10 +232,7 @@ impl Fingerprint { /// Common code for the above functions. fn convert_to_string(&self, pretty: bool) -> String { - let raw = match self { - Fingerprint::V4(ref fp) => &fp[..], - Fingerprint::Invalid(ref fp) => &fp[..], - }; + let raw = self.as_bytes(); // We currently only handle V4 fingerprints, which look like: // @@ -250,8 +247,8 @@ impl Fingerprint { + if pretty { // Every 2 bytes of output, we insert a space. raw.len() / 2 - // After 5 groups, there is another space. - + raw.len() / 10 + // After half of the groups, there is another space. + + 1 } else { 0 }); for (i, b) in raw.iter().enumerate() { @@ -259,7 +256,7 @@ impl Fingerprint { output.push(b' '); } - if pretty && i > 0 && i % 10 == 0 { + if pretty && i > 0 && i * 2 == raw.len() { output.push(b' '); } |