@@ -19,10 +19,9 @@ use parsec_interface::operations::{
1919use parsec_interface:: requests:: { Opcode , ProviderId , ResponseStatus , Result } ;
2020use std:: collections:: { HashMap , HashSet } ;
2121use std:: io:: { Error , ErrorKind } ;
22- use std:: str :: FromStr ;
22+ use std:: num :: ParseIntError ;
2323use std:: sync:: Arc ;
2424use uuid:: Uuid ;
25- use version:: { version, Version } ;
2625
2726const 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