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

Remove unnecessary cbor marshal methods #155

Merged
merged 10 commits into from
Jul 5, 2023
Merged

Remove unnecessary cbor marshal methods #155

merged 10 commits into from
Jul 5, 2023

Conversation

qmuntal
Copy link
Contributor

@qmuntal qmuntal commented Jul 4, 2023

This PR removes a bunch of methods added in #146 which, in my opinion, shouldn't have been added.

This is the list and the reasoning for removing them:

  • Algorithm.UnmarshalCBOR: its sole purpose is to allow unmarshaling algorithms encoded as strings. We don't support any algorithm than can be references as a string, so this method always fail on such case. I would rather not add a code path for a thing that we don't support, just in case in the future we need to. It makes the code base bigger and more difficult to maintain.
  • Algorithm.MarshalCBOR: it was only there as companion method for Algorithm.UnmarshalCBOR.
  • KeyType.UnmarshalCBOR: same reasoning as in Algorithm.UnmarshalCBOR. Additionally, we should not error when the value is not supported by go-cose, as users might want to unmarshal a key using go-cose but create a signer/verifier using external code.
  • Algorithm.MarshalCBOR: it was only there as companion method for KeyType.UnmarshalCBOR.
  • Curve.MarshalCBOR: same reasoning as in KeyType.UnmarshalCBOR, also we shouldn't validate its value.
  • Curve.MarshalCBOR: it was only there as companion method for Curve.UnmarshalCBOR.

Also, I've removed KeyOpt.IsSupported and its usage in KeyOpt.UnmarshalCBOR. RFC 7517 Section 4.3 says that other values may be used.

The alg parameter is unnecessary, and makes these functions more awkward
to use. The input PublicKey/PrivateKey is now identified via a type
switch, and the algorithm is derived from it.

Signed-off-by: setrofim <setrofim@gmail.com>
RFC8152 allows for unregistered curves, therefore we should not fail key
validation if a curve is not recognised when marshalling. We should only
fail when a known curve is used with an incorrect key type.

Signed-off-by: setrofim <setrofim@gmail.com>
Ensure that the KeyType is the expected one for the Curve when creating
crypto.PublicKey or crypto.PrivateKey.

Signed-off-by: setrofim <setrofim@gmail.com>
RFC8152 allows public parts to be omitted from private keys, as they
could be derived (though it recommends that they are present).
crypto.PrivateKey implementations require for them to be present.

Signed-off-by: setrofim <setrofim@gmail.com>
Add test for String() calls not exercised by other test cases to placate
Codecov.

Signed-off-by: setrofim <setrofim@gmail.com>
Signed-off-by: setrofim <setrofim@gmail.com>
Signed-off-by: qmuntal <qmuntaldiaz@microsoft.com>
Signed-off-by: qmuntal <qmuntaldiaz@microsoft.com>
Signed-off-by: qmuntal <qmuntaldiaz@microsoft.com>
@codecov
Copy link

codecov bot commented Jul 4, 2023

Codecov Report

Merging #155 (fec382b) into main (cebef14) will decrease coverage by 0.25%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
- Coverage   91.48%   91.24%   -0.25%     
==========================================
  Files          12       12              
  Lines        1633     1542      -91     
==========================================
- Hits         1494     1407      -87     
+ Misses        101       98       -3     
+ Partials       38       37       -1     
Impacted Files Coverage Δ
algorithm.go 85.36% <ø> (-3.35%) ⬇️
headers.go 93.09% <100.00%> (-0.13%) ⬇️
key.go 88.86% <100.00%> (-0.85%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@yogeshbdeshpande yogeshbdeshpande left a comment

Choose a reason for hiding this comment

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

LGTM!

Base automatically changed from setrofim to main July 5, 2023 11:50
@qmuntal qmuntal merged commit 2f778da into main Jul 5, 2023
@qmuntal qmuntal deleted the cleanmarshal branch July 5, 2023 11:59
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.

4 participants