Skip to content

Commit

Permalink
Sort imports
Browse files Browse the repository at this point in the history
Imports are sorted using default ruff linter configuration.
  • Loading branch information
ekuler committed Jan 9, 2024
1 parent 0ac962e commit 2d1194d
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 51 deletions.
1 change: 0 additions & 1 deletion pykeepass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .pykeepass import PyKeePass, create_database

from .version import __version__

__all__ = ["PyKeePass", "create_database", "__version__"]
1 change: 1 addition & 0 deletions pykeepass/attachment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import entry
from .exceptions import BinaryError


class Attachment:
def __init__(self, element=None, kp=None, id=None, filename=None):
self._element = element
Expand Down
3 changes: 2 additions & 1 deletion pykeepass/baseelement.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import base64
import uuid
from datetime import datetime

from lxml import etree
from lxml.builder import E
from datetime import datetime


class BaseElement:
Expand Down
2 changes: 1 addition & 1 deletion pykeepass/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from lxml.etree import Element, _Element
from lxml.objectify import ObjectifiedElement

from .entry import Entry
from .baseelement import BaseElement
from .entry import Entry


class Group(BaseElement):
Expand Down
38 changes: 25 additions & 13 deletions pykeepass/kdbx_parsing/common.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
from Cryptodome.Cipher import AES, ChaCha20, Salsa20
from .twofish import Twofish
from Cryptodome.Util import Padding as CryptoPadding
import base64
import codecs
import hashlib
import logging
import re
import zlib
from binascii import Error as BinasciiError
from collections import OrderedDict
from copy import deepcopy
from io import BytesIO

from construct import (
Adapter, BitStruct, BitsSwapped, Container, Flag, Padding, ListContainer, Mapping, GreedyBytes, Int32ul, Switch
Adapter,
BitsSwapped,
BitStruct,
Container,
Flag,
GreedyBytes,
Int32ul,
ListContainer,
Mapping,
Padding,
Switch,
)
from Cryptodome.Cipher import AES, ChaCha20, Salsa20
from Cryptodome.Util import Padding as CryptoPadding
from lxml import etree
from copy import deepcopy
import base64
from binascii import Error as BinasciiError
import zlib
import re
import codecs
from io import BytesIO
from collections import OrderedDict
import logging

from .twofish import Twofish

log = logging.getLogger(__name__)

Expand Down
8 changes: 5 additions & 3 deletions pykeepass/kdbx_parsing/kdbx.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from construct import Struct, Switch, Bytes, Int16ul, RawCopy, Check, this
from .kdbx3 import DynamicHeader as DynamicHeader3
from construct import Bytes, Check, Int16ul, RawCopy, Struct, Switch, this

from .kdbx3 import Body as Body3
from .kdbx4 import DynamicHeader as DynamicHeader4
from .kdbx3 import DynamicHeader as DynamicHeader3
from .kdbx4 import Body as Body4
from .kdbx4 import DynamicHeader as DynamicHeader4


# verify file signature
def check_signature(ctx):
Expand Down
44 changes: 37 additions & 7 deletions pykeepass/kdbx_parsing/kdbx3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,48 @@
# keepass decrypt experimentation

import hashlib

from construct import (
Byte, Bytes, Int16ul, Int32ul, Int64ul, RepeatUntil, GreedyBytes, Struct,
this, Mapping, Switch, Prefixed, Padding, Checksum, Computed, IfThenElse,
Pointer, Tell, len_, If
Byte,
Bytes,
Checksum,
Computed,
GreedyBytes,
If,
IfThenElse,
Int16ul,
Int32ul,
Int64ul,
Mapping,
Padding,
Pointer,
Prefixed,
RepeatUntil,
Struct,
Switch,
Tell,
len_,
this,
)

from .common import (
aes_kdf, AES256Payload, ChaCha20Payload, TwoFishPayload, Concatenated,
DynamicDict, compute_key_composite, Decompressed, Reparsed,
compute_master, CompressionFlags, XML, CipherId, ProtectedStreamId, Unprotect
XML,
AES256Payload,
ChaCha20Payload,
CipherId,
CompressionFlags,
Concatenated,
Decompressed,
DynamicDict,
ProtectedStreamId,
Reparsed,
TwoFishPayload,
Unprotect,
aes_kdf,
compute_key_composite,
compute_master,
)


# -------------------- Key Derivation --------------------

# https://github.com/keepassxreboot/keepassxc/blob/8324d03f0a015e62b6182843b4478226a5197090/src/format/KeePass2.cpp#L24-L26
Expand Down
51 changes: 42 additions & 9 deletions pykeepass/kdbx_parsing/kdbx4.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
# Evan Widloski - 2018-04-11
# keepass decrypt experimentation

import struct
import hashlib
import argon2
import hmac
import struct

import argon2
from construct import (
Byte, Bytes, Int32ul, RepeatUntil, GreedyBytes, Struct, this, Mapping,
Switch, Flag, Prefixed, Int64ul, Int32sl, Int64sl, GreedyString, Padding,
Peek, Checksum, Computed, IfThenElse, Pointer, Tell, If
Byte,
Bytes,
Checksum,
Computed,
Flag,
GreedyBytes,
GreedyString,
If,
IfThenElse,
Int32sl,
Int32ul,
Int64sl,
Int64ul,
Mapping,
Padding,
Peek,
Pointer,
Prefixed,
RepeatUntil,
Struct,
Switch,
Tell,
this,
)

from .common import (
aes_kdf, Concatenated, AES256Payload, ChaCha20Payload, TwoFishPayload,
DynamicDict, compute_key_composite, Reparsed, Decompressed,
compute_master, CompressionFlags, XML, CipherId, ProtectedStreamId, Unprotect
XML,
AES256Payload,
ChaCha20Payload,
CipherId,
CompressionFlags,
Concatenated,
Decompressed,
DynamicDict,
ProtectedStreamId,
Reparsed,
TwoFishPayload,
Unprotect,
aes_kdf,
compute_key_composite,
compute_master,
)


# -------------------- Key Derivation --------------------

# https://github.com/keepassxreboot/keepassxc/blob/bc55974ff304794e53c925442784c50a2fdaf6ee/src/format/KeePass2.cpp#L30-L33
Expand Down
1 change: 1 addition & 0 deletions pykeepass/kdbx_parsing/pytwofish.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def get_key_size(self):

import struct


def rotr32(x, n):
return (x >> n) | ((x << (32 - n)) & 0xFFFFFFFF)

Expand Down
5 changes: 3 additions & 2 deletions pykeepass/kdbx_parsing/twofish.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

__all__ = ['Twofish']

from . import pytwofish
from Cryptodome.Util.strxor import strxor
from Cryptodome.Util.Padding import pad
from Cryptodome.Util.strxor import strxor

from . import pytwofish

MODE_ECB = 1
MODE_CBC = 2
Expand Down
33 changes: 23 additions & 10 deletions pykeepass/pykeepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import struct
import uuid
import zlib

from binascii import Error as BinasciiError
from construct import Container, ChecksumError, CheckError
from dateutil import parser, tz
from datetime import datetime, timedelta
from pathlib import Path

from construct import CheckError, ChecksumError, Container
from dateutil import parser, tz
from lxml import etree
from lxml.builder import E
from pathlib import Path

from .attachment import Attachment
from .entry import Entry
from .exceptions import BinaryError, CredentialsError, HeaderChecksumError, PayloadChecksumError, UnableToSendToRecycleBin
from .exceptions import (
BinaryError,
CredentialsError,
HeaderChecksumError,
PayloadChecksumError,
UnableToSendToRecycleBin,
)
from .group import Group
from .kdbx_parsing import KDBX, kdf_uuids
from .xpath import attachment_xp, entry_xp, group_xp, path_xp
Expand Down Expand Up @@ -411,8 +417,10 @@ def _can_be_moved_to_recyclebin(self, entry_or_group):
# ---------- Groups ----------

from .deprecated import (
find_groups_by_name, find_groups_by_path, find_groups_by_uuid,
find_groups_by_notes
find_groups_by_name,
find_groups_by_notes,
find_groups_by_path,
find_groups_by_uuid,
)

def find_groups(self, recursive=True, path=None, group=None, **kwargs):
Expand Down Expand Up @@ -496,9 +504,14 @@ def empty_group(self, group):


from .deprecated import (
find_entries_by_title, find_entries_by_username, find_entries_by_password,
find_entries_by_url, find_entries_by_path, find_entries_by_notes,
find_entries_by_string, find_entries_by_uuid
find_entries_by_notes,
find_entries_by_password,
find_entries_by_path,
find_entries_by_string,
find_entries_by_title,
find_entries_by_url,
find_entries_by_username,
find_entries_by_uuid,
)

def find_entries(self, recursive=True, path=None, group=None, **kwargs):
Expand Down
7 changes: 3 additions & 4 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import unittest
import uuid
from datetime import datetime, timedelta

from dateutil import tz
from io import BytesIO
from pathlib import Path

from io import BytesIO
from dateutil import tz

from pykeepass import PyKeePass, icons
from pykeepass.entry import Entry
from pykeepass.group import Group
from pykeepass.exceptions import BinaryError, CredentialsError, HeaderChecksumError
from pykeepass.group import Group

"""
Missing Tests:
Expand Down

0 comments on commit 2d1194d

Please sign in to comment.