Exemple #1
0
        private void UpdateFromMem(IntPtr signotPtr)
        {
            int len;
            var signot = (_gpgme_sig_notation)Marshal.PtrToStructure(signotPtr,
                                                                     typeof(_gpgme_sig_notation));

            if (signot.value != IntPtr.Zero)
            {
                len    = signot.value_len;
                _value = Gpgme.PtrToStringUTF8(signot.value,
                                               len);
            }
            if (signot.name != IntPtr.Zero)
            {
                len  = signot.name_len;
                Name = Gpgme.PtrToStringUTF8(signot.name,
                                             len);
            }

            Flags         = (SignatureNotationFlags)signot.flags;
            Critical      = signot.critical;
            HumanReadable = signot.human_readable;

            if (signot.next != IntPtr.Zero)
            {
                _next = new SignatureNotation(signot.next);
            }
        }
            public void Add(string name, string value, SignatureNotationFlags flags)
            {
                if (ctx.IsValid)
                {
                    IntPtr namePtr  = IntPtr.Zero;
                    IntPtr valuePtr = IntPtr.Zero;
                    if (name != null)
                    {
                        namePtr = Gpgme.StringToCoTaskMemUTF8(name);
                    }
                    if (value != null)
                    {
                        valuePtr = Gpgme.StringToCoTaskMemUTF8(value);
                    }

                    int err = libgpgme.gpgme_sig_notation_add(
                        ctx.CtxPtr,
                        namePtr,
                        valuePtr,
                        (gpgme_sig_notation_flags_t)flags);

                    if (namePtr != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(namePtr);
                        namePtr = IntPtr.Zero;
                    }
                    if (valuePtr != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(valuePtr);
                        valuePtr = IntPtr.Zero;
                    }

                    gpg_err_code_t errcode = libgpgerror.gpg_err_code(err);
                    if (errcode == gpg_err_code_t.GPG_ERR_NO_ERROR)
                    {
                        return;
                    }
                    if (errcode == gpg_err_code_t.GPG_ERR_INV_VALUE)
                    {
                        throw new ArgumentException("NAME and VALUE are in an invalid combination.");
                    }

                    throw new GeneralErrorException("An unexpected error occurred. Error: "
                                                    + errcode.ToString());
                }
                else
                {
                    throw new InvalidContextException();
                }
            }