@@ -20,44 +20,39 @@ pub fn checkout_license(duration: Duration) -> Result<(), EnterpriseCheckoutErro
2020 return Ok ( ( ) ) ;
2121 }
2222
23- if !is_server_initialized ( ) {
24- if !initialize_server ( ) && is_server_floating_license ( ) {
25- return Err ( EnterpriseCheckoutError ( server_last_error ( ) . to_string ( ) ) ) ;
26- }
23+ if !is_server_initialized ( ) && !initialize_server ( ) && is_server_floating_license ( ) {
24+ return Err ( EnterpriseCheckoutError ( server_last_error ( ) . to_string ( ) ) ) ;
2725 }
2826
2927 if is_server_floating_license ( ) {
3028 if !is_server_connected ( ) && !connect_server ( ) {
3129 return Err ( EnterpriseCheckoutError ( server_last_error ( ) . to_string ( ) ) ) ;
3230 }
3331
34- if !is_server_authenticated ( ) {
35- if !authenticate_server_with_method ( "Keychain" , false ) {
36- let Some ( username) = std:: env:: var ( "BN_ENTERPRISE_USERNAME" ) . ok ( ) else {
37- return Err ( EnterpriseCheckoutError ( "BN_ENTERPRISE_USERNAME not set when attempting to authenticate with credentials" . to_string ( ) ) ) ;
38- } ;
39- let Some ( password) = std:: env:: var ( "BN_ENTERPRISE_PASSWORD" ) . ok ( ) else {
40- return Err ( EnterpriseCheckoutError ( "BN_ENTERPRISE_PASSWORD not set when attempting to authenticate with credentials" . to_string ( ) ) ) ;
41- } ;
42- if !authenticate_server_with_credentials ( username, password, true ) {
43- let failed_message = "Could not checkout a license: Not authenticated. Try one of the following: \n \
44- - Log in and check out a license for an extended time\n \
45- - Set BN_ENTERPRISE_USERNAME and BN_ENTERPRISE_PASSWORD environment variables\n \
46- - Use binaryninja::enterprise::{authenticate_server_with_method OR authenticate_server_with_credentials} in your code";
47- return Err ( EnterpriseCheckoutError ( failed_message. to_string ( ) ) ) ;
48- }
32+ if !is_server_authenticated ( ) && !authenticate_server_with_method ( "Keychain" , false ) {
33+ let Some ( username) = std:: env:: var ( "BN_ENTERPRISE_USERNAME" ) . ok ( ) else {
34+ return Err ( EnterpriseCheckoutError ( "BN_ENTERPRISE_USERNAME not set when attempting to authenticate with credentials" . to_string ( ) ) ) ;
35+ } ;
36+ let Some ( password) = std:: env:: var ( "BN_ENTERPRISE_PASSWORD" ) . ok ( ) else {
37+ return Err ( EnterpriseCheckoutError ( "BN_ENTERPRISE_PASSWORD not set when attempting to authenticate with credentials" . to_string ( ) ) ) ;
38+ } ;
39+ if !authenticate_server_with_credentials ( username, password, true ) {
40+ let failed_message = "Could not checkout a license: Not authenticated. Try one of the following: \n \
41+ - Log in and check out a license for an extended time\n \
42+ - Set BN_ENTERPRISE_USERNAME and BN_ENTERPRISE_PASSWORD environment variables\n \
43+ - Use binaryninja::enterprise::{authenticate_server_with_method OR authenticate_server_with_credentials} in your code";
44+ return Err ( EnterpriseCheckoutError ( failed_message. to_string ( ) ) ) ;
4945 }
5046 }
5147 }
5248
53- if !is_server_license_still_activated ( )
54- || ( !is_server_floating_license ( ) && crate :: license_expiration_time ( ) < SystemTime :: now ( ) )
49+ if ( !is_server_license_still_activated ( )
50+ || ( !is_server_floating_license ( ) && crate :: license_expiration_time ( ) < SystemTime :: now ( ) ) )
51+ && !update_server_license ( duration)
5552 {
56- if !update_server_license ( duration) {
57- return Err ( EnterpriseCheckoutError (
58- "Failed to refresh expired license" . to_string ( ) ,
59- ) ) ;
60- }
53+ return Err ( EnterpriseCheckoutError (
54+ "Failed to refresh expired license" . to_string ( ) ,
55+ ) ) ;
6156 }
6257
6358 Ok ( ( ) )
0 commit comments