diff options
author | Alex Auvolat <alex@adnab.me> | 2023-06-14 17:13:41 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-06-14 17:19:25 +0200 |
commit | 8ef42c9609bcefc642cc9739acb921dffba49b89 (patch) | |
tree | 5d479c3ad3951d5d44cea5c2e033b506733c4f0f /src/model | |
parent | a83a092c032058728f191119de99f38844aa74f5 (diff) | |
download | garage-8ef42c9609bcefc642cc9739acb921dffba49b89.tar.gz garage-8ef42c9609bcefc642cc9739acb921dffba49b89.zip |
admin docs: reformatting, key admin: add check
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/key_table.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/model/key_table.rs b/src/model/key_table.rs index bb5334a3..a9762f1b 100644 --- a/src/model/key_table.rs +++ b/src/model/key_table.rs @@ -149,11 +149,19 @@ impl Key { } /// Import a key from it's parts - pub fn import(key_id: &str, secret_key: &str, name: &str) -> Self { - Self { + pub fn import(key_id: &str, secret_key: &str, name: &str) -> Result<Self, &'static str> { + if key_id.len() != 26 || &key_id[..2] != "GK" || hex::decode(&key_id[2..]).is_err() { + return Err("The specified key ID is not a valid Garage key ID (starts with `GK`, followed by 12 hex-encoded bytes)"); + } + + if secret_key.len() != 64 || hex::decode(&secret_key).is_err() { + return Err("The specified secret key is not a valid Garage secret key (composed of 32 hex-encoded bytes)"); + } + + Ok(Self { key_id: key_id.to_string(), state: crdt::Deletable::present(KeyParams::new(secret_key, name)), - } + }) } /// Create a new Key which can me merged to mark an existing key deleted |