public static GetSignatures ( [ openPgp, [ feedData ) : IEnumerable |
||
openPgp | [ | The OpenPGP-compatible system used to validate the signatures. |
feedData | [ | The feed data containing an embedded signature. |
Résultat | IEnumerable |
/// <inheritdoc/> public IEnumerable <OpenPgpSignature> GetSignatures(FeedUri feedUri) { #region Sanity checks if (feedUri == null) { throw new ArgumentNullException("feedUri"); } #endregion return(FeedUtils.GetSignatures(_openPgp, File.ReadAllBytes(GetPath(feedUri)))); }
public void TestGetSignatures() { var openPgpMock = CreateMock <IOpenPgp>(); var result = new OpenPgpSignature[] { OpenPgpUtilsTest.TestSignature }; openPgpMock.Setup(x => x.Verify(_feedBytes, _signatureBytes)).Returns(result); string input = FeedText + FeedUtils.SignatureBlockStart + _signatureBase64 + FeedUtils.SignatureBlockEnd; FeedUtils.GetSignatures(openPgpMock.Object, Encoding.UTF8.GetBytes(input)).Should().Equal(result); }
public void TestGetSignatures() { var openPgpMock = MockRepository.Create <IOpenPgp>(); var result = new OpenPgpSignature[] { new ValidSignature("123", new DateTime(2000, 1, 1)) }; openPgpMock.Setup(x => x.Verify(_feedBytes, _signatureBytes)).Returns(result); string input = FeedText + FeedUtils.SignatureBlockStart + _signatureBase64 + FeedUtils.SignatureBlockEnd; CollectionAssert.AreEqual(result, FeedUtils.GetSignatures(openPgpMock.Object, Encoding.UTF8.GetBytes(input))); }
/// <summary> /// Determines the key used to sign a feed or catalog file. Only uses the first signature if more than one is present. /// </summary> /// <param name="path">The feed or catalog file to check for signatures.</param> /// <param name="openPgp">The OpenPGP-compatible system used to validate the signatures.</param> /// <returns>The key used to sign the file; <c>null</c> if the file was not signed.</returns> /// <exception cref="FileNotFoundException">The file file could not be found.</exception> /// <exception cref="IOException">The file could not be read.</exception> /// <exception cref="UnauthorizedAccessException">Read access to the file is not permitted.</exception> public static OpenPgpSecretKey?GetKey(string path, 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 = StoreFeedUtils.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 void TestGetSignaturesDataAfterSignature() { string input = FeedText + FeedUtils.SignatureBlockStart + _signatureBase64 + FeedUtils.SignatureBlockEnd + "more data"; Assert.Throws <SignatureException>(() => FeedUtils.GetSignatures(new Mock <IOpenPgp>().Object, Encoding.UTF8.GetBytes(input))); }
public void TestGetSignaturesInvalidChars() { const string input = FeedText + FeedUtils.SignatureBlockStart + "*!?#" + FeedUtils.SignatureBlockEnd; Assert.Throws <SignatureException>(() => FeedUtils.GetSignatures(new Mock <IOpenPgp>().Object, Encoding.UTF8.GetBytes(input))); }
public void TestGetSignaturesMissingNewLine() { string input = "Feed without newline" + FeedUtils.SignatureBlockStart + _signatureBase64 + FeedUtils.SignatureBlockEnd; Assert.Throws <SignatureException>(() => FeedUtils.GetSignatures(new Mock <IOpenPgp>().Object, Encoding.UTF8.GetBytes(input))); }
public void TestGetSignaturesMissingEnd() { string input = FeedText + FeedUtils.SignatureBlockStart + _signatureBase64; Assert.Throws <SignatureException>(() => FeedUtils.GetSignatures(MockRepository.Create <IOpenPgp>().Object, Encoding.UTF8.GetBytes(input))); }