public void ModelInvalid_ShouldThrow_NotSupportedException()
 {
     // Arrange
     // Act & Assert
     Assert.Throws <NotSupportedException>(
         () => SerializationModelConverter.ConvertCertificateModel(model: new SerializationModel()));
 }
            public void WithEmbeddedDataButWithoutSignature_Should_Succeed()
            {
                // Arrange
                var originalKey         = RsaKey.Generate(embeddedData: new byte[] { 0x01, 0x02, 0x03, 0x03 });
                var originalCertificate = (RsaCertificate)originalKey.DeriveCertificate();

                // Act
                var model       = SerializationModelConverter.Convert(certificate: originalCertificate);
                var certificate = SerializationModelConverter.ConvertCertificateModel(model: model);

                // Assert
                System.Convert.FromBase64String(model.Hash).SequenceEqual(originalCertificate.Hash.Hash).Should().BeTrue();
                certificate.Hash.Hash.SequenceEqual(originalCertificate.Hash.Hash).Should().BeTrue();
                System.Convert.FromBase64String(model.EmbeddedData).SequenceEqual(originalCertificate.EmbeddedData).Should().BeTrue();
                certificate.EmbeddedData.SequenceEqual(originalCertificate.EmbeddedData).Should().BeTrue();
                model.SignerCertificateHash.Should().BeNull();
                model.Signature.Should().BeNull();
                certificate.Signature.Should().BeNull();
            }
            public void WithoutEmbeddedDataButWithSignature_Should_Succeed()
            {
                // Arrange
                var signerKey   = RsaKey.Generate();
                var originalKey = RsaKey.Generate(
                    signKeyCallback: hash => (RsaSignature)signerKey.Sign(hash));
                var originalCertificate = (RsaCertificate)originalKey.DeriveCertificate();

                // Act
                var model       = SerializationModelConverter.Convert(certificate: originalCertificate);
                var certificate = SerializationModelConverter.ConvertCertificateModel(model: model);

                // Assert
                System.Convert.FromBase64String(model.Hash).SequenceEqual(originalCertificate.Hash.Hash).Should().BeTrue();
                certificate.Hash.Hash.SequenceEqual(originalCertificate.Hash.Hash).Should().BeTrue();
                model.EmbeddedData.Should().BeNull();
                certificate.EmbeddedData.Should().BeNull();
                System.Convert.FromBase64String(model.SignerCertificateHash).SequenceEqual(originalCertificate.Signature.SignerCertificateHash.Hash).Should().BeTrue();
                System.Convert.FromBase64String(model.Signature).SequenceEqual(originalCertificate.Signature.Signature).Should().BeTrue();
                certificate.Signature.SignerCertificateHash.Hash.SequenceEqual(originalCertificate.Signature.SignerCertificateHash.Hash).Should().BeTrue();
                certificate.Signature.Signature.SequenceEqual(originalCertificate.Signature.Signature).Should().BeTrue();
            }
 public void ModelWithoutSignature_ShouldThrow_NotSupportedException()
 {
     // Arrange
     // Act & Assert
     Assert.Throws <NotSupportedException>(
         () => SerializationModelConverter.ConvertCertificateModel(model: new SerializationModel
     {
         Hash         = "dGVzdA==",
         EmbeddedData = "dGVzdA==",
         Parameters   = new RsaSerializationModel
         {
             D        = null,
             DP       = null,
             DQ       = null,
             Exponent = "dGVzdA==",
             InverseQ = null,
             Modulus  = "dGVzdA==",
             P        = null,
             Q        = null,
         },
         SignerCertificateHash = "dGVzdA==",
         Signature             = null,
     }));
 }
 public void ModelNull_ShouldThrow_ArgumentNullException()
 {
     // Arrange
     // Act & Assert
     Assert.Throws <ArgumentNullException>(() => SerializationModelConverter.ConvertCertificateModel(model: null));
 }