public void WithEmbeddedDataButWithoutSignature_Should_Succeed()
            {
                // Arrange
                var originalKey = RsaKey.Generate(embeddedData: new byte[] { 0x01, 0x02, 0x03, 0x03 });

                // Act
                var model = SerializationModelConverter.Convert(key: originalKey);
                var key   = SerializationModelConverter.ConvertKeyModel(model: model);

                // Assert
                System.Convert.FromBase64String(model.Hash).SequenceEqual(originalKey.Hash.Hash).Should().BeTrue();
                key.Hash.Hash.SequenceEqual(originalKey.Hash.Hash).Should().BeTrue();
                System.Convert.FromBase64String(model.EmbeddedData).SequenceEqual(originalKey.EmbeddedData).Should().BeTrue();
                key.EmbeddedData.SequenceEqual(originalKey.EmbeddedData).Should().BeTrue();
                model.SignerCertificateHash.Should().BeNull();
                model.Signature.Should().BeNull();
                key.Signature.Should().BeNull();
            }
 public void ModelInvalid_ShouldThrow_NotSupportedException()
 {
     // Arrange
     // Act & Assert
     Assert.Throws <NotSupportedException>(
         () => SerializationModelConverter.ConvertKeyModel(model: new SerializationModel
     {
         Parameters = new RsaSerializationModel
         {
             D        = "dGVzdA==",
             DP       = "dGVzdA==",
             DQ       = "dGVzdA==",
             Exponent = "dGVzdA==",
             InverseQ = "dGVzdA==",
             Modulus  = "dGVzdA==",
             P        = "dGVzdA==",
             Q        = "dGVzdA==",
         },
     }));
 }
            public void WithoutEmbeddedDataButWithSignature_Should_Succeed()
            {
                // Arrange
                var signerKey   = RsaKey.Generate();
                var originalKey = RsaKey.Generate(signKeyCallback: hash => (RsaSignature)signerKey.Sign(hash));

                // Act
                var model = SerializationModelConverter.Convert(key: originalKey);
                var key   = SerializationModelConverter.ConvertKeyModel(model: model);

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