Page MenuHomePhabricator

D5999.id20299.diff
No OneTemporary

D5999.id20299.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>,
+ nonce: &str,
+) -> anyhow::Result<String> {
+ let mut signer = Signer::new(MessageDigest::sha256(), &private_key)?;
+ signer.update(nonce.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
Fri, Dec 20, 12:36 AM (20 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2676837
Default Alt Text
D5999.id20299.diff (873 B)

Event Timeline