/// <summary> /// Gets the GPG key associated with the given key ID. /// This method will throw an exception if the given key ID matches zero or multiple keys. /// </summary> /// <param name="keyId">The key ID of the requested GPG key.</param> /// <exception cref="GpgKeyNotFoundException"> /// Thrown when the given key ID matches zero or multiple keys. /// </exception> public GpgKey GetKey(string keyId) { var matches = GpgMeHelper.FindKeys(this, keyId, false).ToArray(); if (matches.Length == 0) { throw new GpgKeyNotFoundException("No matches were returned for the given key ID"); } if (matches.Length > 1) { throw new GpgKeyNotFoundException("Multiple matches were found for the given key ID"); } return(matches[0]); }
/// <summary> /// Searches for keys matching the given search parameters. /// </summary> /// <param name="pattern">One or more GPG key IDs to search for. The default value (null) matches all keys.</param> /// <param name="privateOnly">True if only GPG keys for which a private key is available should be returned, false otherwise.</param> /// <returns>A list of GPG keys matching the given search parameters.</returns> public IEnumerable <GpgKey> FindKeys(string pattern = null, bool privateOnly = false) { return(GpgMeHelper.FindKeys(this, pattern, privateOnly)); }