-
Notifications
You must be signed in to change notification settings - Fork 27
headers: validate CWT claims #210
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
base: main
Are you sure you want to change the base?
Conversation
@veraison/go-cose-maintainers, can we get some 👀's on this? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #210 +/- ##
==========================================
- Coverage 91.12% 89.18% -1.95%
==========================================
Files 12 12
Lines 2006 2053 +47
==========================================
+ Hits 1828 1831 +3
- Misses 122 168 +46
+ Partials 56 54 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Pranjal Kole <pranjal.kole7@gmail.com>
@shizhMSFT, @qmuntal, @thomas-fossati can you PTAL? |
for name, _ := range claims { | ||
switch name { | ||
case 1: | ||
iss, hasIss := claims[name] | ||
if hasIss && !canTstr(iss) { | ||
return claims, errors.New("cwt claim: iss: require tstr") | ||
} | ||
case 2: | ||
sub, hasSub := claims[name] | ||
if hasSub && !canTstr(sub) { | ||
return claims, errors.New("cwt claim: sub: require tstr") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are using a for
loop against claims CWTClaims
where type CWTClaims map[any]any
, you don't need to do something like iss, hasIss := claims[name]
as hasIss
is always true.
You may consider a simpler and better code style. Also, you should use constants instead of 1
, 2
, ..., for readability and maintainability.
for name, _ := range claims { | |
switch name { | |
case 1: | |
iss, hasIss := claims[name] | |
if hasIss && !canTstr(iss) { | |
return claims, errors.New("cwt claim: iss: require tstr") | |
} | |
case 2: | |
sub, hasSub := claims[name] | |
if hasSub && !canTstr(sub) { | |
return claims, errors.New("cwt claim: sub: require tstr") | |
} | |
for name, value := range claims { | |
switch name { | |
case CWTClaimIssuer: | |
if !canTstr(value) { | |
return claims, errors.New("cwt claim: iss: require tstr") | |
} | |
case CWTClaimSubject: | |
if !canTstr(value) { | |
return claims, errors.New("cwt claim: sub: require tstr") | |
} |
So as for the rest of the code.
We could also refactor this to a
validateCWTClaims
function incwt.go