Skip to content

Commit ff28a11

Browse files
Merge pull request #9724 from holtrop-wolfssl/rust-ecc-allow-empty-pub_buf_slice-on-import-private
Rust wrapper: ECC: Allow import_private_*() calls with empty pub_buf slice
2 parents 1dc177f + 88b34a6 commit ff28a11

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,11 @@ impl ECC {
711711
}
712712
let mut wc_ecc_key = unsafe { wc_ecc_key.assume_init() };
713713
let priv_size = priv_buf.len() as u32;
714+
let pub_ptr = if pub_buf.len() == 0 {core::ptr::null()} else {pub_buf.as_ptr()};
714715
let pub_size = pub_buf.len() as u32;
715716
let rc = unsafe {
716717
sys::wc_ecc_import_private_key(priv_buf.as_ptr(), priv_size,
717-
pub_buf.as_ptr(), pub_size, &mut wc_ecc_key)
718+
pub_ptr, pub_size, &mut wc_ecc_key)
718719
};
719720
if rc != 0 {
720721
return Err(rc);
@@ -784,10 +785,11 @@ impl ECC {
784785
}
785786
let mut wc_ecc_key = unsafe { wc_ecc_key.assume_init() };
786787
let priv_size = priv_buf.len() as u32;
788+
let pub_ptr = if pub_buf.len() == 0 {core::ptr::null()} else {pub_buf.as_ptr()};
787789
let pub_size = pub_buf.len() as u32;
788790
let rc = unsafe {
789791
sys::wc_ecc_import_private_key_ex(priv_buf.as_ptr(), priv_size,
790-
pub_buf.as_ptr(), pub_size, &mut wc_ecc_key, curve_id)
792+
pub_ptr, pub_size, &mut wc_ecc_key, curve_id)
791793
};
792794
if rc != 0 {
793795
return Err(rc);

wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ fn test_ecc_import_export_private() {
197197
let mut ecc2 = ECC::import_private_key(&d, x963, None, None).expect("Error with import_private_key()");
198198
let valid = ecc2.verify_hash(&signature, &hash).expect("Error with verify_hash()");
199199
assert_eq!(valid, true);
200+
201+
ECC::import_private_key(&d, &[], None, None).expect("Error with import_private_key()");
200202
}
201203

202204
#[test]
@@ -221,6 +223,8 @@ fn test_ecc_import_export_private_ex() {
221223
let mut ecc2 = ECC::import_private_key_ex(&d, x963, curve_id, None, None).expect("Error with import_private_key_ex()");
222224
let valid = ecc2.verify_hash(&signature, &hash).expect("Error with verify_hash()");
223225
assert_eq!(valid, true);
226+
227+
ECC::import_private_key_ex(&d, &[], curve_id, None, None).expect("Error with import_private_key_ex()");
224228
}
225229

226230
#[test]

0 commit comments

Comments
 (0)