Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: reviewing patch
✓ CI success Fintan Halpenny committed 8 months ago
commit 9b1627faee800898a4a28c22dc276902809de745
parent 8fcabd244dc2f70790d0d279a273f41d0853f746
3 passed (3 total) View logs
1 file changed +21 -16
modified crates/radicle-crypto/src/ssh/keystore.rs
@@ -43,10 +43,12 @@ pub struct Keystore {
}

impl Keystore {
-
    /// Create a new keystore pointing to the given path. Use [`Keystore::init`] to initialize.
+
    /// Create a new keystore pointing to the given path.
+
    ///
+
    /// Use [`Keystore::init`] to initialize.
    pub fn new<P: AsRef<Path>>(path: P) -> Self {
-
        pub const DEFAULT_SECRET_KEY_FILE_NAME: &str = "radicle";
-
        pub const DEFAULT_PUBLIC_KEY_FILE_NAME: &str = "radicle.pub";
+
        const DEFAULT_SECRET_KEY_FILE_NAME: &str = "radicle";
+
        const DEFAULT_PUBLIC_KEY_FILE_NAME: &str = "radicle.pub";

        let keys = path.as_ref().to_path_buf();

@@ -56,8 +58,10 @@ impl Keystore {
        }
    }

-
    /// Create a new keystore pointing to the given paths. Use [`Keystore::init`] to initialize.
-
    pub fn new_secret<P: AsRef<Path>>(secret: &P) -> Self {
+
    /// Create a new keystore pointing to the given paths.
+
    ///
+
    /// Use [`Keystore::init`] to initialize.
+
    pub fn from_secret_path<P: AsRef<Path>>(secret: &P) -> Self {
        Self {
            path_secret: secret.as_ref().to_path_buf(),
            path_public: None,
@@ -74,12 +78,12 @@ impl Keystore {
        self.path_public.as_deref()
    }

-
    /// Initialize a keystore by generating a key pair and storing the secret and public key
-
    /// at the given path.
+
    /// Initialize a keystore by generating a key pair and storing the secret
+
    /// and public key at the given path.
    ///
-
    /// The `comment` is associated with the private key.
-
    /// The `passphrase` is used to encrypt the private key.
-
    /// The `seed` is used to derive the private key and should almost always be generated.
+
    /// The `comment` is associated with the private key. The `passphrase` is
+
    /// used to encrypt the private key. The `seed` is used to derive the
+
    /// private key and should almost always be generated.
    ///
    /// If `passphrase` is `None`, the key is not encrypted.
    pub fn init(
@@ -165,14 +169,15 @@ impl Keystore {
        }

        let public = ssh_key::PublicKey::read_openssh_file(path_public)?;
-
        match public.try_into() {
-
            Ok(public) => Ok(Some(public)),
-
            _ => Err(Error::InvalidKeyType),
-
        }
+
        PublicKey::try_from(public)
+
            .map(Some)
+
            .map_err(|_| Error::InvalidKeyType)
    }

    /// Load the public key from the store. Attempts to compute it from the
-
    /// private key if no public key is set up. Returns `None` if it wasn't found.
+
    /// private key if no public key is set up.
+
    ///
+
    /// Returns `None` if it wasn't found.
    pub fn public_key_derived(
        &self,
        passphrase: Option<&Passphrase>,
@@ -185,7 +190,7 @@ impl Keystore {
            return Ok(None);
        };

-
        Ok(Some(crate::PublicKey(secret_key.public_key())))
+
        Ok(Some(PublicKey(secret_key.public_key())))
    }

    /// Load the secret key from the store, decrypting it with the given passphrase.