Skip to content

Commit

Permalink
Merge pull request #244 from geonnave/improve-authz-c-python
Browse files Browse the repository at this point in the history
EAD Authz: improvements/refactor in C and Python
  • Loading branch information
geonnave authored Mar 14, 2024
2 parents aa4ff9f + 0e2b07b commit f2263e6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ Cargo.lock
cscope*
.DS_Store
.vscode

*.log
2 changes: 1 addition & 1 deletion examples/lakers-c-native/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int main(void)
}
#ifdef LAKERS_EAD_AUTHZ
puts("processing ead2");
res = authz_device_process_ead_2(&device, &ead_2, cred_r);
res = authz_device_process_ead_2(&device, &ead_2, &fetched_cred_r);
if (res != 0) {
printf("Error process ead2 (authz): %d\n", res);
return 1;
Expand Down
10 changes: 5 additions & 5 deletions lakers-c/src/ead_authz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ pub unsafe extern "C" fn authz_device_process_ead_2(
// input parans
device_c: *mut EadAuthzDevice,
ead_2_c: *mut EADItemC,
cred_v: CredentialRPK,
cred_v: *mut CredentialRPK,
) -> i8 {
let crypto = &mut default_crypto();
match (*device_c)
.wait_ead2
.process_ead_2(crypto, (*ead_2_c).to_rust(), cred_v.value.as_slice())
{
let device = &(*device_c);
let ead_2 = (*ead_2_c).to_rust();
let cred_v = (*cred_v).value.as_slice();
match device.wait_ead2.process_ead_2(crypto, ead_2, cred_v) {
Ok(device) => {
(*device_c).done = device;
0
Expand Down
7 changes: 5 additions & 2 deletions lakers-python/src/initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl PyEdhocInitiator {
py: Python<'a>,
cred_transfer: CredentialTransfer,
ead_3: Option<EADItem>,
) -> PyResult<(&'a PyBytes, [u8; SHA256_DIGEST_LEN])> {
) -> PyResult<(&'a PyBytes, &'a PyBytes)> {
match i_prepare_message_3(
&mut self.processed_m2,
&mut default_crypto(),
Expand All @@ -121,7 +121,10 @@ impl PyEdhocInitiator {
) {
Ok((state, message_3, prk_out)) => {
self.completed = state;
Ok((PyBytes::new(py, message_3.as_slice()), prk_out))
Ok((
PyBytes::new(py, message_3.as_slice()),
PyBytes::new(py, prk_out.as_slice()),
))
}
Err(error) => Err(error.into()),
}
Expand Down
8 changes: 6 additions & 2 deletions lakers-python/src/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,18 @@ impl PyEdhocResponder {
}
}

pub fn verify_message_3(&mut self, valid_cred_i: Vec<u8>) -> PyResult<[u8; SHA256_DIGEST_LEN]> {
pub fn verify_message_3<'a>(
&mut self,
py: Python<'a>,
valid_cred_i: Vec<u8>,
) -> PyResult<&'a PyBytes> {
let valid_cred_i = CredentialRPK::new(
EdhocMessageBuffer::new_from_slice(&valid_cred_i.as_slice()).unwrap(),
)?;
match r_verify_message_3(&mut self.processing_m3, &mut default_crypto(), valid_cred_i) {
Ok((state, prk_out)) => {
self.completed = state;
Ok(prk_out)
Ok(PyBytes::new(py, prk_out.as_slice()))
}
Err(error) => Err(error.into()),
}
Expand Down

0 comments on commit f2263e6

Please sign in to comment.