Struct sn_api::SafeAuthenticator [−][src]
Implementations
impl SafeAuthenticator
[src]
pub fn new(
config_dir_path: Option<&Path>,
bootstrap_contacts: Option<HashSet<SocketAddr>>
) -> Self
[src]
config_dir_path: Option<&Path>,
bootstrap_contacts: Option<HashSet<SocketAddr>>
) -> Self
pub async fn create(&mut self, passphrase: &str, password: &str) -> Result<()>
[src]
Create Safe
Creates a new Safe on the Network. Returns an error if a Safe exists or if there was some problem during the creation process. If the Safe is successfully created it keeps the logged in session (discarding a previous session)
Note: This does not perform any strength checks on the strings used to create the Safe.
Example
use sn_api::SafeAuthenticator; let mut safe_auth = SafeAuthenticator::new(None); let my_secret = "mysecretstring"; let my_password = "mypassword"; let acc_created = safe_auth.create(sk, my_secret, my_password).await; match acc_created { Ok(()) => assert!(true), // This should pass Err(_) => assert!(false) }
Error Example
If a Safe with same passphrase already exists, the function will return an error:
use sn_api::{SafeAuthenticator, Error}; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing Safe's passphrase and password: let my_secret = "mysecretstring"; let my_password = "mypassword"; let acc_not_created = safe_auth.create(sk, my_secret, my_password).await; match acc_not_created { Ok(_) => assert!(false), // This should not pass Err(Error::AuthError(message)) => { assert!(message.contains("Failed to create a Safe")); } Err(_) => assert!(false), // This should not pass }
pub async fn unlock(&mut self, passphrase: &str, password: &str) -> Result<()>
[src]
Unlock
Unlock a Safe already created on the network using the Authenticator
daemon.
Example
use sn_api::SafeAuthenticator; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing Safe's passphrase and password: let my_secret = "mysecretstring"; let my_password = "mypassword"; let logged_in = safe_auth.unlock(my_secret, my_password).await; match logged_in { Ok(()) => assert!(true), // This should pass Err(_) => assert!(false) }
Error Example
If the Safe does not exist, the function will return an appropriate error:
use sn_api::{SafeAuthenticator, Error}; let mut safe_auth = SafeAuthenticator::new(None); let not_logged_in = safe_auth.unlock("non", "existant").await; match not_logged_in { Ok(()) => assert!(false), // This should not pass Err(Error::AuthError(message)) => { assert!(message.contains("Failed to log in")); } Err(_) => assert!(false), // This should not pass }
pub fn lock(&mut self) -> Result<()>
[src]
pub fn is_a_safe_unlocked(&self) -> bool
[src]
pub async fn decode_req(&self, req: &str) -> Result<SafeAuthReq>
[src]
pub async fn revoke_app(&self, _y: &str) -> Result<()>
[src]
pub async fn authorise_app(&self, req: &str) -> Result<String>
[src]
Decode requests and trigger application authorisation against the current client
pub async fn authenticate(&self, auth_req: AuthReq) -> Result<AuthGranted>
[src]
Authenticate an app request.
First, this function searches for an app info in the Safe.
If the app is found, then the AuthGranted
struct is returned based on that information.
If the app is not found in the Safe, then it will be authenticated.
Trait Implementations
impl Default for SafeAuthenticator
[src]
fn default() -> SafeAuthenticator
[src]
Auto Trait Implementations
impl !RefUnwindSafe for SafeAuthenticator
impl Send for SafeAuthenticator
impl Sync for SafeAuthenticator
impl Unpin for SafeAuthenticator
impl !UnwindSafe for SafeAuthenticator
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,