Skip to content

Commit

Permalink
Merge pull request #8 from andrewwhitehead/cleanups
Browse files Browse the repository at this point in the history
indy-utils cleanups: remove unused features
  • Loading branch information
andrewwhitehead authored Apr 29, 2021
2 parents dea3d95 + 2be0b1a commit 856c634
Show file tree
Hide file tree
Showing 29 changed files with 217 additions and 967 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ members = [
"indy-credx",
"indy-data-types",
"indy-test-utils",
"indy-utils"
"indy-utils",
"indy-wql"
]

[profile.release]
lto = true
codegen-units = 1
12 changes: 4 additions & 8 deletions indy-credx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "indy-credx"
version = "0.2.3"
version = "0.3.0"
authors = ["Hyperledger Indy Contributors <indy@lists.hyperledger.org>"]
description = "Verifiable credential issuance and presentation for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org)."
edition = "2018"
Expand Down Expand Up @@ -30,22 +30,18 @@ rand = "0.7"
regex = "1.2.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.9"
tempfile = "3.1.0"
thiserror = "1.0.9"
zeroize = { version = "1.1", optional = true }

[dependencies.indy-data-types]
version = "0.4"
version = "0.5"
path = "../indy-data-types"
features = ["cl_native"]

[dependencies.indy-utils]
version = "0.3"
version = "0.4"
path = "../indy-utils"
default-features = false
features = ["wql"]

[dependencies.ursa]
version = "0.3.5"
default-features = false
features = ["cl_native", "log", "serde"]
2 changes: 1 addition & 1 deletion indy-credx/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error::Error as StdError;
use std::fmt::{self, Display, Formatter};
use std::result::Result as StdResult;

use ursa::errors::{UrsaCryptoError, UrsaCryptoErrorKind};
use crate::ursa::errors::{UrsaCryptoError, UrsaCryptoErrorKind};

pub type Result<T> = std::result::Result<T, Error>;

Expand Down
19 changes: 9 additions & 10 deletions indy-credx/src/services/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
use ursa::{
bn::BigNumber,
cl::{
issuer, verifier, CredentialSchema, CredentialValues as CryptoCredentialValues,
MasterSecret as CryptoMasterSecret, NonCredentialSchema, SubProofRequest,
},
};

use crate::error::Result;
use std::collections::{HashMap, HashSet};

use indy_data_types::anoncreds::{
credential::AttributeValues,
Expand All @@ -15,7 +7,14 @@ use indy_data_types::anoncreds::{
};
use indy_utils::hash::SHA256;

use std::collections::{HashMap, HashSet};
use crate::error::Result;
use crate::ursa::{
bn::BigNumber,
cl::{
issuer, verifier, CredentialSchema, CredentialValues as CryptoCredentialValues,
MasterSecret as CryptoMasterSecret, NonCredentialSchema, SubProofRequest,
},
};

pub fn attr_common_view(attr: &str) -> String {
attr.replace(" ", "").to_lowercase()
Expand Down
12 changes: 6 additions & 6 deletions indy-credx/src/services/tails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::io::{Read, Seek, SeekFrom, Write};
use std::path::PathBuf;

use indy_utils::base58;
use sha2::{Digest, Sha256};
use tempfile;

use crate::error::Result;
use crate::ursa::{
cl::{RevocationTailsAccessor, RevocationTailsGenerator, Tail},
errors::{UrsaCryptoError, UrsaCryptoErrorKind},
hash::{sha2::Sha256, Digest},
};

const TAILS_BLOB_TAG_SZ: u8 = 2;
Expand Down Expand Up @@ -110,10 +110,10 @@ impl TailsReaderImpl for TailsFileReader {
loop {
let sz = file.read(&mut buf)?;
if sz == 0 {
self.hash = Some(hasher.result().to_vec());
self.hash = Some(hasher.finalize().to_vec());
return Ok(self.hash.as_ref().unwrap().clone());
}
hasher.input(&buf[0..sz]);
hasher.update(&buf[0..sz]);
}
}

Expand Down Expand Up @@ -155,14 +155,14 @@ impl TailsWriter for TailsFileWriter {
let mut hasher = Sha256::default();
let version = &[0u8, 2u8];
file.write(version)?;
hasher.input(version);
hasher.update(version);
while let Some(tail) = generator.try_next()? {
let tail_bytes = tail.to_bytes()?;
file.write(tail_bytes.as_slice())?;
hasher.input(tail_bytes);
hasher.update(tail_bytes);
}
let tails_size = &file.seek(SeekFrom::Current(0))?;
let hash = base58::encode(hasher.result());
let hash = base58::encode(hasher.finalize());
let path = tempf.path().with_file_name(hash.clone());
let _outf = match tempf.persist_noclobber(&path) {
Ok(f) => f,
Expand Down
17 changes: 9 additions & 8 deletions indy-data-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "indy-data-types"
version = "0.4.2"
version = "0.5.0"
authors = ["Hyperledger Indy Contributors <indy@lists.hyperledger.org>"]
description = "Common data types for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org)."
edition = "2018"
Expand All @@ -17,24 +17,25 @@ crate-type = ["rlib"]

[features]
default = ["merkle_tree", "serde_support"]
cl = ["indy-utils/cl", "serde_support"]
cl_native = ["indy-utils/cl_native", "serde_support"]
hash = ["indy-utils/hash"]
merkle_tree = ["hash"]
cl = ["serde_support", "ursa", "ursa/cl", "ursa/serde"]
cl_native = ["serde_support", "ursa", "ursa/cl_native", "ursa/serde"]
merkle_tree = ["indy-utils/hash", "hex"]
rich_schema = []
serde_support = ["indy-utils/serde_support", "serde", "serde_json"]
serde_support = ["serde", "serde_json"]
vendored = ["openssl", "openssl/vendored"]

[dependencies]
hex = { version = "0.4", optional = true }
openssl = { version = "0.10", optional = true }
once_cell = "1.4"
regex = "1.3"
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true, features = ["raw_value"] }
zeroize = "1.1"
ursa = { version = "0.3.5", default-features = false, optional = true }
zeroize = { version = "1.1", features = ["zeroize_derive"] }

[dependencies.indy-utils]
version = "0.3"
version = "0.4"
path = "../indy-utils"
default-features = false
features = ["wql"]
Expand Down
9 changes: 4 additions & 5 deletions indy-data-types/src/anoncreds/cred_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ pub struct CredentialDefinitionV1 {

#[cfg(any(feature = "cl", feature = "cl_native"))]
impl CredentialDefinitionV1 {
pub fn get_public_key(
&self,
) -> Result<crate::ursa::cl::CredentialPublicKey, crate::ConversionError> {
pub fn get_public_key(&self) -> Result<crate::ursa::cl::CredentialPublicKey, ConversionError> {
let key = crate::ursa::cl::CredentialPublicKey::build_from_parts(
&self.value.primary,
self.value.revocation.as_ref(),
)?;
)
.map_err(|e| e.to_string())?;
Ok(key)
}
}
Expand Down Expand Up @@ -123,7 +122,7 @@ impl CredentialKeyCorrectnessProof {
#[cfg(any(feature = "cl", feature = "cl_native"))]
{
Ok(Self {
value: self.value.try_clone()?,
value: self.value.try_clone().map_err(|e| e.to_string())?,
})
}
#[cfg(not(any(feature = "cl", feature = "cl_native")))]
Expand Down
7 changes: 5 additions & 2 deletions indy-data-types/src/anoncreds/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ impl Credential {
cred_def_id: self.cred_def_id.clone(),
rev_reg_id: self.rev_reg_id.clone(),
values: self.values.clone(),
signature: self.signature.try_clone()?,
signature_correctness_proof: self.signature_correctness_proof.try_clone()?,
signature: self.signature.try_clone().map_err(|e| e.to_string())?,
signature_correctness_proof: self
.signature_correctness_proof
.try_clone()
.map_err(|e| e.to_string())?,
rev_reg: self.rev_reg.clone(),
witness: self.witness.clone(),
})
Expand Down
2 changes: 1 addition & 1 deletion indy-data-types/src/anoncreds/master_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl MasterSecret {

pub fn try_clone(&self) -> Result<Self, ConversionError> {
Ok(Self {
value: self.value.try_clone()?,
value: self.value.try_clone().map_err(|e| e.to_string())?,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions indy-data-types/src/anoncreds/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Nonce {
#[cfg(any(feature = "cl", feature = "cl_native"))]
#[inline]
pub fn from_native(native: UrsaNonce) -> Result<Self, ConversionError> {
let strval = native.to_dec()?;
let strval = native.to_dec().map_err(|e| e.to_string())?;
Ok(Self { strval, native })
}

Expand Down Expand Up @@ -55,7 +55,7 @@ impl Nonce {
}
#[cfg(any(feature = "cl", feature = "cl_native"))]
{
let native = UrsaNonce::from_dec(&strval)?;
let native = UrsaNonce::from_dec(&strval).map_err(|e| e.to_string())?;
Ok(Self { strval, native })
}
#[cfg(not(any(feature = "cl", feature = "cl_native")))]
Expand Down
6 changes: 2 additions & 4 deletions indy-data-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ mod macros;

mod utils {
pub use indy_utils::base58;
#[cfg(feature = "hash")]
pub use indy_utils::hash;
pub use indy_utils::{qualifiable, Qualifiable};
}

pub use indy_utils::did;
pub use indy_utils::keys;
pub use indy_utils::{invalid, ConversionError, Validatable, ValidationError};

#[cfg(any(feature = "cl", feature = "cl_native", feature = "hash"))]
pub use indy_utils::ursa;
#[cfg(any(feature = "cl", feature = "cl_native"))]
pub use ursa;

/// Type definitions related Indy credential issuance and verification
pub mod anoncreds;
Expand Down
6 changes: 3 additions & 3 deletions indy-data-types/src/merkle_tree/merkletree.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::utils::hash::{
use indy_utils::hash::{
TreeHash,
SHA256::{digest_empty, DigestType as Hash},
};
use crate::ValidationError;

use super::proof::{Lemma, Proof};
use super::tree::{LeavesIntoIterator, LeavesIterator, Tree, TreeLeafData};
use crate::ValidationError;

/// A Merkle tree is a binary tree, with values of type `T` at the leafs,
/// and where every internal node holds the hash of the concatenation of the hashes of its children nodes.
Expand Down Expand Up @@ -102,7 +102,7 @@ impl MerkleTree {

/// Returns the hex root hash of Merkle tree
pub fn root_hash_hex(&self) -> String {
indy_utils::hex::encode(self.root.hash())
hex::encode(self.root.hash())
}

/// Returns the height of Merkle tree
Expand Down
12 changes: 7 additions & 5 deletions indy-data-types/src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
mod merkletree;
mod proof;
mod tree;
use indy_utils::hash::{TreeHash, SHA256::DigestType as Hash};

pub use self::merkletree::MerkleTree;
use self::tree::{Tree, TreeLeafData};
use crate::utils::hash::{TreeHash, SHA256::DigestType as Hash};
use crate::ValidationError;

mod merkletree;
pub use self::merkletree::MerkleTree;

mod proof;
mod tree;

impl MerkleTree {
fn count_bits(v: usize) -> usize {
let mut ret = 0;
Expand Down
4 changes: 2 additions & 2 deletions indy-data-types/src/merkle_tree/proof.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::hash::{TreeHash, SHA256::DigestType as Hash};
use crate::ValidationError;
use indy_utils::hash::{TreeHash, SHA256::DigestType as Hash};

use super::tree::{Tree, TreeLeafData};
use crate::ValidationError;

/// An inclusion proof represent the fact that a `value` is a member
/// of a `MerkleTree` with root hash `root_hash`.
Expand Down
3 changes: 2 additions & 1 deletion indy-data-types/src/merkle_tree/tree.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cmp;

use crate::utils::hash::{TreeHash, SHA256::DigestType as Hash};
use indy_utils::hash::{TreeHash, SHA256::DigestType as Hash};

use crate::ValidationError;

pub type TreeLeafData = Vec<u8>;
Expand Down
25 changes: 9 additions & 16 deletions indy-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "indy-utils"
version = "0.3.9"
version = "0.4.0"
authors = ["Hyperledger Indy Contributors <indy@lists.hyperledger.org>"]
description = "Utilities for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org)."
edition = "2018"
Expand All @@ -16,34 +16,27 @@ path = "src/lib.rs"
crate-type = ["rlib"]

[features]
default = ["ed25519", "hash", "pack", "txn_signature", "wql"]
default = ["ed25519", "hash", "txn_signature", "wql"]
base64 = ["base64_rs"]
cl = ["ursa", "ursa/cl"]
cl_native = ["ursa", "ursa/cl_native"]
ed25519 = ["ursa", "ursa/ed25519", "ursa/x25519"]
hash = ["ursa", "ursa/sha2"]
pack = ["base64", "chacha20poly1305", "crypto_box", "ed25519", "serde_support", "ursa", "ursa/blake2"]
serde_support = ["serde", "serde_json", "ursa/serde"]
txn_signature = ["hash", "serde_support"]
wql = []
hash = ["sha2"]
txn_signature = ["hex", "sha2", "serde", "serde_json"]
wql = ["indy-wql", "serde", "serde_json"]

[dependencies]
aead = "0.3"
base64_rs = { package = "base64", version = "0.12", optional = true }
bs58 = "0.3"
chacha20 = "0.6"
chacha20poly1305 = { version = "0.7", default-features = false, features = ["alloc", "chacha20"], optional = true }
crypto_box = { version = "0.2", optional = true }
hex = "0.4"
hex = { version = "0.4", optional = true }
indy-wql = { version = "0.4", optional = true, path = "../indy-wql" }
once_cell = "1.4"
rand = "0.7"
regex = "1.3"
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
tempfile = { version = "3.1", optional = true }
sha2 = { version = "0.9", optional = true }
thiserror = "1.0"
ursa = { version = "0.3.5", default-features = false, optional = true }
zeroize = { version = "1.1", features = ["zeroize_derive"] }
zeroize = { version = "1.1" }

[dev-dependencies]
async-global-executor = "1.2"
Expand Down
2 changes: 1 addition & 1 deletion indy-utils/src/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Validatable for ShortDidValue {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "ed25519"))]
mod tests {
use super::*;
use crate::keys::EncodedVerKey;
Expand Down
Loading

0 comments on commit 856c634

Please sign in to comment.