askar_crypto/backend/
mod.rs

1//! Supported key backends
2
3use crate::Error;
4use core::str::FromStr;
5
6/// Backend of the key
7#[derive(Debug, Clone, PartialEq, Eq, Default)]
8pub enum KeyBackend {
9    /// Software based keys
10    #[default]
11    Software,
12
13    /// Keys generated and store in the secure element of the device
14    SecureElement,
15}
16
17impl From<KeyBackend> for &str {
18    fn from(key_backend: KeyBackend) -> Self {
19        match key_backend {
20            KeyBackend::Software => "software",
21            KeyBackend::SecureElement => "secure_element",
22        }
23    }
24}
25
26impl FromStr for KeyBackend {
27    type Err = Error;
28
29    fn from_str(s: &str) -> Result<Self, Self::Err> {
30        match s {
31            "software" => Ok(Self::Software),
32            "secure_element" => Ok(Self::SecureElement),
33            _ => Err(err_msg!(Invalid, "Invalid key backend.")),
34        }
35    }
36}
37
38impl core::fmt::Display for KeyBackend {
39    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
40        write!(f, "{}", <KeyBackend as Into<&str>>::into(self.clone()))
41    }
42}