Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
session: return ReturnCode from reset() on failure
Browse files Browse the repository at this point in the history
Callers of reset() will care about a ReturnCode::NetError, since this is
what is actually typically returned on success. The HSM reboots
immediately when reset() is called, meaning it vanishes out from under
the connector which dutifully returns a NetError. However, don't try to
be clever here in the library and let callers deal with it.
  • Loading branch information
csssuf committed Apr 25, 2018
1 parent 4aedf90 commit b3d0519
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,19 @@ impl Session {
}
}

/// Reset the device to factory settings and reboot.
///
/// Note that since the device reboots when this function is called, this function is far more
/// likely to return a `ReturnCode::NetError` upon success, since it will vanish out from
/// underneath the connector. However, it is left to library consumers to decide whether or not
/// this is an acceptable result.
pub fn reset(self) -> Result<(), Error> {
let rc = ReturnCode::from(unsafe {
match ReturnCode::from(unsafe {
yubihsm_sys::yh_util_reset(self.this.load(Ordering::Relaxed))
});

if rc != ReturnCode::Success {
bail!("util_reset failed: {}", rc);
}) {
ReturnCode::Success => Ok(()),
rc => Err(rc.into()),
}

Ok(())
}

pub fn list_objects(&self) -> ListObjectsQuery {
Expand Down

0 comments on commit b3d0519

Please sign in to comment.