fix(key): return None when empty binary is loaded (#96)

This commit is contained in:
Friedel Ziegelmayer
2019-05-28 20:10:09 +02:00
committed by Lars-Magnus Skog
parent 3ade0a1de8
commit a674557f07

View File

@@ -106,8 +106,9 @@ impl Key {
}
pub fn from_binary(data: *const u8, len: libc::c_int, key_type: KeyType) -> Option<Self> {
assert!(!data.is_null(), "missing data");
assert!(len > 0);
if data.is_null() || len == 0 {
return None;
}
let bytes = unsafe { slice::from_raw_parts(data, len as usize) };
Self::from_slice(bytes, key_type)