Skip to content

Commit a9abfad

Browse files
refactor: switch from bs58 to multibase for base58
Most projects will already use multibase in their dependency tree, so this should reduce duplication there. If multibase is not good enough for folks, we should make sure to improve it, so we can include it without worry.
1 parent 8bcd8ef commit a9abfad

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ default = ["url"]
1414

1515
[dependencies]
1616
arrayref = "0.3"
17-
bs58 = "0.4.0"
1817
byteorder = "1.3.1"
1918
data-encoding = "2.1"
19+
multibase = "0.9.1"
2020
multihash = { version = "0.16", default-features = false, features = ["std", "multihash-impl", "identity"] }
2121
percent-encoding = "2.1.0"
2222
serde = "1.0.70"

src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ impl From<multihash::Error> for Error {
5555
}
5656
}
5757

58-
impl From<bs58::decode::Error> for Error {
59-
fn from(err: bs58::decode::Error) -> Error {
58+
impl From<multibase::Error> for Error {
59+
fn from(err: multibase::Error) -> Error {
6060
Error::ParsingError(err.into())
6161
}
6262
}

src/protocol.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a> Protocol<'a> {
162162
}
163163
"p2p" => {
164164
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
165-
let decoded = bs58::decode(s).into_vec()?;
165+
let decoded = multibase::Base::Base58Btc.decode(s)?;
166166
Ok(Protocol::P2p(Multihash::from_bytes(&decoded)?))
167167
}
168168
"http" => Ok(Protocol::Http),
@@ -512,7 +512,11 @@ impl<'a> fmt::Display for Protocol<'a> {
512512
let s = BASE32.encode(addr.hash());
513513
write!(f, "/onion3/{}:{}", s.to_lowercase(), addr.port())
514514
}
515-
P2p(c) => write!(f, "/p2p/{}", bs58::encode(c.to_bytes()).into_string()),
515+
P2p(c) => write!(
516+
f,
517+
"/p2p/{}",
518+
multibase::Base::Base58Btc.encode(c.to_bytes())
519+
),
516520
P2pCircuit => f.write_str("/p2p-circuit"),
517521
Quic => f.write_str("/quic"),
518522
Sctp(port) => write!(f, "/sctp/{}", port),

tests/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn ma_valid(source: &str, target: &str, protocols: Vec<Protocol<'_>>) {
161161
}
162162

163163
fn multihash(s: &str) -> Multihash {
164-
Multihash::from_bytes(&bs58::decode(s).into_vec().unwrap()).unwrap()
164+
Multihash::from_bytes(&multibase::Base::Base58Btc.decode(s).unwrap()).unwrap()
165165
}
166166

167167
#[test]

0 commit comments

Comments
 (0)