Page MenuHomePhabricator

D5999.id20026.diff
No OneTemporary

D5999.id20026.diff

diff --git a/native/native_rust_library/src/crypto_tools.rs b/native/native_rust_library/src/crypto_tools.rs
--- a/native/native_rust_library/src/crypto_tools.rs
+++ b/native/native_rust_library/src/crypto_tools.rs
@@ -1,5 +1,9 @@
use crate::ffi::DeviceType;
+use openssl::hash::MessageDigest;
+use openssl::pkey::PKey;
+use openssl::sign::Signer;
use rand::distributions::{Alphanumeric, DistString};
+
#[cfg(test)]
use regex::Regex;
@@ -33,6 +37,16 @@
Ok(format!("{}:{}", &prefix, &suffix))
}
+pub fn sign_string_with_private_key(
+ private_key: &PKey<openssl::pkey::Private>,
+ string_to_be_signed: &str,
+) -> anyhow::Result<String> {
+ let mut signer = Signer::new(MessageDigest::sha256(), &private_key)?;
+ signer.update(string_to_be_signed.as_bytes())?;
+ let signature = signer.sign_to_vec()?;
+ Ok(base64::encode(signature))
+}
+
#[cfg(test)]
mod tests {
use super::*;

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 7:47 PM (1 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2688894
Default Alt Text
D5999.id20026.diff (901 B)

Event Timeline