pub trait Store: Send + Sync + 'static {
// Required methods
fn fetch(
&self,
url: Url
) -> Pin<Box<dyn Future<Output = Result<Bytes, FetchError>> + Send>>;
fn new_nonce(
&self,
email: String
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send>>;
fn consume_nonce(
&self,
nonce: String,
email: String
) -> Pin<Box<dyn Future<Output = Result<bool, Box<dyn Error + Send + Sync>>> + Send>>;
}
Expand description
Trait that describes a backing store used by Client
for two purposes:
- to fetch JSON documents using HTTP GET with additional caching, and
- to generate and manage nonces (numbers used once) used in authentication.
The store is shared between threads by reference, and is itself responsible for synchronizing access from different threads.
Required Methods§
sourcefn fetch(
&self,
url: Url
) -> Pin<Box<dyn Future<Output = Result<Bytes, FetchError>> + Send>>
fn fetch( &self, url: Url ) -> Pin<Box<dyn Future<Output = Result<Bytes, FetchError>> + Send>>
Requests a document using HTTP GET, and perform caching.
Implementors should honor HTTP cache headers, with a sensibile minimum (and possibly
maximum) applied to the cache lifespan. See simple_fetch
for a default fallback
implementation that can be used on cache miss.
sourcefn new_nonce(
&self,
email: String
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send>>
fn new_nonce( &self, email: String ) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send>>
Generate a random nonce and store the pair nonce/email.
See generate_nonce
for a default implementation for generating the nonce, but using this
is not required. When using a custom implementation, the returned string should be in some
URL safe format to prevent unnecessary escaping.
Implementors should not apply any limits to the amount of active nonces; this is left to
the application using the Client
.
sourcefn consume_nonce(
&self,
nonce: String,
email: String
) -> Pin<Box<dyn Future<Output = Result<bool, Box<dyn Error + Send + Sync>>> + Send>>
fn consume_nonce( &self, nonce: String, email: String ) -> Pin<Box<dyn Future<Output = Result<bool, Box<dyn Error + Send + Sync>>> + Send>>
Check that a nonce/email pair exists and delete it if so.
This method should return Ok(true)
if a pair was found, Ok(false)
if not, and use Err
only to indicate problems with the store.