Skip to content

Commit

Permalink
Bump the actions group across 2 directories with 2 updates (#66)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alexis <alexis.challande@trailofbits.com>
  • Loading branch information
dependabot[bot] and DarkaMaul authored Nov 19, 2024
1 parent b22aebb commit bc2090d
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 98 deletions.
37 changes: 22 additions & 15 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ crate-type = ["cdylib"]

[dependencies]
tsp-asn1 = { path = "tsp-asn1" }
pyo3 = { version = "0.22.6", features = ["abi3"] }
asn1 = "0.18"
pyo3 = { version = "0.23.1", features = ["abi3"] }
asn1 = "0.19"
self_cell = "1"
hex = "0.4"
sha2 = "0.10.8"
rand = "0.8.5"
cryptography-x509 = { git = "https://github.com/pyca/cryptography.git", rev = "a63ca251a7aa8a5aac6153e0b69083cb05e1a6d0" }
cryptography-x509 = { git = "https://github.com/pyca/cryptography.git", rev = "4c72f368234e60a06e4a0beaf87be55940dd49c1" }
openssl = { version = "0.10.68", features = ["vendored"] }

[features]
Expand Down
96 changes: 44 additions & 52 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl TimeStampReq {
match self.raw.borrow_dependent().nonce {
Some(nonce) => {
let py_nonce = crate::util::big_asn1_uint_to_py(py, nonce)?;
Ok(Some(py_nonce.into_py(py)))
Ok(Some(py_nonce.into_pyobject(py)?.into_any().unbind()))
}
None => Ok(None),
}
Expand All @@ -47,7 +47,7 @@ impl TimeStampReq {
match &self.raw.borrow_dependent().req_policy {
Some(req_policy) => {
let py_oid = crate::util::oid_to_py_oid(py, &req_policy)?;
Ok(Some(py_oid.into_py(py)))
Ok(Some(py_oid.into_pyobject(py)?.into_any().unbind()))
}
None => Ok(None),
}
Expand All @@ -71,7 +71,7 @@ impl TimeStampReq {
.position(|window| window == message_imprint)
{
let slice = &full_bytes[offset..offset + message_imprint.len()];
let new_owner = pyo3::types::PyBytes::new_bound(py, slice);
let new_owner = pyo3::types::PyBytes::new(py, slice);
Ok(PyMessageImprint {
contents: OwnedMessageImprint::try_new(new_owner.as_unbound().clone_ref(py), |v| {
asn1::parse_single::<tsp_asn1::tsp::MessageImprint>(v.as_bytes(py))
Expand All @@ -91,7 +91,7 @@ impl TimeStampReq {
) -> PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
let result = asn1::write_single(&self.raw.borrow_dependent());
match result {
Ok(request_bytes) => Ok(pyo3::types::PyBytes::new_bound(py, &request_bytes)),
Ok(request_bytes) => Ok(pyo3::types::PyBytes::new(py, &request_bytes)),
Err(e) => Err(pyo3::exceptions::PyValueError::new_err(format!("{e}"))),
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ impl PyMessageImprint {
py: pyo3::Python<'p>,
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
let message = self.contents.borrow_dependent().hashed_message;
Ok(pyo3::types::PyBytes::new_bound(py, message))
Ok(pyo3::types::PyBytes::new(py, message))
}
}

Expand Down Expand Up @@ -183,14 +183,14 @@ impl TimeStampResp {
let opt_status_strings = &self.raw.borrow_dependent().status.status_string;
match opt_status_strings {
Some(status_strings) => {
let status_list = pyo3::types::PyList::empty_bound(py);
let status_list = pyo3::types::PyList::empty(py);
for status_string in status_strings.clone() {
let _ = status_list
.append(pyo3::types::PyString::new_bound(py, status_string.as_str()));
let _ =
status_list.append(pyo3::types::PyString::new(py, status_string.as_str()));
}
Ok(status_list)
}
None => Ok(pyo3::types::PyList::empty_bound(py)),
None => Ok(pyo3::types::PyList::empty(py)),
}
}

Expand Down Expand Up @@ -222,7 +222,7 @@ impl TimeStampResp {
.position(|window| window == tst_bytes)
{
let tst_slice = &full_bytes[offset..offset + tst_bytes.len()];
let new_owner = pyo3::types::PyBytes::new_bound(py, tst_slice);
let new_owner = pyo3::types::PyBytes::new(py, tst_slice);

let py_tstinfo = PyTSTInfo {
raw: OwnedTSTInfo::try_new(new_owner.as_unbound().clone_ref(py), |v| {
Expand Down Expand Up @@ -257,7 +257,7 @@ impl TimeStampResp {
.position(|window| window == signed_data_bytes)
{
let tst_slice = &full_bytes[offset..offset + signed_data_bytes.len()];
let new_owner = pyo3::types::PyBytes::new_bound(py, tst_slice);
let new_owner = pyo3::types::PyBytes::new(py, tst_slice);

let py_signed_data = SignedData {
raw: OwnedSignedData::try_new(new_owner.as_unbound().clone_ref(py), |v| {
Expand Down Expand Up @@ -286,7 +286,7 @@ impl TimeStampResp {
) -> PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
let result = asn1::write_single(&self.raw.borrow_dependent());
match result {
Ok(response_bytes) => Ok(pyo3::types::PyBytes::new_bound(py, &response_bytes)),
Ok(response_bytes) => Ok(pyo3::types::PyBytes::new(py, &response_bytes)),
Err(e) => Err(pyo3::exceptions::PyValueError::new_err(format!("{e}"))),
}
}
Expand All @@ -298,7 +298,7 @@ impl TimeStampResp {
) -> PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
let result = asn1::write_single(&self.raw.borrow_dependent().time_stamp_token);
match result {
Ok(request_bytes) => Ok(pyo3::types::PyBytes::new_bound(py, &request_bytes)),
Ok(request_bytes) => Ok(pyo3::types::PyBytes::new(py, &request_bytes)),
Err(e) => Err(pyo3::exceptions::PyValueError::new_err(format!("{e}"))),
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ impl SignedData {
&self,
py: pyo3::Python<'p>,
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::types::PySet>> {
let py_set = pyo3::types::PySet::empty_bound(py)?;
let py_set = pyo3::types::PySet::empty(py)?;
for algorithm in self.raw.borrow_dependent().digest_algorithms.clone() {
let py_oid = crate::util::oid_to_py_oid(py, algorithm.oid())?;
py_set.add(py_oid)?;
Expand All @@ -357,31 +357,28 @@ impl SignedData {
}

#[getter]
fn certificates<'p>(
&self,
py: pyo3::Python<'p>,
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::types::PySet>> {
let py_certs = pyo3::types::PySet::empty_bound(py)?;
fn certificates<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<pyo3::PyObject> {
let py_certs = pyo3::types::PySet::empty(py)?;
let certs = match self.raw.borrow_dependent().certificates.clone() {
Some(certs) => certs,
None => return Ok(py_certs),
None => return Ok(py_certs.into_any().unbind()),
};

for cert in certs {
match cert {
tsp_asn1::certificate::CertificateChoices::Certificate(cert) => {
let raw = asn1::write_single(&cert).unwrap().clone();
py_certs.add(pyo3::types::PyBytes::new_bound(py, &raw))?;
py_certs.add(pyo3::types::PyBytes::new(py, &raw))?;
}
_ => return Err(PyValueError::new_err("Unknown certificate type")),
}
}
Ok(py_certs)
Ok(py_certs.into_pyobject(py)?.into_any().unbind())
}

#[getter]
fn signer_infos<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<pyo3::PyObject> {
let py_set = pyo3::types::PySet::empty_bound(py)?;
let py_set = pyo3::types::PySet::empty(py)?;

let full_bytes = self.raw.borrow_owner().as_bytes(py);
for signer in self.raw.borrow_dependent().signer_infos.clone() {
Expand All @@ -394,19 +391,19 @@ impl SignedData {
.position(|window| window == signer_bytes)
{
let slice = &full_bytes[offset..offset + signer_bytes.len()];
let new_owner = pyo3::types::PyBytes::new_bound(py, slice);
let new_owner = pyo3::types::PyBytes::new(py, slice);

let py_signer_info = SignerInfo {
raw: OwnedSignerInfo::try_new(new_owner.as_unbound().clone_ref(py), |v| {
asn1::parse_single::<RawSignerInfo>(v.as_bytes(py))
})
.unwrap(),
};
py_set.add(py_signer_info.into_py(py))?;
py_set.add(py_signer_info.into_pyobject(py)?.unbind())?;
}
}

Ok(py_set.to_object(py))
Ok(py_set.into_pyobject(py)?.into_any().unbind())
}
}

Expand Down Expand Up @@ -500,7 +497,7 @@ impl PyTSTInfo {
match &self.raw.borrow_dependent().policy {
Some(req_policy) => {
let py_oid = crate::util::oid_to_py_oid(py, &req_policy)?;
Ok(Some(py_oid.into_py(py)))
Ok(Some(py_oid.into_pyobject(py)?.into_any().unbind()))
}
None => Ok(None),
}
Expand All @@ -519,7 +516,7 @@ impl PyTSTInfo {
.position(|window| window == message_imprint)
{
let slice = &full_bytes[offset..offset + message_imprint.len()];
let new_owner = pyo3::types::PyBytes::new_bound(py, slice);
let new_owner = pyo3::types::PyBytes::new(py, slice);
Ok(PyMessageImprint {
contents: OwnedMessageImprint::try_new(new_owner.as_unbound().clone_ref(py), |v| {
asn1::parse_single::<tsp_asn1::tsp::MessageImprint>(v.as_bytes(py))
Expand Down Expand Up @@ -567,7 +564,7 @@ impl PyTSTInfo {
match self.raw.borrow_dependent().nonce {
Some(nonce) => {
let py_nonce = crate::util::big_asn1_uint_to_py(py, nonce)?;
Ok(Some(py_nonce.into_py(py)))
Ok(Some(py_nonce.into_pyobject(py)?.into_any().unbind()))
}
None => Ok(None),
}
Expand All @@ -592,7 +589,7 @@ impl PyTSTInfo {
) -> PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
let result = asn1::write_single(&self.raw.borrow_dependent());
match result {
Ok(request_bytes) => Ok(pyo3::types::PyBytes::new_bound(py, &request_bytes)),
Ok(request_bytes) => Ok(pyo3::types::PyBytes::new(py, &request_bytes)),
Err(e) => Err(pyo3::exceptions::PyValueError::new_err(format!("{e}"))),
}
}
Expand Down Expand Up @@ -659,7 +656,7 @@ pub(crate) fn create_timestamp_request(

let request_bytes = asn1::write_single(&timestamp_request)
.map_err(|e| PyValueError::new_err(format!("Serialization error: {:?}", e)));
let py_bytes = pyo3::types::PyBytes::new_bound(py, &request_bytes.unwrap()).unbind();
let py_bytes = pyo3::types::PyBytes::new(py, &request_bytes.unwrap()).unbind();

let raw = OwnedTimeStampReq::try_new(py_bytes, |data| asn1::parse_single(data.as_bytes(py)))
.map_err(|e| {
Expand Down Expand Up @@ -740,31 +737,26 @@ fn pkcs7_verify(

/// A Python module implemented in Rust.
#[pyo3::pymodule]
mod rfc3161_client {
use super::*;
mod _rust {

#[pyo3::pymodule]
mod _rust {
#[pymodule_export]
use super::parse_timestamp_response;
#[pymodule_export]
use super::parse_timestamp_response;

#[pymodule_export]
use super::create_timestamp_request;
#[pymodule_export]
use super::create_timestamp_request;

#[pymodule_export]
use super::parse_timestamp_request;
#[pymodule_export]
use super::parse_timestamp_request;

#[pymodule_export]
use super::{
Accuracy, PyMessageImprint, PyTSTInfo, SignedData, SignerInfo, TimeStampReq,
TimeStampResp,
};
#[pymodule_export]
use super::{
Accuracy, PyMessageImprint, PyTSTInfo, SignedData, SignerInfo, TimeStampReq, TimeStampResp,
};

#[pyo3::pymodule]
mod verify {
#[pymodule_export]
use super::super::pkcs7_verify;
}
#[pyo3::pymodule]
mod verify {
#[pymodule_export]
use super::super::pkcs7_verify;
}
}

Expand All @@ -781,7 +773,7 @@ mod tests {
let data = hex::decode("308202ec3003020100308202e306092a864886f70d010702a08202d4308202d0020103310d300b06096086480165030402013081d9060b2a864886f70d0109100104a081c90481c63081c302010106092b0601040183bf30023051300d0609608648016503040203050004409b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec04302143e2f3211f06695a6fb447d11dadf37b2228e8ca1180f32303234313030323039323135355a3003020101a034a4323030310e300c060355040a13056c6f63616c311e301c0603550403131554657374205453412054696d657374616d70696e67a000318201dc308201d802010130483030310e300c060355040a13056c6f63616c311e301c06035504031315546573742054534120496e7465726d656469617465021461ab8956727edad25ee3c2cd663d5ddd719071a0300b0609608648016503040201a0820126301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3234313030323039323135355a302f06092a864886f70d0109043122042089719cf333d5226a661aeab5807edcf53ba01f85323dc0415ee981f6c78d21953081b8060b2a864886f70d010910022f3181a83081a53081a230819f300d060960864801650304020305000440c04d4b48148c29c5cbab7919d432f6b1ae33995426613b4f759631108ff7d1e9c95537fac1acf43e2813754630c29abe6a0e3b804701ef3e04d3a17a4624c910304c3034a4323030310e300c060355040a13056c6f63616c311e301c06035504031315546573742054534120496e7465726d656469617465021461ab8956727edad25ee3c2cd663d5ddd719071a0300a06082a8648ce3d0403020446304402205333cdad93a03d3b22ebc3e84c560e9271fbedef0f97babf71c973a5ce4bd98e022001baf6b000e63eafac813c6e73bd46619bd2a6ebb161ca4e20b5c09a13e118c1")
.unwrap();

let py_bytes = pyo3::types::PyBytes::new_bound(py, &data);
let py_bytes = pyo3::types::PyBytes::new(py, &data);
let raw = OwnedTimeStampResp::try_new(py_bytes.into(), |v| {
asn1::parse_single::<RawTimeStampResp>(v.as_bytes(py))
})
Expand Down
Loading

0 comments on commit bc2090d

Please sign in to comment.