public static OpenPgpSecretKey GetKey([NotNull] string path, [NotNull] IOpenPgp openPgp)
{
#region Sanity checks
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
if (openPgp == null) throw new ArgumentNullException(nameof(openPgp));
#endregion
try
{
var signature = Store.Feeds.FeedUtils.GetSignatures(openPgp, File.ReadAllBytes(path))
.OfType<ValidSignature>().FirstOrDefault();
if (signature == null) return null;
return openPgp.GetSecretKey(signature);
}
#region Error handling
catch (KeyNotFoundException)
{
Log.Info(Resources.SecretKeyNotInKeyring);
return null;
}
catch (SignatureException ex)
{
// Unable to parse the signature
Log.Error(ex);
return null;
}
#endregion
}
}