diff options
| author | Glenn Smith <glenn@vector35.com> | 2021-12-06 18:01:10 -0500 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2021-12-06 18:18:24 -0500 |
| commit | 5904e6ec629c7bc2fc824c98fad126bd5d7d9341 (patch) | |
| tree | bb215f0bedbcc83de2f0be7208116794b9561c70 /python/enterprise.py | |
| parent | 810e54963af76ed5d5e5c5e79cd747550d48296d (diff) | |
PEP8 + cleanups for enterprise.py
Diffstat (limited to 'python/enterprise.py')
| -rw-r--r-- | python/enterprise.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/python/enterprise.py b/python/enterprise.py index 8eadb06c..7e6ebb18 100644 --- a/python/enterprise.py +++ b/python/enterprise.py @@ -16,6 +16,7 @@ def connect(): if not core.BNConnectEnterpriseServer(): raise RuntimeError(last_error()) + def is_connected() -> bool: """ Determine if the Enterprise Server is currently connected. @@ -23,6 +24,7 @@ def is_connected() -> bool: """ return core.BNIsEnterpriseServerConnected() + def authenticate_with_credentials(username: str, password: str): """ Authenticate to the Enterprise Server with username/password credentials. @@ -32,6 +34,7 @@ def authenticate_with_credentials(username: str, password: str): if not core.BNAuthenticateEnterpriseServerWithCredentials(username, password): raise RuntimeError(last_error()) + def authenticate_with_method(method: str): """ Authenticate to the Enterprise Server with a non-password method. Note that many of these will @@ -42,6 +45,7 @@ def authenticate_with_method(method: str): if not core.BNAuthenticateEnterpriseServerWithMethod(method): raise RuntimeError(last_error()) + def authentication_methods() -> List[Tuple[str, str]]: """ Get a list of authentication methods accepted by the Enterprise Server. @@ -57,6 +61,7 @@ def authentication_methods() -> List[Tuple[str, str]]: core.BNFreeStringList(names, count) return results + def deauthenticate(): """ Deauthenticate from the Enterprise server, clearing any cached credentials. @@ -64,6 +69,7 @@ def deauthenticate(): if not core.BNDeauthenticateEnterpriseServer(): raise RuntimeError(last_error()) + def cancel_authentication(): """ Cancel a call to :func:`authenticate_with_credentials` or :func:`authenticate_with_method`. @@ -71,6 +77,7 @@ def cancel_authentication(): """ core.BNCancelEnterpriseServerAuthentication() + def is_authenticated() -> bool: """ Determine if you have authenticated to the Enterprise Server. @@ -78,6 +85,7 @@ def is_authenticated() -> bool: """ return core.BNIsEnterpriseServerAuthenticated() + def username() -> Optional[None]: """ Get the username of the currently authenticated user to the Enterprise Server. @@ -85,6 +93,7 @@ def username() -> Optional[None]: """ return core.BNGetEnterpriseServerUsername() + def reservation_time_limit() -> int: """ Get the maximum checkout duration allowed by the Enterprise Server. @@ -94,6 +103,7 @@ def reservation_time_limit() -> int: """ return core.BNGetEnterpriseServerReservationTimeLimit() + def acquire_license(duration, cache=False): """ Check out and activate a license from the Enterprise Server. @@ -114,6 +124,7 @@ def acquire_license(duration, cache=False): if not core.BNAcquireEnterpriseServerLicense(duration, cache): raise RuntimeError(last_error()) + def release_license(): """ Release the currently checked out license back to the Enterprise Server. @@ -126,6 +137,7 @@ def release_license(): if not core.BNReleaseEnterpriseServerLicense(): raise RuntimeError(last_error()) + def license_expiration_time() -> int: """ Get the expiry time of the current license checkout. @@ -133,6 +145,7 @@ def license_expiration_time() -> int: """ return core.BNGetEnterpriseServerLicenseExpirationTime() + def license_duration() -> int: """ Get the duration of the current license checkout. @@ -140,6 +153,7 @@ def license_duration() -> int: """ return core.BNGetEnterpriseServerLicenseDuration() + def is_license_still_activated() -> bool: """ Determine if your current license checkout is still valid. @@ -147,6 +161,7 @@ def is_license_still_activated() -> bool: """ return core.BNIsEnterpriseServerLicenseStillActivated() + def last_error() -> str: """ Get a text representation the last error encountered by the Enterprise Client @@ -154,6 +169,7 @@ def last_error() -> str: """ return core.BNGetEnterpriseServerLastError() + class LicenseCheckout: """ Helper class for scripts to make use of a license checkout in a scope. @@ -163,7 +179,8 @@ class LicenseCheckout: enterprise.authenticate_with_credentials("username", "password") with enterprise.LicenseCheckout(): # Do some operation - bv = open_view("/bin/ls") # e.g + with open_view("/bin/ls") as bv: # e.g. + print(hex(bv.start)) # License is released at end of scope """ @@ -179,7 +196,9 @@ class LicenseCheckout: if not is_connected(): connect() if not is_authenticated(): - raise RuntimeError("Could not checkout a license: Not authenticated. Please use binaryninja.enterprise.authenticate_with_credentials or authenticate_with_method first!") + raise RuntimeError( + "Could not checkout a license: Not authenticated. " + "Please use binaryninja.enterprise.authenticate_with_credentials or authenticate_with_method first!") acquire_license(self.desired_duration, self.desired_cache) def __exit__(self, exc_type, exc_val, exc_tb): |
