Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Add typing hints for most functions, which makes it easier to use IDEs for programming #117

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions smbclientng/core/CommandCompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
# Author : Podalirius (@podalirius_)
# Date created : 20 may 2024


from __future__ import annotations
import ntpath
import os
import shlex
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional
from smbclientng.core.SMBSession import SMBSession
from smbclientng.core.Config import Config
from smbclientng.core.Logger import Logger


class CommandCompleter(object):
Expand Down Expand Up @@ -342,8 +349,12 @@ class CommandCompleter(object):
"autocomplete": ["share"]
},
}

smbSession: SMBSession
config: Config
logger: Logger

def __init__(self, smbSession, config, logger):
def __init__(self, smbSession: SMBSession, config: Config, logger: Logger):
# Objects
self.smbSession = smbSession
self.config = config
Expand All @@ -352,7 +363,7 @@ def __init__(self, smbSession, config, logger):
self.commands["help"]["subcommands"] = ["format"] + list(self.commands.keys())
self.commands["help"]["subcommands"].remove("help")

def complete(self, text, state):
def complete(self, text: str, state: int) -> str:
"""
Function to handle command completion in the LDAP console.

Expand Down Expand Up @@ -505,7 +516,7 @@ def complete(self, text, state):
except IndexError:
return None

def print_help(self, command=None):
def print_help(self, command: Optional[str] = None):
"""
Prints help information for a specific command or all commands if no command is specified.

Expand Down
6 changes: 4 additions & 2 deletions smbclientng/core/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class Config(object):
no_colors: Property to get or set the colored output preference.
"""

not_interactive = False
not_interactive: bool = False
startup_script = None
_debug: bool
_no_colors: bool

def __init__(self, debug=False, no_colors=None):
def __init__(self, debug: bool = False, no_colors=None):
self._debug = debug

if no_colors is not None:
Expand Down
41 changes: 21 additions & 20 deletions smbclientng/core/Credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,50 @@
# Author : Podalirius (@podalirius_)
# Date created : 22 June 2024


from __future__ import annotations
from smbclientng.core.utils import parse_lm_nt_hashes
import re
import binascii

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional

class Credentials(object):
"""
Documentation for class Credentials
"""

# Identity
domain = None
username = None
password = None
domain: Optional[str]
username: Optional[str]
password: Optional[str]
# Hashes
nt_hex = ""
nt_raw = ""
lm_hex = ""
lm_raw = ""
nt_hex: str
nt_raw: bytes
lm_hex: str
lm_raw: bytes
# Kerberos
use_kerberos = False
aesKey = None
kdcHost = None
use_kerberos: bool = False
aesKey: Optional[str]
kdcHost: Optional[str]

def __init__(self, domain, username, password, hashes=None, use_kerberos=False, aesKey=None, kdcHost=None):
def __init__(self, domain: str, username: str, password: str, hashes: Optional[str] = None, use_kerberos: bool = False, aesKey: Optional[str] = None, kdcHost: Optional[str] = None):
super(Credentials, self).__init__()
# Identity
self.domain = domain
self.username = username
self.password = password

# Hashes
self.nt_hex = ""
self.nt_raw = ""
self.lm_hex = ""
self.lm_raw = ""
self.set_hashes(hashes=hashes)

# Kerberos
self.use_kerberos = use_kerberos
self.kdcHost = kdcHost
self.aesKey = aesKey

def set_hashes(self, hashes):
def set_hashes(self, hashes: Optional[str]):
"""
Sets the LM and NT hashes for the credentials.
Expand All @@ -60,9 +61,9 @@ def set_hashes(self, hashes):
"""

self.nt_hex = ""
self.nt_raw = ""
self.nt_raw = b""
self.lm_hex = ""
self.lm_raw = ""
self.lm_raw = b""

lmhash, nthash = None, None
if hashes is not None:
Expand Down
Loading
Loading