(bin: &[u8])
| 295 | } |
| 296 | |
| 297 | pub fn bin2hex(bin: &[u8]) -> String { |
| 298 | let bin_len = bin.len(); |
| 299 | let hex_len = bin_len * 2 + 1; |
| 300 | let mut hex = vec![0u8; hex_len]; |
| 301 | unsafe { |
| 302 | sodium_bin2hex(hex.as_mut_ptr() as *mut _, hex_len, bin.as_ptr(), bin_len); |
| 303 | } |
| 304 | CStr::from_bytes_with_nul(&hex) |
| 305 | .unwrap() |
| 306 | .to_str() |
| 307 | .unwrap() |
| 308 | .to_string() |
| 309 | } |
| 310 | |
| 311 | pub fn init() -> Result<(), Error> { |
| 312 | let res = unsafe { sodium_init() }; |