// Shadow these bindgen created values to correct their type. pubconst SHA256_LENGTH: usize = nss_p11::SHA256_LENGTH as usize; pubconst AES_BLOCK_SIZE: usize = nss_p11::AES_BLOCK_SIZE as usize;
impl PublicKey { /// Get the HPKE serialization of the public key. /// /// # Errors /// When the key cannot be exported, which can be because the type is not supported. /// # Panics /// When keys are too large to fit in `c_uint/usize`. So only on programming error. pubfn key_data(&self) -> Res<Vec<u8>> { letmut buf = vec![0; 100]; letmut len: c_uint = 0;
secstatus_to_res(unsafe {
PK11_HPKE_Serialize(
**self,
buf.as_mut_ptr(),
&mut len,
c_uint::try_from(buf.len()).unwrap(),
)
})?;
buf.truncate(usize::try_from(len).unwrap());
Ok(buf)
}
impl PrivateKey { /// Get the bits of the private key. /// /// # Errors /// When the key cannot be exported, which can be because the type is not supported /// or because the key data cannot be extracted from the PKCS#11 module. /// # Panics /// When the values are too large to fit. So never. pubfn key_data(&self) -> Res<Vec<u8>> { letmut key_item = SECItemMut::make_empty();
secstatus_to_res(unsafe {
PK11_ReadRawAttribute(
PK11ObjectType::PK11_TypePrivKey,
(**self).cast(),
CKA_VALUE,
key_item.as_mut(),
)
})?;
Ok(key_item.as_slice().to_owned())
}
}
impl SymKey { /// You really don't want to use this. /// /// # Errors /// Internal errors in case of failures in NSS. pubfn key_data(&self) -> Res<&[u8]> {
secstatus_to_res(unsafe { PK11_ExtractKeyValue(**self) })?;
let key_item = unsafe { PK11_GetKeyData(**self) }; // This is accessing a value attached to the key, so we can treat this as a borrow. matchunsafe { key_item.as_mut() } {
None => Err(Error::InternalError),
Some(key) => Ok(unsafe { std::slice::from_raw_parts(key.data, key.len as usize) }),
}
}
/// Generate a randomized buffer. /// # Panics /// When `size` is too large or NSS fails. #[must_use] pubfn random(size: usize) -> Vec<u8> { letmut buf = vec![0; size];
secstatus_to_res(unsafe {
PK11_GenerateRandom(buf.as_mut_ptr(), c_int::try_from(buf.len()).unwrap())
})
.unwrap();
buf
}
impl_into_result!(SECOidData);
#[cfg(test)] mod test { usesuper::random; use test_fixture::fixture_init;
#[test] fn randomness() {
fixture_init(); // If this ever fails, there is either a bug, or it's time to buy a lottery ticket.
assert_ne!(random(16), random(16));
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-22)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.