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

July 14 changes #4

Conversation

ethan-lowman-dd
Copy link
Collaborator

for _, pattern := range d.Paths {
if matched, _ := filepath.Match(pattern, file); matched {
return true
return true, nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I wanted to avoid with the struct that enforces oneof Paths, PathHashPrefixes.

I'm more comfortable with the second approach ethan-lowman-dd@8eac49a
We are bubbling complexity:

  • a user can create an invalid DelegatedRole with the struct
  • we have to add error handling everywhere for no real error (can be checked at encoding and decoding)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the type system can fully enforce all validation (which it can't for more complex kinds of validation), I don't see a way to avoid storing invalid data in a struct. In my opinion, matching the type definition directly to the spec is much easier to understand (for library authors and users alike), and validating before use and when marshalling/unmarshalling provides the necessary properties, matching the spec as close as possible.

Using a boolean flag (MatchWithHashPrefixes) and field with two possible meanings (PathMatchers) to implement the "one of" constraint forces users to understand quirks of the library's implementation, rather than following the spec.

Additionally, the boolean field is not extensible. If the TUF spec introduces a third field that is also subject to the "one of" constraint, the boolean flag would no longer properly implement the constraint across the three fields.

@raphaelgavache raphaelgavache merged commit ea6bcf8 into raphaelgavache:raphael/support_delegations_client Jul 15, 2021
raphaelgavache pushed a commit that referenced this pull request Jul 16, 2021
* Clarify validation of signing role & metadata type

* Add/update comments

* Validation happens on both decode & encode

* Bubble up an error if MatchesPath is called on an invalid DelegatedRole

* Match spec for delegation traversal

* Comment in the iterator

* Add diamond test case

* Revert "Match spec for delegation traversal"

This reverts commit 15fee6b.

* Rename IsTopLevelRole back to ValidRole to avoid breaking change
raphaelgavache added a commit that referenced this pull request Sep 2, 2021
* Add delegation client

* Add TUF3 php test

* Use ioutil for go 1.15

* Add more delegations tests

* Cleanups

* Check new paths

* Add suggestion

* Add struct tags

* Add tags and remove duplicate types

* Formatting

* Fix order of asserts (should be want, got)

* Clean up DelegatedRole validation

* Fix root to top targets delegation

* July 14 changes (#4)

* Clarify validation of signing role & metadata type

* Add/update comments

* Validation happens on both decode & encode

* Bubble up an error if MatchesPath is called on an invalid DelegatedRole

* Match spec for delegation traversal

* Comment in the iterator

* Add diamond test case

* Revert "Match spec for delegation traversal"

This reverts commit 15fee6b.

* Rename IsTopLevelRole back to ValidRole to avoid breaking change

* Update after reviews

* Add back lower case check

* Initialize with size and comment

* Simplify iterator initialization

* Revert back to "nodes seen" interpretation of delegation traversal spec (#6)

(instead of true cycle detection with "edges seen").

This reverts commit cfbb024.

* Update client/delegations.go

Co-authored-by: Ethan Lowman <53835328+ethan-lowman-dd@users.noreply.github.com>

* Update following reviews of 16th of july (#7)

* Update name

* Rename file to target

* Nits

* Move verifier in iterator and rename fields

* Add tests

* Update after 19th july review (#9)

* Update delegations to err on top level role

* Add simple cycle test

* Remove duplicate check

* Fix comment

* Update comment

Co-authored-by: Ethan Lowman <ethan.lowman@datadoghq.com>
Co-authored-by: Ethan Lowman <53835328+ethan-lowman-dd@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants