mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
caps, ecaps2: Add a function to create a Disco query from a hash.
This commit is contained in:
parent
42235c42fb
commit
bdaced7603
2 changed files with 21 additions and 2 deletions
12
src/caps.rs
12
src/caps.rs
|
@ -91,7 +91,8 @@ fn compute_features(features: &[Feature]) -> Vec<u8> {
|
||||||
|
|
||||||
fn compute_identities(identities: &[Identity]) -> Vec<u8> {
|
fn compute_identities(identities: &[Identity]) -> Vec<u8> {
|
||||||
compute_items(identities, |identity| {
|
compute_items(identities, |identity| {
|
||||||
let string = format!("{}/{}/{}/{}", identity.category, identity.type_, identity.xml_lang, match identity.name { Some(ref name) => name.clone(), None => String::new() });
|
let empty = String::new();
|
||||||
|
let string = format!("{}/{}/{}/{}", identity.category, identity.type_, identity.xml_lang, match identity.name { Some(ref name) => name, None => &empty });
|
||||||
let bytes = string.as_bytes();
|
let bytes = string.as_bytes();
|
||||||
let mut vec = Vec::with_capacity(bytes.len());
|
let mut vec = Vec::with_capacity(bytes.len());
|
||||||
vec.extend_from_slice(bytes);
|
vec.extend_from_slice(bytes);
|
||||||
|
@ -191,6 +192,15 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result<Hash, String> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn query_caps(caps: Caps) -> Disco {
|
||||||
|
Disco {
|
||||||
|
node: Some(format!("{}#{}", caps.node, base64::encode(&caps.hash.hash))),
|
||||||
|
identities: vec!(),
|
||||||
|
features: vec!(),
|
||||||
|
extensions: vec!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -13,6 +13,7 @@ use hashes::{Hash, Algo};
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use ns;
|
use ns;
|
||||||
|
use base64;
|
||||||
|
|
||||||
use sha2::{Sha256, Sha512};
|
use sha2::{Sha256, Sha512};
|
||||||
use sha3::{Sha3_256, Sha3_512};
|
use sha3::{Sha3_256, Sha3_512};
|
||||||
|
@ -171,11 +172,19 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result<Hash, String> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn query_ecaps2(hash: Hash) -> Disco {
|
||||||
|
Disco {
|
||||||
|
node: Some(format!("{}#{}.{}", ns::ECAPS2, String::from(hash.algo), base64::encode(&hash.hash))),
|
||||||
|
identities: vec!(),
|
||||||
|
features: vec!(),
|
||||||
|
extensions: vec!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ecaps2;
|
use ecaps2;
|
||||||
use base64;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse() {
|
fn test_parse() {
|
||||||
|
|
Loading…
Reference in a new issue