mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
auth: add generate_master_key function
This commit is contained in:
parent
9925309492
commit
66e18eae79
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2352,6 +2352,7 @@ dependencies = [
|
|||||||
name = "meilisearch-auth"
|
name = "meilisearch-auth"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64",
|
||||||
"enum-iterator",
|
"enum-iterator",
|
||||||
"hmac",
|
"hmac",
|
||||||
"meilisearch-types",
|
"meilisearch-types",
|
||||||
|
@ -4,6 +4,7 @@ version = "1.0.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
base64 = "0.13.1"
|
||||||
enum-iterator = "1.1.3"
|
enum-iterator = "1.1.3"
|
||||||
hmac = "0.12.1"
|
hmac = "0.12.1"
|
||||||
meilisearch-types = { path = "../meilisearch-types" }
|
meilisearch-types = { path = "../meilisearch-types" }
|
||||||
|
@ -268,3 +268,19 @@ fn generate_default_keys(store: &HeedAuthStore) -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const MASTER_KEY_MIN_SIZE: usize = 16;
|
||||||
|
const MASTER_KEY_GEN_SIZE: usize = 32;
|
||||||
|
|
||||||
|
pub fn generate_master_key() -> String {
|
||||||
|
use rand::rngs::OsRng;
|
||||||
|
use rand::RngCore;
|
||||||
|
|
||||||
|
let mut csprng = OsRng;
|
||||||
|
let mut buf = vec![0; MASTER_KEY_GEN_SIZE];
|
||||||
|
csprng.fill_bytes(&mut buf);
|
||||||
|
|
||||||
|
// let's encode the random bytes to base64 to make them human-readable and not too long.
|
||||||
|
// We're using the URL_SAFE alphabet that will produce keys without =, / or other unusual characters.
|
||||||
|
base64::encode_config(buf, base64::URL_SAFE_NO_PAD)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user