Example #1
0
        /// <summary>
        /// Returns a list of all engines available for use.
        /// </summary>
        public static List <EngineInfo> GetEngines()
        {
            GpgMeEngineInfo info;

            ErrorHandler.Check(GpgMeWrapper.gpgme_get_engine_info(out info));
            return(info.ToList());
        }
Example #2
0
        /// <summary>
        /// Searches the keyring for all keys that match the given search parameters,
        /// and stops the search as soon as the first match is found.
        /// </summary>
        public static GpgKey FindKey(GpgContext ctx, string pattern, bool privateOnly)
        {
            ErrorHandler.Check(GpgMeWrapper.gpgme_op_keylist_start(ctx.Handle, pattern, privateOnly));
            // Grab the first key
            IntPtr keyPtr;
            var    result = GpgMeWrapper.gpgme_op_keylist_next(ctx.Handle, out keyPtr);

            if (result != GpgMeError.GPG_ERR_NO_ERROR)
            {
                return(null);
            }
            // If the operation succeeds, keyPtr will have been assigned a value.
            // Grab the GpgMeKey structure belonging to the pointer
            var key = Marshal.PtrToStructure <GpgMeKey>(keyPtr);

            // Turn the GpgMeKey into a GpgKey (resolves the subkeys and uids linked lists)
            return(key.ToGpgKey(keyPtr));
        }
Example #3
0
        /// <summary>
        /// Searches the keyring for all keys that match the given search parameters.
        /// </summary>
        public static IEnumerable <GpgKey> FindKeys(GpgContext ctx, string pattern, bool privateOnly)
        {
            // Start the key listing operation
            ErrorHandler.Check(GpgMeWrapper.gpgme_op_keylist_start(ctx.Handle, pattern, privateOnly));

            // Grab the first key
            IntPtr keyPtr;
            var    result = GpgMeWrapper.gpgme_op_keylist_next(ctx.Handle, out keyPtr);

            while (result == GpgMeError.GPG_ERR_NO_ERROR)
            {
                // If the operation succeeds, keyPtr will have been assigned a value.
                // Grab the GpgMeKey structure belonging to the pointer
                var key = Marshal.PtrToStructure <GpgMeKey>(keyPtr);

                // Turn the GpgMeKey into a GpgKey (resolves the subkeys and uids linked lists)
                yield return(key.ToGpgKey(keyPtr));

                // Try grabbing the next key
                result = GpgMeWrapper.gpgme_op_keylist_next(ctx.Handle, out keyPtr);
            }
            // End the key listing operation
            ErrorHandler.Check(GpgMeWrapper.gpgme_op_keylist_end(ctx.Handle));
        }