private int _passphrase_cb(IntPtr Hook, IntPtr uid_hint, IntPtr passphrase_info,
                                   int prev_was_bad, int fd)
        {
            bool   prevbad;
            string hint, info;

            char[] passwd = null;

            hint = Gpgme.PtrToStringUTF8(uid_hint);
            info = Gpgme.PtrToStringUTF8(passphrase_info);
            if (prev_was_bad > 0)
            {
                prevbad = true;
            }
            else
            {
                prevbad = false;
            }

            PassphraseResult result;

            try
            {
                PassphraseInfo pinfo = new PassphraseInfo(Hook, hint, info, prevbad);
                result = passphraseFunc(this, pinfo, ref passwd);
            }
            catch (Exception ex)
            {
                LastCallbackException = ex;
                passwd = "".ToCharArray();
                result = PassphraseResult.Canceled;
            }

            if (fd > 0)
            {
                byte[] utf8passwd = Gpgme.ConvertCharArrayToUTF8(passwd, 0);

                Stream fdstream = Gpgme.ConvertToStream(fd, FileAccess.Write);
                fdstream.Write(utf8passwd, 0, utf8passwd.Length);
                fdstream.Flush();
                fdstream.WriteByte((byte)'\n');
                fdstream.Flush();

                // try to wipe the passwords
                int i;
                for (i = 0; i < utf8passwd.Length; i++)
                {
                    utf8passwd[i] = 0;
                }
            }

            return((int)result);
        }
Пример #2
0
        // internal callback function
        private int _edit_cb(
            IntPtr opaque,
            int status,
            IntPtr args,
            int fd)
        {
            gpgme_status_code_t statuscode = (gpgme_status_code_t)status;
            string cmdargs = Gpgme.PtrToStringUTF8(args);
            Stream fdstream;

            if (fd > 0)
            {
                fdstream = Gpgme.ConvertToStream(fd, FileAccess.Write);
            }
            else
            {
                fdstream = null;
            }

            int result = 0;

            try
            {
                // call user callback function.
                result = KeyEditCallback(
                    opaque,
                    (KeyEditStatusCode)statuscode,
                    cmdargs,
                    fdstream);
            }
            catch (Exception ex)
            {
                LastCallbackException = ex;
            }

            return(result);
        }