Rust wrapper: ECC: Allow import_private_*() calls with empty pub_buf slice

This commit is contained in:
Josh Holtrop
2026-01-29 10:32:41 -05:00
parent a6316114bd
commit 88b34a68d8
2 changed files with 8 additions and 2 deletions

View File

@@ -711,10 +711,11 @@ impl ECC {
}
let mut wc_ecc_key = unsafe { wc_ecc_key.assume_init() };
let priv_size = priv_buf.len() as u32;
let pub_ptr = if pub_buf.len() == 0 {core::ptr::null()} else {pub_buf.as_ptr()};
let pub_size = pub_buf.len() as u32;
let rc = unsafe {
sys::wc_ecc_import_private_key(priv_buf.as_ptr(), priv_size,
pub_buf.as_ptr(), pub_size, &mut wc_ecc_key)
pub_ptr, pub_size, &mut wc_ecc_key)
};
if rc != 0 {
return Err(rc);
@@ -784,10 +785,11 @@ impl ECC {
}
let mut wc_ecc_key = unsafe { wc_ecc_key.assume_init() };
let priv_size = priv_buf.len() as u32;
let pub_ptr = if pub_buf.len() == 0 {core::ptr::null()} else {pub_buf.as_ptr()};
let pub_size = pub_buf.len() as u32;
let rc = unsafe {
sys::wc_ecc_import_private_key_ex(priv_buf.as_ptr(), priv_size,
pub_buf.as_ptr(), pub_size, &mut wc_ecc_key, curve_id)
pub_ptr, pub_size, &mut wc_ecc_key, curve_id)
};
if rc != 0 {
return Err(rc);

View File

@@ -197,6 +197,8 @@ fn test_ecc_import_export_private() {
let mut ecc2 = ECC::import_private_key(&d, x963, None, None).expect("Error with import_private_key()");
let valid = ecc2.verify_hash(&signature, &hash).expect("Error with verify_hash()");
assert_eq!(valid, true);
ECC::import_private_key(&d, &[], None, None).expect("Error with import_private_key()");
}
#[test]
@@ -221,6 +223,8 @@ fn test_ecc_import_export_private_ex() {
let mut ecc2 = ECC::import_private_key_ex(&d, x963, curve_id, None, None).expect("Error with import_private_key_ex()");
let valid = ecc2.verify_hash(&signature, &hash).expect("Error with verify_hash()");
assert_eq!(valid, true);
ECC::import_private_key_ex(&d, &[], curve_id, None, None).expect("Error with import_private_key_ex()");
}
#[test]