Skip to content
Snippets Groups Projects
Commit 42398a54 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

rust: infohash support == operator and from hex

parent 429a5ad1
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ pub struct Blob ...@@ -44,6 +44,7 @@ pub struct Blob
} }
#[repr(C)] #[repr(C)]
#[derive(PartialEq)]
pub struct InfoHash pub struct InfoHash
{ {
pub d: [u8; HASH_LEN], pub d: [u8; HASH_LEN],
...@@ -144,6 +145,7 @@ extern { ...@@ -144,6 +145,7 @@ extern {
pub fn dht_infohash_print(h: *const InfoHash) -> *const c_char; pub fn dht_infohash_print(h: *const InfoHash) -> *const c_char;
pub fn dht_infohash_random(h: *mut InfoHash); pub fn dht_infohash_random(h: *mut InfoHash);
pub fn dht_infohash_get(h: *mut InfoHash, dat: *mut u8, dat_size: size_t); pub fn dht_infohash_get(h: *mut InfoHash, dat: *mut u8, dat_size: size_t);
pub fn dht_infohash_from_hex(h: *mut InfoHash, dat: *const c_char);
pub fn dht_infohash_is_zero(j: *const InfoHash) -> bool; pub fn dht_infohash_is_zero(j: *const InfoHash) -> bool;
// dht::PkId // dht::PkId
......
...@@ -55,6 +55,15 @@ impl InfoHash { ...@@ -55,6 +55,15 @@ impl InfoHash {
h h
} }
pub fn from_hex(data: &str) -> InfoHash {
let mut h = InfoHash::new();
unsafe {
let c_str = CString::new(data).unwrap();
dht_infohash_from_hex(&mut h, c_str.as_ptr());
}
h
}
pub fn is_zero(&self) -> bool { pub fn is_zero(&self) -> bool {
unsafe { unsafe {
dht_infohash_is_zero(self) dht_infohash_is_zero(self)
......
...@@ -65,7 +65,7 @@ impl Value { ...@@ -65,7 +65,7 @@ impl Value {
} }
} }
fn recipient(&self) -> InfoHash { pub fn recipient(&self) -> InfoHash {
unsafe { unsafe {
dht_value_get_recipient(self) dht_value_get_recipient(self)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment