Transaction: Meaningful method names
This commit is contained in:
parent
d67e134e26
commit
e398fbfe00
4 changed files with 16 additions and 12 deletions
|
@ -60,7 +60,7 @@ impl InteractionModel {
|
|||
let root = get_root_node_struct(rx_buf)?;
|
||||
let inv_req = InvReq::from_tlv(&root)?;
|
||||
|
||||
let timed_tx = trans.exch.get_expiry_ts().map(|_| true);
|
||||
let timed_tx = trans.get_timeout().map(|_| true);
|
||||
let timed_request = inv_req.timed_request.filter(|a| *a == true);
|
||||
// Either both should be None, or both should be Some(true)
|
||||
if timed_tx != timed_request {
|
||||
|
|
|
@ -78,11 +78,15 @@ impl<'a> Transaction<'a> {
|
|||
|
||||
pub fn set_timeout(&mut self, timeout: u64) {
|
||||
self.exch
|
||||
.set_expiry_ts(SystemTime::now().checked_add(Duration::from_millis(timeout)));
|
||||
.set_data_time(SystemTime::now().checked_add(Duration::from_millis(timeout)));
|
||||
}
|
||||
|
||||
pub fn get_timeout(&mut self) -> Option<SystemTime> {
|
||||
self.exch.get_data_time()
|
||||
}
|
||||
|
||||
pub fn has_timed_out(&self) -> bool {
|
||||
if let Some(timeout) = self.exch.get_expiry_ts() {
|
||||
if let Some(timeout) = self.exch.get_data_time() {
|
||||
if SystemTime::now() > timeout {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ impl Case {
|
|||
let mut case_session = ctx
|
||||
.exch_ctx
|
||||
.exch
|
||||
.take_exchange_data::<CaseSession>()
|
||||
.take_data_boxed::<CaseSession>()
|
||||
.ok_or(Error::InvalidState)?;
|
||||
if case_session.state != State::Sigma1Rx {
|
||||
return Err(Error::Invalid);
|
||||
|
@ -171,7 +171,7 @@ impl Case {
|
|||
SCStatusCodes::SessionEstablishmentSuccess,
|
||||
None,
|
||||
)?;
|
||||
ctx.exch_ctx.exch.clear_exchange_data();
|
||||
ctx.exch_ctx.exch.clear_data_boxed();
|
||||
ctx.exch_ctx.exch.close();
|
||||
|
||||
Ok(())
|
||||
|
@ -269,7 +269,7 @@ impl Case {
|
|||
tw.str16(TagType::Context(4), encrypted)?;
|
||||
tw.end_container()?;
|
||||
case_session.tt_hash.update(ctx.tx.as_borrow_slice())?;
|
||||
ctx.exch_ctx.exch.set_exchange_data(case_session);
|
||||
ctx.exch_ctx.exch.set_data_boxed(case_session);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -129,15 +129,15 @@ impl Exchange {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_exchange_data(&mut self, data: Box<dyn Any>) {
|
||||
pub fn set_data_boxed(&mut self, data: Box<dyn Any>) {
|
||||
self.data = DataOption::Boxed(data);
|
||||
}
|
||||
|
||||
pub fn clear_exchange_data(&mut self) {
|
||||
pub fn clear_data_boxed(&mut self) {
|
||||
self.data = DataOption::None;
|
||||
}
|
||||
|
||||
pub fn get_exchange_data<T: Any>(&mut self) -> Option<&mut T> {
|
||||
pub fn get_data_boxed<T: Any>(&mut self) -> Option<&mut T> {
|
||||
if let DataOption::Boxed(a) = &mut self.data {
|
||||
a.downcast_mut::<T>()
|
||||
} else {
|
||||
|
@ -145,7 +145,7 @@ impl Exchange {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn take_exchange_data<T: Any>(&mut self) -> Option<Box<T>> {
|
||||
pub fn take_data_boxed<T: Any>(&mut self) -> Option<Box<T>> {
|
||||
let old = std::mem::replace(&mut self.data, DataOption::None);
|
||||
match old {
|
||||
DataOption::Boxed(d) => d.downcast::<T>().ok(),
|
||||
|
@ -156,13 +156,13 @@ impl Exchange {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_expiry_ts(&mut self, expiry_ts: Option<SystemTime>) {
|
||||
pub fn set_data_time(&mut self, expiry_ts: Option<SystemTime>) {
|
||||
if let Some(t) = expiry_ts {
|
||||
self.data = DataOption::Time(t);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_expiry_ts(&self) -> Option<SystemTime> {
|
||||
pub fn get_data_time(&self) -> Option<SystemTime> {
|
||||
match self.data {
|
||||
DataOption::Time(t) => Some(t),
|
||||
_ => None,
|
||||
|
|
Loading…
Add table
Reference in a new issue