Add TicketFlags class and Creds.ticket_flags attribute#43
Add TicketFlags class and Creds.ticket_flags attribute#43jborean93 merged 1 commit intojborean93:mainfrom
Conversation
9634b23 to
b7957af
Compare
|
I'm a bit torn here, while this library does paper over some API differences that's more around some minor API/struct changes to expose the same data through a Python interface. This case is actually changing the results we get back to some more common standard. Without thinking about it too hard I'm probably against the idea for the following reasons
I'm wondering whether we should keep |
|
The reason I wrote it this way was to allow checking things like "does this ticket have the
I mostly chose the Heimdal version here because it is closer to the RFCs, and because it would in theory allow more than 32 flags. (The on-the-wire ASN1 structure allow more than 32 flags, but both the MIT and Heimdal APIs can return only 32 flags, and changing this would break the ABI.) But I understand the point that this might be confusing to people. Another thing is that python-gssapi also returns the raw ticket flags (in
I think I like the idea. Should I update the PR to
|
I think this might be the easiest option to me, change the existing
Makes sense to me, I would prefer that setup as well. I think as long as we document that |
fb27be2 to
429df05
Compare
|
I've updated the PR to do that. |
| endtime: int | ||
| renew_till: int | ||
|
|
||
| class TicketFlags(enum.IntFlag): |
There was a problem hiding this comment.
Would be great to add a docstring about this enum that links to the RFC where they are defined.
src/krb5/_creds.pyi
Outdated
| """ | ||
|
|
||
| @property | ||
| def addr(self) -> int: |
There was a problem hiding this comment.
Did you add this for a reason? AFAIK this isn't exposed on the actual Creds object.
There was a problem hiding this comment.
Hmm. I thought it was exposed. Probably I added it at some point to the .pyx file and then removed it again.
I'll remove it from the .pyi file.
| # This is to prevent python >= 3.11 from clearing unknown flags when doing: | ||
| # flags = flags & ~TicketFlags.forwarded | ||
| # (Under python 3.11, ~TicketFlags.forwarded will contain only known flags.) | ||
| _all_flags = (1 << 32) - 1 |
There was a problem hiding this comment.
Can you share an actual scenario where this is required? When you say will contain only known flags do you mean that unsetting the bit will clear out any values that aren't defined here or something else?
There was a problem hiding this comment.
Can you share an actual scenario where this is required?
This would be if the KDC sets some flag which is not known to the pykrb5 library and the application wants to see that flag.
When you say
will contain only known flagsdo you mean that unsetting the bit will clear out any values that aren't defined here
Yes.
import enum
class MyFlags(enum.IntFlag):
A = 1
B = 2
print(int(MyFlags(15))) # Will print 15
print(int(MyFlags(15) & ~MyFlags.B)) # On python >= 3.11, will print 1, before 3.11 will print 13
print(int(~MyFlags.B)) # On python >= 3.11, will print 1, before then will print -3
That means without this on Python >= 3.11, a & ~TicketFlags.initial will remove not only the initial flag, but also all flags which are not defined in the TicketFlags enum.
There was a problem hiding this comment.
That's definitely surprising behaviour but if that's out of our control here :) Thanks for sharing the details.
429df05 to
4f7931b
Compare
|
Thanks for all your fantastic PRs for this library, please let me know if you have any more features you want to add anytime soon and I'll hold off on doing some integration testing for the next release. |
Thanks for the quick review and merging of the changes :-)
I opened one last PR #44, but other than that I'm not planning on any new features soon (the last PRs were mostly things I had in my local repository for the last 1-2 years). |
Note that this uses the heimdal definition of the ticket flags (where flag
iis represented as1 << i) instead of the MIT one (where flagiis represented as1 << (31 - i)) because this seems to make more sense to me. For MIT the values are converted when readingCreds.ticket_flags.