Skip to content

Commit

Permalink
Use Protocol V3 on python binding
Browse files Browse the repository at this point in the history
- Correct definition of `RealmUpdateRoles` for the introduced reply `user_revoked` in `3.1`.
  • Loading branch information
FirelightFlagboy committed Dec 7, 2022
1 parent ffa7afe commit de292da
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 109 deletions.
2 changes: 1 addition & 1 deletion oxidation/libparsec/crates/core/src/trustchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::HashMap;

use crate::{build_signature_path, TrustchainError, TrustchainResult};
use libparsec_crypto::VerifyKey;
use libparsec_protocol::authenticated_cmds::v2::user_get::Trustchain;
use libparsec_protocol::authenticated_cmds::v3::user_get::Trustchain;
use libparsec_types::{
CertificateSignerOwned, CertificateSignerRef, DateTime, DeviceCertificate, DeviceID,
RevokedUserCertificate, TimeProvider, UserCertificate, UserID, UserProfile,
Expand Down
2 changes: 1 addition & 1 deletion oxidation/libparsec/crates/core/tests/test_trustchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chrono::{TimeZone, Utc};
use rstest::rstest;

use libparsec_core::{TrustchainContext, TrustchainError};
use libparsec_protocol::authenticated_cmds::v2::user_get::Trustchain;
use libparsec_protocol::authenticated_cmds::v3::user_get::Trustchain;
use libparsec_types::{
CertificateSignerOwned, DateTime, DeviceCertificate, DeviceID, RevokedUserCertificate,
UserCertificate, UserProfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
{
"label": "RealmUpdateRoles",
"major_versions": [
1,
2,
3
],
"req": {
Expand Down Expand Up @@ -64,6 +62,90 @@
}
}
},
"bad_timestamp": {
"fields": {
"reason": {
"type": "NonRequiredOption<String>"
},
"ballpark_client_early_offset": {
"type": "Float"
},
"ballpark_client_late_offset": {
"type": "Float"
},
"backend_timestamp": {
"type": "DateTime"
},
"client_timestamp": {
"type": "DateTime"
}
}
}
}
},
{
"label": "RealmUpdateRoles",
"major_versions": [
1,
2
],
"req": {
"cmd": "realm_update_roles",
"fields": {
"role_certificate": {
"type": "Bytes"
},
"recipient_message": {
"type": "RequiredOption<Bytes>"
}
}
},
"reps": {
"ok": {},
"not_allowed": {
"fields": {
"reason": {
"type": "NonRequiredOption<String>"
}
}
},
"invalid_certification": {
"fields": {
"reason": {
"type": "NonRequiredOption<String>"
}
}
},
"invalid_data": {
"fields": {
"reason": {
"type": "NonRequiredOption<String>"
}
}
},
"already_granted": {},
"incompatible_profile": {
"fields": {
"reason": {
"type": "NonRequiredOption<String>"
}
}
},
"not_found": {
"fields": {
"reason": {
"type": "NonRequiredOption<String>"
}
}
},
"in_maintenance": {},
"require_greater_timestamp": {
"fields": {
"strictly_greater_than": {
"type": "DateTime"
}
}
},
"bad_timestamp": {
"fields": {
"reason": {
Expand Down
21 changes: 11 additions & 10 deletions oxidation/libparsec/crates/protocol/tests/test_realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,16 +611,17 @@ fn serde_realm_update_roles_req(#[case] raw_expected: (&[u8], authenticated_cmds
authenticated_cmds::realm_update_roles::Rep::InMaintenance
)
)]
#[case::user_revoked(
(
// Generated from Python implementation (Parsec v2.11.1+dev)
// Content:
// status: "user_revoked"
//
&hex!("81a6737461747573ac757365725f7265766f6b6564")[..],
authenticated_cmds::realm_update_roles::Rep::UserRevoked
)
)]
// TODO: Test me on API-v3
// #[case::user_revoked(
// (
// // Generated from Python implementation (Parsec v2.11.1+dev)
// // Content:
// // status: "user_revoked"
// //
// &hex!("81a6737461747573ac757365725f7265766f6b6564")[..],
// authenticated_cmds::realm_update_roles::Rep::UserRevoked
// )
// )]
#[case::require_greater_timestamp(
(
// Generated from Python implementation (Parsec v2.11.1+dev)
Expand Down
8 changes: 4 additions & 4 deletions parsec/_parsec_pyi/protocol/realm.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class RealmCreateRepBadTimestamp(RealmCreateRep):
def __init__(
self,
reason: str | None,
ballpark_client_early_offset: float | None,
ballpark_client_late_offset: float | None,
backend_timestamp: DateTime | None,
client_timestamp: DateTime | None,
ballpark_client_early_offset: float,
ballpark_client_late_offset: float,
backend_timestamp: DateTime,
client_timestamp: DateTime,
) -> None: ...
@property
def reason(self) -> str | None: ...
Expand Down
2 changes: 1 addition & 1 deletion src/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pyo3::{
};

use libparsec::client_types;
use libparsec::protocol::authenticated_cmds::v2::{invite_delete, invite_new};
use libparsec::protocol::authenticated_cmds::v3::{invite_delete, invite_new};

#[pyclass]
#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
gen_rep,
},
};
use libparsec::protocol::authenticated_cmds::v2::{block_create, block_read};
use libparsec::protocol::authenticated_cmds::v3::{block_create, block_read};

#[pyclass]
#[derive(Clone)]
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use pyo3::{
};

use libparsec::protocol::{
anonymous_cmds::v2 as anonymous_cmds, authenticated_cmds::v2 as authenticated_cmds,
invited_cmds::v2 as invited_cmds,
anonymous_cmds::v3 as anonymous_cmds, authenticated_cmds::v3 as authenticated_cmds,
invited_cmds::v3 as invited_cmds,
};

use crate::protocol::*;
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
Reason,
},
};
use libparsec::protocol::authenticated_cmds::v2::{
use libparsec::protocol::authenticated_cmds::v3::{
events_listen::{self, APIEvent},
events_subscribe,
};
Expand Down
13 changes: 6 additions & 7 deletions src/protocol/invite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use pyo3::{
types::{PyBytes, PyType},
};

use libparsec::protocol::authenticated_cmds::v2::{
use libparsec::protocol::authenticated_cmds::v3::{
invite_1_greeter_wait_peer, invite_2a_greeter_get_hashed_nonce, invite_2b_greeter_send_nonce,
invite_3a_greeter_wait_peer_trust, invite_3b_greeter_signify_trust,
invite_4_greeter_communicate, invite_delete, invite_list, invite_new,
};
use libparsec::protocol::invited_cmds::v2::{
use libparsec::protocol::invited_cmds::v3::{
invite_1_claimer_wait_peer, invite_2a_claimer_send_hashed_nonce, invite_2b_claimer_send_nonce,
invite_3a_claimer_signify_trust, invite_3b_claimer_wait_peer_trust,
invite_4_claimer_communicate, invite_info,
Expand Down Expand Up @@ -232,7 +232,7 @@ impl InviteNewRepOk {
Self,
InviteNewRep(invite_new::Rep::Ok {
token,
email_sent: libparsec::types::Maybe::Present(email_sent.0),
email_sent: email_sent.0,
}),
))
}
Expand All @@ -248,10 +248,9 @@ impl InviteNewRepOk {
#[getter]
fn email_sent(_self: PyRef<'_, Self>) -> PyResult<InvitationEmailSentStatus> {
match &_self.as_ref().0 {
invite_new::Rep::Ok { email_sent, .. } => match email_sent {
libparsec::types::Maybe::Present(p) => Ok(InvitationEmailSentStatus(p.clone())),
libparsec::types::Maybe::Absent => Err(PyAttributeError::new_err("")),
},
invite_new::Rep::Ok { email_sent, .. } => {
Ok(InvitationEmailSentStatus(email_sent.clone()))
}
_ => Err(PyAttributeError::new_err("")),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pyo3::{
types::{PyBytes, PyTuple},
};

use libparsec::protocol::authenticated_cmds::v2::message_get;
use libparsec::protocol::authenticated_cmds::v3::message_get;

use crate::ids::DeviceID;
use crate::protocol::{
Expand Down
14 changes: 0 additions & 14 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ use pyo3::{types::PyModule, PyResult, Python};
pub(crate) type Reason = Option<String>;
pub(crate) type Bytes = Vec<u8>;
pub(crate) type ListOfBytes = Vec<Vec<u8>>;
pub(crate) type OptionalFloat = Option<f64>;
pub(crate) type OptionalDateTime = Option<crate::time::DateTime>;

macro_rules! rs_to_py {
($v: ident, Reason, $py: ident) => {
Expand All @@ -54,18 +52,6 @@ macro_rules! rs_to_py {
($v: ident, SequesterServiceID, $py: ident) => {
SequesterServiceID(*$v)
};
($v: ident, OptionalDateTime, $py: ident) => {
match *$v {
libparsec::types::Maybe::Present(v) => Some(DateTime(v)),
libparsec::types::Maybe::Absent => None,
}
};
($v: ident, OptionalFloat, $py: ident) => {
match *$v {
libparsec::types::Maybe::Present(v) => Some(v),
libparsec::types::Maybe::Absent => None,
}
};
($v: ident, $ty: ty, $py: ident) => {
*$v
};
Expand Down
26 changes: 9 additions & 17 deletions src/protocol/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pyo3::{
types::{PyBytes, PyTuple},
};

use libparsec::protocol::authenticated_cmds::v2::{organization_config, organization_stats};
use libparsec::protocol::authenticated_cmds::v3::{organization_config, organization_stats};

use crate::{
enumerate::UserProfile,
Expand Down Expand Up @@ -226,12 +226,8 @@ impl OrganizationConfigRepOk {
OrganizationConfigRep(organization_config::Rep::Ok {
user_profile_outsider_allowed,
active_users_limit,
sequester_authority_certificate: libparsec::types::Maybe::Present(
sequester_authority_certificate,
),
sequester_services_certificates: libparsec::types::Maybe::Present(
sequester_services_certificates,
),
sequester_authority_certificate,
sequester_services_certificates,
}),
))
}
Expand Down Expand Up @@ -266,10 +262,9 @@ impl OrganizationConfigRepOk {
organization_config::Rep::Ok {
sequester_authority_certificate,
..
} => match sequester_authority_certificate {
libparsec::types::Maybe::Present(x) => x.as_ref().map(|x| PyBytes::new(py, x)),
_ => None,
},
} => sequester_authority_certificate
.as_ref()
.map(|x| PyBytes::new(py, x)),
_ => return Err(PyNotImplementedError::new_err("")),
})
}
Expand All @@ -283,12 +278,9 @@ impl OrganizationConfigRepOk {
organization_config::Rep::Ok {
sequester_services_certificates,
..
} => match sequester_services_certificates {
libparsec::types::Maybe::Present(x) => x
.as_ref()
.map(|x| PyTuple::new(py, x.iter().map(|x| PyBytes::new(py, x)))),
_ => None,
},
} => sequester_services_certificates
.as_ref()
.map(|x| PyTuple::new(py, x.iter().map(|x| PyBytes::new(py, x)))),
_ => return Err(PyNotImplementedError::new_err("")),
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pyo3::{
};

use libparsec::protocol::{
authenticated_cmds::v2 as authenticated_cmds, invited_cmds::v2 as invited_cmds,
authenticated_cmds::v3 as authenticated_cmds, invited_cmds::v3 as invited_cmds,
};

use crate::protocol::{
Expand Down
7 changes: 2 additions & 5 deletions src/protocol/pki.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use libparsec::protocol::{
anonymous_cmds::v2::{pki_enrollment_info, pki_enrollment_submit},
authenticated_cmds::{
v2::pki_enrollment_accept,
v2::{pki_enrollment_list, pki_enrollment_reject},
},
anonymous_cmds::v3::{pki_enrollment_info, pki_enrollment_submit},
authenticated_cmds::v3::{pki_enrollment_accept, pki_enrollment_list, pki_enrollment_reject},
};
use pyo3::{
exceptions::PyAttributeError,
Expand Down
Loading

0 comments on commit de292da

Please sign in to comment.