Skip to content

Commit

Permalink
[clean] Turn the code into a proper python library
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Apr 6, 2022
1 parent f9424c6 commit aa47a1f
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*egg
*egg-info
__pychache__
*pyc
*~
build/
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Dummy APDU Logger, Explained

This project aims at parsing all kind of APDU exchange files, and displaying
them in a understandable fashion.


## Install

From the top of the repo, given you have the right to install the package
(either root or in a `virtualenv`):

```
pip install .
```

## Usage

Once install, you should now have a `dale` command:

```
$ dale -h
usage: dale [-h] APDU_FILE
Explicit logging of a list of APDUs
positional arguments:
APDU_FILE The file containing the list of APDUs
optional arguments:
-h, --help show this help message and exit
```
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"protobuf>=3.19",
]
build-backend = "setuptools.build_meta"

[tool.mypy]
ignore_missing_imports = true
41 changes: 41 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[metadata]
name = dale
version = 0.0.1
author = Ledger
author_email = [email protected]
description = Dummy APDU Logger, Explained
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/LedgerHQ/dale
project_urls =
Bug Tracker = https://github.com/LedgerHQ/dale/issues
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.8

[options]
package_dir=
=src
packages = find:
include_package_data = True
python_requires = >=3.6
install_requires=
protobuf>=3.19

[options.packages.find]
where=src
exclude =
tests

[options.entry_points]
console_scripts =
dale = dale.logger:main

[options.extras_require]
tests=
pytest
checkers=
yapf
toml
flake8
mypy
Empty file added src/dale/__init__.py
Empty file.
File renamed without changes.
1 change: 1 addition & 0 deletions src/dale/exchange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .exchange import factory
7 changes: 4 additions & 3 deletions exchange.py → src/dale/exchange/exchange.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from base import Command, Response
from pb.exchange_pb2 import NewTransactionResponse
from dale.base import Command, Response

from .pb.exchange_pb2 import NewTransactionResponse


EXCHANGE_CLA = 0xE0
Expand Down Expand Up @@ -50,7 +51,7 @@ def raw_hex_str(name: str, field: bytes):
return f"{name}:\n\t{field!r}\n\t{field.hex()}"


def exchange_factory(data):
def factory(data):
assert data[0] == EXCHANGE_CLA
assert len(data) > 1
ins = data[1]
Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
12 changes: 8 additions & 4 deletions logger.py → src/dale/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from pathlib import Path
from typing import Tuple, Optional

from base import Response, APDUPair
from exchange import exchange_factory, ExchangeCommand, ExchangeResponse
from parser import DefaultAPDUParser
from dale.base import Response, APDUPair
from dale.exchange import factory as exchange_factory
from dale.parser import DefaultAPDUParser


def init_parser() -> ArgumentParser:
Expand All @@ -18,7 +18,7 @@ def init_parser() -> ArgumentParser:
return parser


if __name__ == '__main__':
def main():
logging.root.setLevel(logging.INFO)

parser = init_parser()
Expand All @@ -34,3 +34,7 @@ def init_parser() -> ArgumentParser:

for exchange in apdu_parser.conversation:
print(exchange)


if __name__ == '__main__':
main()
3 changes: 1 addition & 2 deletions parser.py → src/dale/parser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging

from abc import ABC, abstractmethod
from base import Command, Response, APDUPair
from types import TracebackType
from typing import Optional, Tuple, Type

from base import APDUPair, Command
from dale.base import APDUPair, Response, Command


class APDUParser(ABC):
Expand Down

0 comments on commit aa47a1f

Please sign in to comment.