Fix credential get functions not checking for null

This commit is contained in:
pjht 2023-08-29 10:01:06 -05:00
parent 361caedafc
commit d04e75ce3b
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -30,12 +30,16 @@ impl Credential {
} }
impl CredentialRef { impl CredentialRef {
pub fn aaguid(&self) -> &[u8] { pub fn aaguid(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_aaguid_ptr(self.as_ptr()).is_null() {
fido_cred_aaguid_ptr(self.as_ptr()), None
fido_cred_aaguid_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_aaguid_ptr(self.as_ptr()),
fido_cred_aaguid_len(self.as_ptr()),
))
}
} }
} }
@ -48,12 +52,16 @@ impl CredentialRef {
} }
} }
pub fn authdata(&self) -> &[u8] { pub fn authdata(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_authdata_ptr(self.as_ptr()).is_null() {
fido_cred_authdata_ptr(self.as_ptr()), None
fido_cred_authdata_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_authdata_ptr(self.as_ptr()),
fido_cred_authdata_len(self.as_ptr()),
))
}
} }
} }
@ -66,12 +74,16 @@ impl CredentialRef {
} }
} }
pub fn clientdata_hash(&self) -> &[u8] { pub fn clientdata_hash(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_clientdata_hash_ptr(self.as_ptr()).is_null() {
fido_cred_clientdata_hash_ptr(self.as_ptr()), None
fido_cred_clientdata_hash_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_clientdata_hash_ptr(self.as_ptr()),
fido_cred_clientdata_hash_len(self.as_ptr()),
))
}
} }
} }
@ -105,21 +117,29 @@ impl CredentialRef {
} }
} }
pub fn cred_id(&self) -> &[u8] { pub fn cred_id(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_id_ptr(self.as_ptr()).is_null() {
fido_cred_id_ptr(self.as_ptr()), None
fido_cred_id_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_id_ptr(self.as_ptr()),
fido_cred_id_len(self.as_ptr()),
))
}
} }
} }
pub fn largeblob_key(&self) -> &[u8] { pub fn largeblob_key(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_largeblob_key_ptr(self.as_ptr()).is_null() {
fido_cred_largeblob_key_ptr(self.as_ptr()), None
fido_cred_largeblob_key_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_largeblob_key_ptr(self.as_ptr()),
fido_cred_largeblob_key_len(self.as_ptr()),
))
}
} }
} }
@ -145,12 +165,16 @@ impl CredentialRef {
} }
} }
pub fn pubkey(&self) -> &[u8] { pub fn pubkey(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_pubkey_ptr(self.as_ptr()).is_null() {
fido_cred_pubkey_ptr(self.as_ptr()), None
fido_cred_pubkey_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_pubkey_ptr(self.as_ptr()),
fido_cred_pubkey_len(self.as_ptr()),
))
}
} }
} }
@ -321,12 +345,16 @@ impl CredentialRef {
unsafe { check(fido_cred_set_x509(self.as_ptr_mut(), &x509[0], x509.len())) } unsafe { check(fido_cred_set_x509(self.as_ptr_mut(), &x509[0], x509.len())) }
} }
pub fn sig(&self) -> &[u8] { pub fn sig(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_sig_ptr(self.as_ptr()).is_null() {
fido_cred_sig_ptr(self.as_ptr()), None
fido_cred_sig_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_sig_ptr(self.as_ptr()),
fido_cred_sig_len(self.as_ptr()),
))
}
} }
} }
@ -373,12 +401,16 @@ impl CredentialRef {
unsafe { check(fido_cred_verify_self(self.as_ptr())) } unsafe { check(fido_cred_verify_self(self.as_ptr())) }
} }
pub fn x5c(&self) -> &[u8] { pub fn x5c(&self) -> Option<&[u8]> {
unsafe { unsafe {
std::slice::from_raw_parts( if fido_cred_x5c_ptr(self.as_ptr()).is_null() {
fido_cred_x5c_ptr(self.as_ptr()), None
fido_cred_x5c_len(self.as_ptr()), } else {
) Some(std::slice::from_raw_parts(
fido_cred_x5c_ptr(self.as_ptr()),
fido_cred_x5c_len(self.as_ptr()),
))
}
} }
} }
} }