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

added module for unix compatibility #1

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions src/passwordlib/unix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding=utf-8 -*-
r"""
Compatibility for the widely used unix formats
"""
from . import encrypt
from . import loading
14 changes: 14 additions & 0 deletions src/passwordlib/unix/encrypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding=utf-8 -*-
r"""

"""


__all__ = ['encrypt_sha1']


def encrypt_sha1(password: str):
from hashlib import sha1
from base64 import b64encode
hashed = sha1(password.encode()).digest()
return "{SHA1}" + b64encode(hashed).decode()
17 changes: 17 additions & 0 deletions src/passwordlib/unix/loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding=utf-8 -*-
r"""

"""
from ..core import LoadedTuple


__all__ = ['load_sha1']


def load_sha1(dump: str) -> LoadedTuple:
from base64 import b64decode
if not dump.startswith("{SHA}"):
raise ValueError("Invalid dump format")
b64encoded = dump[6:]
hashed = b64decode(b64encoded)
return LoadedTuple(algorithm="sha1", iterations=-1, salt=b'', hashed=hashed)