summaryrefslogtreecommitdiff
path: root/ext/node/ops/crypto/dh.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/ops/crypto/dh.rs')
-rw-r--r--ext/node/ops/crypto/dh.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/node/ops/crypto/dh.rs b/ext/node/ops/crypto/dh.rs
index f60f84277..ff2bd030e 100644
--- a/ext/node/ops/crypto/dh.rs
+++ b/ext/node/ops/crypto/dh.rs
@@ -5,14 +5,21 @@ use num_bigint_dig::BigUint;
use num_bigint_dig::RandBigInt;
use num_traits::FromPrimitive;
+#[derive(Clone)]
pub struct PublicKey(BigUint);
impl PublicKey {
+ pub fn from_bytes(bytes: &[u8]) -> Self {
+ let public_key = BigUint::from_bytes_be(bytes);
+ Self(public_key)
+ }
+
pub fn into_vec(self) -> Vec<u8> {
self.0.to_bytes_be()
}
}
+#[derive(Clone)]
pub struct PrivateKey(BigUint);
impl PrivateKey {
@@ -22,6 +29,11 @@ impl PrivateKey {
Self(exponent)
}
+ pub fn from_bytes(bytes: &[u8]) -> Self {
+ let exponent = BigUint::from_bytes_be(bytes);
+ Self(exponent)
+ }
+
/// Diffie-Hellman modular exponentiation.
/// s = g^x mod p
pub fn compute_public_key(