Page MenuHomePhabricator

D5999.diff
No OneTemporary

D5999.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
Thu, Dec 19, 10:23 PM (21 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2676837
Default Alt Text
D5999.diff (873 B)

Event Timeline