private GetKey ( [ path, [ openPgp ) : OpenPgpSecretKey | ||
path | [ | |
openPgp | [ | |
Результат | OpenPgpSecretKey |
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
}
}
public static SignedCatalog Load([NotNull] string path) { #region Sanity checks if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } #endregion return(new SignedCatalog(XmlStorage.LoadXml <Catalog>(path), FeedUtils.GetKey(path, OpenPgpFactory.CreateDefault()))); }