Skip to content

Commit

Permalink
Merge pull request #218 from geonnave/fix-authz-python-return-bytes
Browse files Browse the repository at this point in the history
Fix(python): authz server now returns bytes
  • Loading branch information
geonnave authored Feb 13, 2024
2 parents ff3beb1 + 3c1c0e9 commit 9b7c1ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lakers-python/src/ead_authz/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lakers::*;
use lakers_crypto::default_crypto;
use pyo3::prelude::*;
use pyo3::{prelude::*, types::PyBytes};

#[pyclass(name = "AuthzEnrollmentServer")]
pub struct PyAuthzEnrollmentServer {
Expand All @@ -24,13 +24,13 @@ impl PyAuthzEnrollmentServer {
}
}

fn handle_voucher_request(&self, vreq: Vec<u8>) -> PyResult<Vec<u8>> {
fn handle_voucher_request<'a>(&self, py: Python<'a>, vreq: Vec<u8>) -> PyResult<&'a PyBytes> {
let vreq = EdhocMessageBuffer::new_from_slice(vreq.as_slice()).unwrap();
match self
.server
.handle_voucher_request(&mut default_crypto(), &vreq)
{
Ok(voucher_response) => Ok(Vec::from(voucher_response.as_slice())),
Ok(voucher_response) => Ok(PyBytes::new(py, voucher_response.as_slice())),
Err(error) => Err(error.into()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion lakers-python/test/test_ead_authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_authenticator_and_server():
ead_1 = lakers.EADItem(1, True, EAD_1_VALUE)
loc_w, voucher_request = authenticator.process_ead_1(ead_1, MESSAGE_1_WITH_EAD)
voucher_response = enrollment_server.handle_voucher_request(voucher_request)
assert bytes(voucher_response) == VOUCHER_RESPONSE
assert type(voucher_response) == bytes

ead_2 = authenticator.prepare_ead_2(voucher_response)
assert ead_2.label() == 1
Expand Down

0 comments on commit 9b7c1ae

Please sign in to comment.