Struct iroh_p2p::Keychain

source ·
pub struct Keychain<S: Storage> { /* private fields */ }
Expand description

A keychain to manage your keys.

Implementations§

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))
    }

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"))
}

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"))
}

Returns how many keys are stored in this keychain.

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"))
}

Creates a new on disk keychain, with the root defaulting to .iroh.

Creates a new on disk keychain, located at the given path.

If the path does not exist it is created.

Examples found in repository?
src/keys.rs (line 117)
116
117
118
    pub async fn new(root: PathBuf) -> Result<Self> {
        Self::with_root(root).await
    }

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Wrap the input message T in a tonic::Request
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more