Skip to content

Commit

Permalink
Replace openssl by crates num-bigint, sha2 (#317)
Browse files Browse the repository at this point in the history
* Replace openssl by crates 'num-bigint', 'sha2'

Signed-off-by: Patrik Stas <[email protected]>

* Update dependencies

Signed-off-by: Patrik Stas <[email protected]>

---------

Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas authored Aug 26, 2023
1 parent cfea9f7 commit 091529f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ serde_json = "1.0.40"
serde_derive = "1.0.97"
regex = "1.1.0"
base64 = "0.10"
openssl = { version = "0.10.48" }
sha2 = "0.10.7"
num-bigint = "0.4.3"
futures = { version = "0.3", default-features = false }
uuid = { version = "0.8", default-features = false, features = ["v4"] }
strum = "0.16.0"
Expand Down
21 changes: 7 additions & 14 deletions aries_vcx/src/utils/openssl.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
use openssl::bn::BigNum;
use openssl::sha::sha256;
use num_bigint::BigUint;
use sha2::{Digest, Sha256};

use crate::errors::error::prelude::*;

pub fn encode(s: &str) -> VcxResult<String> {
match s.parse::<u32>() {
Ok(val) => Ok(val.to_string()),
Err(_) => {
let hash = sha256(s.as_bytes());
let bignum = BigNum::from_slice(&hash).map_err(|err| {
AriesVcxError::from_msg(AriesVcxErrorKind::EncodeError, format!("Cannot encode string: {}", err))
})?;

let encoded = bignum
.to_dec_str()
.map_err(|err| {
AriesVcxError::from_msg(AriesVcxErrorKind::EncodeError, format!("Cannot encode string: {}", err))
})?
.to_string();

let mut hasher = Sha256::new();
hasher.update(s.as_bytes());
let hash = hasher.finalize();
let bignum = BigUint::from_bytes_be(&hash.as_slice());
let encoded = bignum.to_str_radix(10);
Ok(encoded)
}
}
Expand Down
13 changes: 0 additions & 13 deletions aries_vcx/src/utils/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::utils::qualifier;

use bs58;
use messages::msg_types::Role;
use openssl::bn::BigNum;

pub fn validate_did(did: &str) -> VcxResult<String> {
if qualifier::is_fully_qualified(did) {
Expand All @@ -24,18 +23,6 @@ pub fn validate_did(did: &str) -> VcxResult<String> {
}
}

pub fn validate_nonce(nonce: &str) -> VcxResult<String> {
let nonce =
BigNum::from_dec_str(nonce).map_err(|err| AriesVcxError::from_msg(AriesVcxErrorKind::InvalidNonce, err))?;
if nonce.num_bits() > 80 {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidNonce,
"Invalid Nonce length",
));
}
Ok(nonce.to_string())
}

pub fn validate_key_delegate(delegate: &str) -> VcxResult<String> {
//todo: find out what needs to be validated for key_delegate
let check_delegate = String::from(delegate);
Expand Down
Empty file added libvcx/src/utils/validation.rs
Empty file.

0 comments on commit 091529f

Please sign in to comment.