Struct sn_api::SafeAuthenticator[][src]

pub struct SafeAuthenticator { /* fields omitted */ }

Implementations

impl SafeAuthenticator[src]

pub fn new(
    config_dir_path: Option<&Path>,
    bootstrap_contacts: Option<HashSet<SocketAddr>>
) -> Self
[src]

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]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,