pub struct Keychain<S: Storage> { /* private fields */ }Expand description
A keychain to manage your keys.
Implementations§
source§impl<S: Storage> Keychain<S>
impl<S: Storage> Keychain<S>
sourcepub fn from_storage(storage: S) -> Self
pub fn from_storage(storage: S) -> Self
Create a keychain based on the provided storage.
Examples found in repository?
src/keys.rs (line 104)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
fn default() -> Self {
let storage = MemoryStorage::default();
Self::from_storage(storage)
}
}
impl Keychain<MemoryStorage> {
pub fn new() -> Self {
Default::default()
}
}
impl Keychain<DiskStorage> {
/// Creates a new on disk keychain, with the root defaulting to `.iroh`.
pub async fn new(root: PathBuf) -> Result<Self> {
Self::with_root(root).await
}
/// Creates a new on disk keychain, located at the given path.
///
/// If the path does not exist it is created.
pub async fn with_root(root: PathBuf) -> Result<Self> {
let storage = DiskStorage::new(&root).await?;
Ok(Self::from_storage(storage))
}sourcepub async fn create_ed25519_key(&mut self) -> Result<()>
pub async fn create_ed25519_key(&mut self) -> Result<()>
Creates a new Ed25519 based key and stores it.
Examples found in repository?
src/node.rs (line 1061)
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
async fn load_identity<S: Storage>(kc: &mut Keychain<S>) -> Result<Keypair> {
if kc.is_empty().await? {
info!("no identity found, creating",);
kc.create_ed25519_key().await?;
}
// for now we just use the first key
let first_key = kc.keys().next().await;
if let Some(keypair) = first_key {
let keypair: Keypair = keypair?.into();
info!("identity loaded: {}", PeerId::from(keypair.public()));
return Ok(keypair);
}
Err(anyhow!("inconsistent keystate"))
}sourcepub fn keys(&self) -> impl Stream<Item = Result<Keypair>> + '_
pub fn keys(&self) -> impl Stream<Item = Result<Keypair>> + '_
Returns a stream of all keys stored.
Examples found in repository?
src/node.rs (line 1065)
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
async fn load_identity<S: Storage>(kc: &mut Keychain<S>) -> Result<Keypair> {
if kc.is_empty().await? {
info!("no identity found, creating",);
kc.create_ed25519_key().await?;
}
// for now we just use the first key
let first_key = kc.keys().next().await;
if let Some(keypair) = first_key {
let keypair: Keypair = keypair?.into();
info!("identity loaded: {}", PeerId::from(keypair.public()));
return Ok(keypair);
}
Err(anyhow!("inconsistent keystate"))
}sourcepub async fn is_empty(&self) -> Result<bool>
pub async fn is_empty(&self) -> Result<bool>
Returns true if there are no keys stored.
Examples found in repository?
src/node.rs (line 1059)
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
async fn load_identity<S: Storage>(kc: &mut Keychain<S>) -> Result<Keypair> {
if kc.is_empty().await? {
info!("no identity found, creating",);
kc.create_ed25519_key().await?;
}
// for now we just use the first key
let first_key = kc.keys().next().await;
if let Some(keypair) = first_key {
let keypair: Keypair = keypair?.into();
info!("identity loaded: {}", PeerId::from(keypair.public()));
return Ok(keypair);
}
Err(anyhow!("inconsistent keystate"))
}Trait Implementations§
Auto Trait Implementations§
impl<S> RefUnwindSafe for Keychain<S>where
S: RefUnwindSafe,
impl<S> Send for Keychain<S>where
S: Send,
impl<S> Sync for Keychain<S>where
S: Sync,
impl<S> Unpin for Keychain<S>where
S: Unpin,
impl<S> UnwindSafe for Keychain<S>where
S: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request