|
2 | 2 | //! |
3 | 3 | //! More info [here](https://typesense.org/docs/0.20.0/api/api-keys.html). |
4 | 4 |
|
| 5 | +use base64::{engine::general_purpose::STANDARD as Base64Engine, Engine}; |
| 6 | +use core::fmt; |
5 | 7 | use hmac::{Hmac, Mac}; |
6 | 8 | use serde::{Deserialize, Serialize}; |
7 | 9 | use sha2::Sha256; |
@@ -96,12 +98,12 @@ where |
96 | 98 | let mut mac = Hmac::<Sha256>::new_from_slice(key.as_ref().as_bytes()).unwrap(); |
97 | 99 | mac.update(params.as_bytes()); |
98 | 100 | let result = mac.finalize(); |
99 | | - let digest = base64::encode(result.into_bytes()); |
| 101 | + let digest = Base64Engine.encode(result.into_bytes()); |
100 | 102 |
|
101 | 103 | let key_prefix = &key.as_ref()[0..4]; |
102 | 104 | let raw_scoped_key = format!("{}{}{}", digest, key_prefix, params); |
103 | 105 |
|
104 | | - Ok(base64::encode(raw_scoped_key.as_bytes())) |
| 106 | + Ok(Base64Engine.encode(raw_scoped_key.as_bytes())) |
105 | 107 | } |
106 | 108 | } |
107 | 109 |
|
@@ -138,16 +140,16 @@ pub enum Actions { |
138 | 140 | #[serde(rename = "*")] |
139 | 141 | All, |
140 | 142 | } |
141 | | -impl ToString for Actions { |
142 | | - fn to_string(&self) -> String { |
| 143 | +impl fmt::Display for Actions { |
| 144 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
143 | 145 | match self { |
144 | | - Self::DocumentsAll => "documents:*".to_string(), |
145 | | - Self::DocumentsSearch => "documents:search".to_string(), |
146 | | - Self::DocumentsGet => "documents:get".to_string(), |
147 | | - Self::CollectionsAll => "collections:*".to_string(), |
148 | | - Self::CollectionsDelete => "collections:delete".to_string(), |
149 | | - Self::CollectionsCreate => "collections:create".to_string(), |
150 | | - Self::All => "*".to_string(), |
| 146 | + Self::DocumentsAll => write!(f, "documents:*"), |
| 147 | + Self::DocumentsSearch => write!(f, "documents:search"), |
| 148 | + Self::DocumentsGet => write!(f, "documents:get"), |
| 149 | + Self::CollectionsAll => write!(f, "collections:*"), |
| 150 | + Self::CollectionsDelete => write!(f, "collections:delete"), |
| 151 | + Self::CollectionsCreate => write!(f, "collections:create"), |
| 152 | + Self::All => write!(f, "*"), |
151 | 153 | } |
152 | 154 | } |
153 | 155 | } |
|
0 commit comments