public async Task <Signature> SignAsync(CertificateContent certificate, ICrypt crypt) { stream.Position = 0; var bytes = new byte[stream.Length]; await stream.ReadAsync(bytes, 0, bytes.Length).ConfigureAwait(false); return(crypt.Sign(bytes, certificate.ToBytes())); }
public async Task Should_upload_and_sign_content_by_given_certificate() { var expectedSignature = Signature.FromBytes(new byte[] { 3, 4, 5, 6, 7 }); var certificateContent = CertificateContent.FromBytes(new byte[] { 1, 2, 3 }); documentContent.SignAsync(certificateContent, crypt) .Returns(expectedSignature); var uploadStrategy = new DocumentContentToUpload(documentContent, certificateContent); var(contentId, signature) = await uploadStrategy.UploadAndSignAsync(accountId, uploader, crypt, 1.Seconds()); contentId.Should().Be(expectedContentId); signature.Should().BeEquivalentTo(expectedSignature); }
public bool Add(Certificate entity) { var content = new CertificateContent { Content = entity.Content }; if (Database.Certificates.Any(c => c.Name.Equals(entity.Name))) { return(false); } entity.InternalContent = content; Database.CertificateContents.Add(content); Database.Certificates.Add(entity); Database.SaveChanges(); return(true); }
public DocumentContentToUpload(IDocumentContent documentContent, CertificateContent certificate) : this(documentContent) { this.certificate = certificate ?? throw new ArgumentNullException(nameof(certificate)); }