Skip to content

Instantly share code, notes, and snippets.

@roee88
Created April 7, 2021 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roee88/49d22e28cfd95dbabde2813e067594aa to your computer and use it in GitHub Desktop.
Save roee88/49d22e28cfd95dbabde2813e067594aa to your computer and use it in GitHub Desktop.
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