CredentialApi

Trait CredentialApi 

Source
pub trait CredentialApi {
    // Required methods
    fn set_secret(&self, secret: &[u8]) -> Result<()>;
    fn get_secret(&self) -> Result<Vec<u8>>;
    fn delete_credential(&self) -> Result<()>;
    fn get_credential(&self) -> Result<Option<Arc<Credential>>>;
    fn get_specifiers(&self) -> Option<(String, String)>;
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn set_password(&self, password: &str) -> Result<()> { ... }
    fn get_password(&self) -> Result<String> { ... }
    fn get_attributes(&self) -> Result<HashMap<String, String>> { ... }
    fn update_attributes(&self, _: &HashMap<&str, &str>) -> Result<()> { ... }
    fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result { ... }
}
Expand description

The API that credentials implement.

Required Methods§

Source

fn set_secret(&self, secret: &[u8]) -> Result<()>

Set the underlying credential’s protected data to be the given byte array.

  • If the password cannot be stored in a credential, return an Invalid error.
  • If the entry is a specifier, and there is no matching credential, create a matching credential and save the data in it.
  • If the entry is a specifier, and there is more than one matching credential, return an Ambiguous error.
  • If the entry is a wrapper, and the wrapped credential has been deleted, either recreate the wrapped credential and set its value or return a NoEntry error.
  • Otherwise, set the value of the single, matching credential.

Note: If an entry is both a specifier and a wrapper, it’s up to the store whether to recreate a deleted credential or to fail with a NoEntry error.

Source

fn get_secret(&self) -> Result<Vec<u8>>

Retrieve the protected data as a byte array from the underlying credential.

  • If the entry is a specifier, and there is no matching credential, return a NoEntry error.
  • If the entry is a specifier, and there is more than one matching credential, return an Ambiguous error.
  • If the entry is a wrapper, and the wrapped credential has been deleted, return a NoEntry error.
  • Otherwise, return the value of the single, matching credential.
Source

fn delete_credential(&self) -> Result<()>

Delete the underlying credential.

If the underlying credential doesn’t exist, return a NoEntry error.

If there is more than one matching credential, return an Ambiguous error.

Source

fn get_credential(&self) -> Result<Option<Arc<Credential>>>

Return a wrapper for the underlying credential.

If self is already a wrapper, return None.

If the underlying credential doesn’t exist, return a NoEntry error.

If there is more than one matching credential, return an Ambiguous error.

Source

fn get_specifiers(&self) -> Option<(String, String)>

Return the <service, user> pair for this credential, if any.

Source

fn as_any(&self) -> &dyn Any

Return the inner credential object cast to Any.

This call is used to expose the Debug trait for credentials.

Provided Methods§

Source

fn set_password(&self, password: &str) -> Result<()>

Set the entry’s protected data to be the given string.

This method has a default implementation in terms of set_secret, which see.

Source

fn get_password(&self) -> Result<String>

Retrieve the protected data as a UTF-8 string from the underlying credential.

This method has a default implementation in terms of get_secret, which see. If the data in the credential is not valid UTF-8, the default implementation returns a BadEncoding error containing the data.

Source

fn get_attributes(&self) -> Result<HashMap<String, String>>

Return any store-specific decorations on this entry’s credential.

The expected error and success cases are the same as with get_secret, which see.

For convenience, a default implementation of this method is provided which doesn’t return any attributes. Credential store implementations which support attributes should override this method.

Source

fn update_attributes(&self, _: &HashMap<&str, &str>) -> Result<()>

Update the secure store attributes on this entry’s credential.

If the user supplies any attributes that cannot be updated, return an appropriate Invalid error.

Other expected error and success cases are the same as with get_secret, which see.

For convenience, a default implementation of this method is provided which returns a NotSupportedByStore error.

Source

fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result

The Debug trait call for the object.

This is used to implement the Debug trait on this type; it allows generic code to provide debug printing as provided by the underlying concrete object.

We provide a (no-op) default implementation of this method.

Implementors§