summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mod.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 0039298..8a80b23 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -8,6 +8,8 @@ pub use self::clipboard::set_text;
pub use self::prompt_input::*;
pub use self::tiktoken::cl100k_base_singleton;
+use sha2::{Digest, Sha256};
+
pub fn now() -> String {
let now = chrono::Local::now();
now.to_rfc3339_opts(chrono::SecondsFormat::Secs, false)
@@ -76,6 +78,13 @@ pub fn init_tokio_runtime() -> anyhow::Result<tokio::runtime::Runtime> {
.with_context(|| "Failed to init tokio")
}
+pub fn sha256sum(input: &str) -> String {
+ let mut hasher = Sha256::new();
+ hasher.update(input);
+ let result = hasher.finalize();
+ format!("{:x}", result)
+}
+
#[cfg(test)]
mod tests {
use super::*;