Skip to content

Commit d583981

Browse files
authored
Backward compatible to old-format fingerprint already in database. (#15)
1 parent faf0e89 commit d583981

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ indenter = "0.3.3"
3636
itertools = "0.14.0"
3737
derivative = "2.2.0"
3838
async-lock = "3.4.0"
39+
hex = "0.4.3"

src/utils/fingerprint.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::bail;
1+
use anyhow::{anyhow, bail};
22
use base64::prelude::*;
33
use blake2::digest::typenum;
44
use blake2::{Blake2b, Digest};
@@ -39,10 +39,16 @@ impl Fingerprint {
3939
}
4040

4141
pub fn from_base64(s: &str) -> anyhow::Result<Self> {
42-
let bytes = BASE64_STANDARD.decode(s)?;
42+
let bytes = match s.len() {
43+
24 => BASE64_STANDARD.decode(s)?,
44+
45+
// For backward compatibility. Some old version (<= v0.1.2) is using hex encoding.
46+
32 => hex::decode(s)?,
47+
_ => bail!("Encoded fingerprint length is unexpected: {}", s.len()),
48+
};
4349
match bytes.try_into() {
4450
Ok(bytes) => Ok(Fingerprint(bytes)),
45-
Err(_) => bail!("Fingerprint base64 length is unexpected"),
51+
Err(e) => bail!("Fingerprint bytes length is unexpected: {}", e.len()),
4652
}
4753
}
4854
}

0 commit comments

Comments
 (0)