How to detect PDF security permissions?

Q: Is there a way to detect what kind of Permission a pdf has? The
problem I want to tackle is whether the pdf is password protected and
what is the protection type ("file open" or "file edit" or others).
----
A:

You can find if a security handler was successfully initialized by
checking the return value from InitSecurityHandler() or
InitStdSecurityHandler().

If a call to these functions returns false, it means that the document
requires additional authorization (e.g. a password). In this case you
can assume that permission is _not_ granted for the following flags and
you should not call securityHandler.Authorize()/GetPermission():

e_all
e_doc_open
e_doc_secure

On the other hand, you can obtain the following permissions even if the
security handler failed to initialize:

e_print
e_doc_modify
e_extract_content
e_mod_annot
e_fill_forms
e_access_support
e_assemble_doc
e_print_high

For example, you can use the following line to check the 'content
extraction' permission:
bool allow_content_extraction = security_handler.Authorize(
   SecurityHandler.Permission.e_extract_content);