Rustfmt pass, and rustfmt --check in CI"
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
e1b53eae3c
commit
a104ebc3f6
79 changed files with 1344 additions and 957 deletions
|
|
@ -4,9 +4,9 @@
|
|||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
use crate::hashes::{Hash, Algo};
|
||||
use crate::util::helpers::Base64;
|
||||
use crate::hashes::{Algo, Hash};
|
||||
use crate::util::error::Error;
|
||||
use crate::util::helpers::Base64;
|
||||
use minidom::IntoAttributeValue;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
@ -27,11 +27,11 @@ impl FromStr for ContentId {
|
|||
let temp: Vec<_> = match temp[..] {
|
||||
[lhs, rhs] => {
|
||||
if rhs != "bob.xmpp.org" {
|
||||
return Err(Error::ParseError("Wrong domain for cid URI."))
|
||||
return Err(Error::ParseError("Wrong domain for cid URI."));
|
||||
}
|
||||
lhs.splitn(2, '+').collect()
|
||||
},
|
||||
_ => return Err(Error::ParseError("Missing @ in cid URI."))
|
||||
}
|
||||
_ => return Err(Error::ParseError("Missing @ in cid URI.")),
|
||||
};
|
||||
let (algo, hex) = match temp[..] {
|
||||
[lhs, rhs] => {
|
||||
|
|
@ -41,8 +41,8 @@ impl FromStr for ContentId {
|
|||
_ => unimplemented!(),
|
||||
};
|
||||
(algo, rhs)
|
||||
},
|
||||
_ => return Err(Error::ParseError("Missing + in cid URI."))
|
||||
}
|
||||
_ => return Err(Error::ParseError("Missing + in cid URI.")),
|
||||
};
|
||||
let hash = Hash::from_hex(algo, hex)?;
|
||||
Ok(ContentId { hash })
|
||||
|
|
@ -108,15 +108,26 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
let cid: ContentId = "sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org".parse().unwrap();
|
||||
let cid: ContentId = "sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org"
|
||||
.parse()
|
||||
.unwrap();
|
||||
assert_eq!(cid.hash.algo, Algo::Sha_1);
|
||||
assert_eq!(cid.hash.hash, b"\x8f\x35\xfe\xf1\x10\xff\xc5\xdf\x08\xd5\x79\xa5\x00\x83\xff\x93\x08\xfb\x62\x42");
|
||||
assert_eq!(cid.into_attribute_value().unwrap(), "sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org");
|
||||
assert_eq!(
|
||||
cid.hash.hash,
|
||||
b"\x8f\x35\xfe\xf1\x10\xff\xc5\xdf\x08\xd5\x79\xa5\x00\x83\xff\x93\x08\xfb\x62\x42"
|
||||
);
|
||||
assert_eq!(
|
||||
cid.into_attribute_value().unwrap(),
|
||||
"sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org"
|
||||
);
|
||||
|
||||
let elem: Element = "<data xmlns='urn:xmpp:bob' cid='sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org'/>".parse().unwrap();
|
||||
let data = Data::try_from(elem).unwrap();
|
||||
assert_eq!(data.cid.hash.algo, Algo::Sha_1);
|
||||
assert_eq!(data.cid.hash.hash, b"\x8f\x35\xfe\xf1\x10\xff\xc5\xdf\x08\xd5\x79\xa5\x00\x83\xff\x93\x08\xfb\x62\x42");
|
||||
assert_eq!(
|
||||
data.cid.hash.hash,
|
||||
b"\x8f\x35\xfe\xf1\x10\xff\xc5\xdf\x08\xd5\x79\xa5\x00\x83\xff\x93\x08\xfb\x62\x42"
|
||||
);
|
||||
assert!(data.max_age.is_none());
|
||||
assert!(data.type_.is_none());
|
||||
assert!(data.data.is_empty());
|
||||
|
|
@ -138,14 +149,18 @@ mod tests {
|
|||
};
|
||||
assert_eq!(message, "Missing + in cid URI.");
|
||||
|
||||
let error = "sha1+1234@coucou.linkmauve.fr".parse::<ContentId>().unwrap_err();
|
||||
let error = "sha1+1234@coucou.linkmauve.fr"
|
||||
.parse::<ContentId>()
|
||||
.unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Wrong domain for cid URI.");
|
||||
|
||||
let error = "sha1+invalid@bob.xmpp.org".parse::<ContentId>().unwrap_err();
|
||||
let error = "sha1+invalid@bob.xmpp.org"
|
||||
.parse::<ContentId>()
|
||||
.unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseIntError(error) => error,
|
||||
_ => panic!(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue