-
-
Save roee88/49d22e28cfd95dbabde2813e067594aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cdef cppclass PyDecryptionKeyRetriever(CDecryptionKeyRetriever): | |
object pyobject | |
__init__(object pyobject): | |
this.pyobject = pyobject | |
c_string GetKey(const c_string& key_metadata) const: | |
h = cp.PyGILState_Ensure() | |
try: | |
if callable(this.pyobject): | |
return <c_string> tobytes(this.pyobject(key_metadata)) | |
elif hasattr(this.pyobject, "get_key"): | |
return <c_string> tobytes(this.pyobject.get_key(key_metadata)) | |
else: | |
raise RuntimeError( | |
"KeyRetriever must be callable or implement get_key") | |
finally: | |
cp.PyGILState_Release(h) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment