Skip to content

Commit 838e93a

Browse files
Merge pull request #657 from ema/rm-version-crate
Remove dependency on crate "version"
2 parents da820b5 + 6e5cafe commit 838e93a

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ tss-esapi = { version = "7.1.0", optional = true }
3333
bincode = "1.3.1"
3434
structopt = "0.3.21"
3535
derivative = "2.2.0"
36-
version = "3.0.0"
3736
hex = { version = "0.4.2", optional = true }
3837
psa-crypto = { version = "0.9.2", default-features = false, features = ["operations"], optional = true }
3938
zeroize = { version = "1.2.0", features = ["zeroize_derive"] }

src/providers/core/mod.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ use parsec_interface::operations::{
1919
use parsec_interface::requests::{Opcode, ProviderId, ResponseStatus, Result};
2020
use std::collections::{HashMap, HashSet};
2121
use std::io::{Error, ErrorKind};
22-
use std::str::FromStr;
22+
use std::num::ParseIntError;
2323
use std::sync::Arc;
2424
use uuid::Uuid;
25-
use version::{version, Version};
2625

2726
const SUPPORTED_OPCODES: [Opcode; 5] = [
2827
Opcode::ListProviders,
@@ -263,13 +262,29 @@ impl ProviderBuilder {
263262
provider_info_vec.push(provider_info);
264263
}
265264

266-
let crate_version: Version = Version::from_str(version!()).map_err(|e| {
267-
format_error!("Error parsing the crate version", e);
265+
let crate_version: std::result::Result<Vec<u32>, ParseIntError> = env!("CARGO_PKG_VERSION")
266+
.split('.')
267+
.map(|v| v.parse())
268+
.collect();
269+
270+
let crate_version = crate_version.map_err(|e| {
271+
format_error!("Invalid CARGO_PKG_VERSION format", e);
268272
Error::new(
269273
ErrorKind::InvalidData,
270274
"crate version number has invalid format",
271275
)
272276
})?;
277+
278+
if crate_version.len() != 3 {
279+
return Err(Error::new(
280+
ErrorKind::InvalidData,
281+
format!(
282+
"Invalid CARGO_PKG_VERSION format: expected 3 components, got {}.",
283+
crate_version.len()
284+
),
285+
));
286+
}
287+
273288
provider_info_vec.push(ProviderInfo {
274289
// Assigned UUID for this provider: 47049873-2a43-4845-9d72-831eab668784
275290
uuid: Uuid::parse_str("47049873-2a43-4845-9d72-831eab668784").map_err(|_| Error::new(
@@ -278,9 +293,9 @@ impl ProviderBuilder {
278293
))?,
279294
description: String::from("Software provider that implements only administrative (i.e. no cryptographic) operations"),
280295
vendor: String::new(),
281-
version_maj: crate_version.major,
282-
version_min: crate_version.minor,
283-
version_rev: crate_version.patch,
296+
version_maj: crate_version[0],
297+
version_min: crate_version[1],
298+
version_rev: crate_version[2],
284299
id: ProviderId::Core,
285300
});
286301

@@ -326,4 +341,13 @@ mod tests {
326341
provider.wire_protocol_version_min
327342
);
328343
}
344+
345+
#[test]
346+
fn test_build() {
347+
let provider_builder = ProviderBuilder::new().with_wire_protocol_version(42, 12);
348+
assert!(
349+
provider_builder.build().is_ok(),
350+
"error building a CoreProvider"
351+
)
352+
}
329353
}

0 commit comments

Comments
 (0)