Commit graph

350 commits

Author SHA1 Message Date
Jussi Kukkonen
8ed4414946 Fix incorrect targetpath comparison on Windows
fnmatch() will do case-normalization if the OS expects it:
we do not want this as
* the path is more a URL than a file path
* results need to not change based on OS

Fix the result on Windows by using fnmatchcase()

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-04-21 12:27:16 +03:00
Jussi Kukkonen
7ecb67d83e api: make the zip() usage clearer
We manually enforce matching lengths but there's no harm in doing this
too.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-01-08 13:15:37 +02:00
Jussi Kukkonen
0785c78b33 Make linter happy after python upgrade
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-01-08 13:08:53 +02:00
Jussi Kukkonen
8513f46c2b Bump minimum Python version to 3.10
We could just stop testing with 3.9... but I think this will lead to
unintentionally breaking 3.9 anyway sooner or later.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-01-08 13:08:47 +02:00
Lukas Puehringer
f1afc98c95 lint: change base tuple order in SimpleEnvelope
Latest ruff complains about Generic[T] not being the last base class in
the bases tuple of Simple Envelope (generic-not-last-base-class
(PYI059)).

This commit applies the default fix by changing the order of the bases.
While this can change the MRO, there shouldn't be a change of behavior
given the used bases.

See https://docs.astral.sh/ruff/rules/generic-not-last-base-class/ for
details.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2025-09-16 09:10:50 +02:00
Jussi Kukkonen
88cc98420e lint fixes
Fixes for ruff 0.12
* Tweak some annotations
* Add __hash__() implementations to api classes: These really should be
  hashable
* My use of "super().__hash__()" is not very optimized but avoids some
  repetition

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-06-24 11:02:09 +03:00
Lukas Pühringer
500e8b9a8b
Merge pull request #2815 from lukpueh/port-sslib-hash
Port securesystemslib.hash module
2025-03-19 12:21:09 +01:00
Lukas Puehringer
75e83b36d0 docs: Remove reference to securesystemslib hash
Default hash sha256 is now defined locally.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2025-03-19 11:29:36 +01:00
Lukas Puehringer
535a18918b Refactor hash helpers
Consolidate interface of bytes hash and file hash helpers.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2025-03-19 10:07:58 +01:00
Jussi Kukkonen
f3eddc19ff lint: Accept ruff suggestions for cast()
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-03-18 18:20:11 +02:00
Lukas Puehringer
866409ffe9 Port securesystemslib.hash module
securesystemslib.hash is a small wrapper around hashlib, which serves
two main purposes:
* provide helper function to hash a file
* translate custom hash algorithm name "blake2b-256" to "blake2b" with
  (digest_size=32).

In preparation for the removal of securesystemslib.hash, this patch ports
above behavior to tuf and uses the builtin hashlib directly where
possible.

related secure-systems-lab/securesystemslib#943

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2025-03-18 16:39:46 +01:00
Dimitri Papadopoulos
4a28307270
Fix typos
Signed-off-by: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com>
2025-03-10 22:06:30 +01:00
pakagronglb
acd7ed08d1 Update Python shebangs to explicitly use python3
Signed-off-by: pakagronglb <pakagronglebel@gmail.com>
2025-02-19 19:44:21 +07:00
pakagronglb
94639360ec Enable FA (future annotations) linting ruleset
Signed-off-by: pakagronglb <pakagronglebel@gmail.com>
2025-02-19 19:44:05 +07:00
Jussi Kukkonen
1a1312e1af dsse: Improve type checking
mypy rightly complains our types do not match (this only happen if you
enable type checks for securesystemslib):
* I think the annotation is actually wrong: Envelope does not know the
  contained type at this point.
* Likely SimpleEnvelope should not be generic: it does not relly know
  what it contains

I decided not to break the API here and just made the type cast
explicit (even though we don't really know that the cast is correct):
this silences mypy but has no other consequences.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-01-31 13:47:45 +02:00
Jussi Kukkonen
bb62dded29 Add type check
mypy warns about this but we know that encode_canonical() cannot return
None if we don't set output_function argument.

ruff does not like assert so I added a "noqa" and a comment

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-01-30 18:20:39 +02:00
Jussi Kukkonen
5b2c041da0 lint: Fixes from new ruff
The noqa comment was added manually to avoid
  A005 Module `json` shadows a Python standard-library module

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-01-14 10:40:21 +02:00
Jussi Kukkonen
687d4557ad Revert "refactor to use dict union, instead of unpacking"
This reverts commit eb6d82f324.

The change itself was fine but since the code is otherwise compatible
with python 3.8, let's revert this to be compatible for one more
release.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-11-29 12:51:35 +02:00
Jussi Kukkonen
1d81a04707 Use __future.annotations module
This allows using some more nice annotations from 3.10
while still being compatible with even Python 3.8.

These are all annotation changes, should not modify any functionality.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-11-29 12:41:09 +02:00
NicholasTanz
eb6d82f324 refactor to use dict union, instead of unpacking
Signed-off-by: NicholasTanz <nicholastanzillo@gmail.com>
2024-11-03 23:30:09 -05:00
NicholasTanz
5c71f4f062 update python annotations
Signed-off-by: NicholasTanz <nicholastanzillo@gmail.com>
2024-11-03 23:21:23 -05:00
h4l0gen
e63ba54906
made variable public
Signed-off-by: h4l0gen <ks3913688@gmail.com>
2024-05-28 17:35:14 +05:30
h4l0gen
35a29bbf1d
fix url link
Signed-off-by: h4l0gen <ks3913688@gmail.com>
2024-05-21 17:09:14 +05:30
Jussi Kukkonen
716cde704b lint: Remove unneeded noqa flags
Re-raising a blind exception is now ok.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-07 11:11:08 +02:00
Jussi Kukkonen
80882dbe7d lint: Enable flake8-annotations
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
Jussi Kukkonen
7e52190bf0 lint: Enable flake8-pyi
"object" is slightly more informative than "Any" as annotation

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
Jussi Kukkonen
981788bca2 lint: Enable flake8-pie
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
Lukas Puehringer
3e549793e4 Remove SSlibSigner mention in docstring
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-03 11:18:27 +02:00
Jussi Kukkonen
38f309bbbf WIP: Update to new securesystemslib API
* API changes covered:
  * keys and interface modules removed
  * SSlibSigner removed
  * CryptoSigner added: this replaces the removed functionality
  * DSSE "signatures" container type changed
* Currently pins a securesystemslib main branch commit:
  this shoudl be reverted before merging, when securesystemslib
  has made a release
* tests/generated_data/generate_md.py was simplified
* Encrypted test keys in tests/repository_data/keystore were replaced
  with the unencrypted PEM versions of the same keys
* The public test keys in tests/repository_data/keystore were removed
  as they were not used anymore

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-04-25 14:27:54 +03:00
E3E
52601e2bd8 add RUF and BLE rulesets; ignore some broad exceptions (BLE001) and RUF012
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-04-21 01:37:40 -04:00
Jussi Kukkonen
3605eaf2fb Metadata API: Stop using a deprecated method
persist_temp_file() is deprecated, and seemingly not very useful.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-04-12 22:41:12 +03:00
Lukas Pühringer
e1b52e7fd8
Merge pull request #2580 from theupdateframework/dependabot/pip/test-and-lint-dependencies-c17666fe2e
build(deps): bump the test-and-lint-dependencies group with 1 update
2024-03-12 09:40:40 +01:00
Jussi Kukkonen
27cc46f61d Metadata API: Refactor strptime call
This makes flake8-datetimez happier but has no effect on the result:

    DTZ007 The use of `datetime.datetime.strptime()` without %z must be
    followed by `.replace(tzinfo=)` or `.astimezone()

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-03-08 14:59:04 +02:00
Jussi Kukkonen
884cae9660 lint: Update formatting for ruff 3.x
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-03-07 10:05:36 +02:00
Jussi Kukkonen
de9633dab7 Metadata API: convenience tweak to expires setter
Practically were changing API if we start requiring that
expires is non-naive because this no longer works:

    metadata.signed.expires = datetime(3000,1,1)

We can make this work without API breaks though:
* it the input is naive, just use UTC
* if the input is not naive or UTC, raise

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-29 15:36:54 +02:00
Jussi Kukkonen
c2edd30669 Metadata API: Make sure Signed.expires is UTC
* Most importantly use strftime() to serialize the datetime
* Force the timezone as UTC when deserializing

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-29 15:34:36 +02:00
Nurgaleev_Mansur_908
53ac05d5d3 change utcnow() to now(timezone.utc)
Signed-off-by: Nurgaleev_Mansur_908 <mansur0158@gmail.com>
2024-02-27 21:57:46 +03:00
Lukas Puehringer
4005e766b4 Add LengthOrHashMismatchError back to metadata.
22b2726413 claims to add all names
that were moved to the internal _payload module back to metadata.

LengthOrHashMismatchError was not added back. Now it is.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-22 13:48:21 +01:00
Lukas Puehringer
8544bbd6f1 Envelope API: rename, add docs, add alias
* Rename Envelope to SimpleEnvelope:
  Envelope should be the generic term in this context for something that
  contains a payload and signatures. SimpleEnvelope is the specific
  DSSE implementation (just like Metadata is the specific traditional
  canonical JSON -based TUF envelope implementation).

* Add SimpleEnvelope class and method docstrings.

* Add convenience alias for ``self.signatures`` mapped to keyids for
  compatibility with Metadata.signatures.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:59:55 +01:00
Lukas Puehringer
b422afe0a4 Envelope API: add dsse equivalent for Metadata API
Add Envelope class with basic de/serialization methods, currently
hardcoded to JSON.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:34:53 +01:00
Lukas Puehringer
22b2726413 Metadata API: move inner classes to internal module
Allows to simultanously use those classes in different container /
signature wrapper APIs, e.g. Metadata API and Envelope API (DSSE).

All moved classes are imported into tuf.api.metadata scope for
backwards-compatibility.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:20:55 +01:00
Lukas Pühringer
76f39f52ef
Merge pull request #2558 from NicholasTanz/replaceLintingTools
Replace most linting tools with ruff
2024-02-21 15:59:03 +01:00
E3E
f156e21537 remove pylint and suppressed inline errors from pylint
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-20 22:57:53 -05:00
E3E
73842c97b8 reformat docstrings and supress small errors inline
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-20 15:19:33 -05:00
Jussi Kukkonen
3b65c2217b metadata API: Tweak exception message on sign failure
I still don't know how we should handle failures in signing
(maybe just let all of the weird exceptions raise instead of wrapping
them) but this makes the wrapping error at least a bit more useful.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-20 14:39:50 +02:00
E3E
206c9424f1 Add to linting Configuration:
- adpot changes in dependabot.yml and remove --diff from ruff check.
- select pydocstyle, isort, pyflakes, pep8-naming, pycodestyle for ruff and ignore some small issues / add inline comments.
- adjust docstring length to 80 in various files

Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-20 00:34:47 -05:00
Jussi Kukkonen
eb4834d920 Metadata API: Fix role lookup for succinct delegation
get_delegated_role() should not return a Role if the rolename is not
a delegated role. This is already true for "normal" DelegatedRole but
was not actually verified for SuccinctRoles.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-11 14:30:24 +02:00
Jussi Kukkonen
161c3e35ad Metadata API: Add VerificationResult.missing
This is helper to tell how many signatures are still required.
Also change the order of Roots given to RootVerificationResult
(this way first is version N, second is version N+1).

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 15:01:46 +02:00
Jussi Kukkonen
b158c0852d Metadata API: Make sanity checks in root verification
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 14:36:05 +02:00
Jussi Kukkonen
42d3a75787 Metadata API: Improve docs for RootVerificationResult
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 13:56:57 +02:00