Ejemplo n.º 1
0
            public void GivenUnsupportedAlgorithmType_ThrowsNotSupportedException()
            {
                var    unsupported = new CustomSignatureAlgorithm("CUSTOM");
                Action act         = () => SignatureAlgorithmDataRecord.FromSignatureAlgorithm(unsupported);

                act.Should().Throw <NotSupportedException>();
            }
Ejemplo n.º 2
0
 public void GivenHMACAlgorithm_ReturnsExpectedDataRecord()
 {
     using (var hmac = SignatureAlgorithm.CreateForVerification("s3cr3t", HashAlgorithmName.SHA384)) {
         var actual   = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(hmac);
         var expected = new SignatureAlgorithmDataRecord {
             Type          = "HMAC",
             Parameter     = "s3cr3t",
             HashAlgorithm = HashAlgorithmName.SHA384.Name
         };
         actual.Should().BeEquivalentTo(expected);
     }
 }
Ejemplo n.º 3
0
 public void GivenECDsaAlgorithm_ReturnsExpectedDataRecord()
 {
     using (var ecdsa = ECDsa.Create()) {
         using (var ecdsaAlg = SignatureAlgorithm.CreateForVerification(ecdsa, HashAlgorithmName.SHA384)) {
             var actual   = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(ecdsaAlg);
             var expected = new SignatureAlgorithmDataRecord {
                 Type          = "ECDsa",
                 Parameter     = ecdsa.ExportParameters(false).ToXml(),
                 HashAlgorithm = HashAlgorithmName.SHA384.Name
             };
             actual.Should().BeEquivalentTo(expected);
         }
     }
 }
Ejemplo n.º 4
0
 public void GivenRSAAlgorithm_ReturnsExpectedDataRecord()
 {
     using (var rsa = new RSACryptoServiceProvider()) {
         using (var rsaAlg = SignatureAlgorithm.CreateForVerification(rsa, HashAlgorithmName.SHA384)) {
             var actual   = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(rsaAlg);
             var expected = new SignatureAlgorithmDataRecord {
                 Type          = "RSA",
                 Parameter     = rsa.ExportParameters(false).ToXml(),
                 HashAlgorithm = HashAlgorithmName.SHA384.Name
             };
             actual.Should().BeEquivalentTo(expected);
         }
     }
 }
        public Task Register(Client client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var record = new ClientDataRecord {
                Id                 = client.Id,
                Name               = client.Name,
                NonceExpiration    = client.NonceLifetime.TotalSeconds,
                Claims             = client.Claims?.Select(c => ClaimDataRecord.FromClaim(c))?.ToArray(),
                SignatureAlgorithm = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(client.SignatureAlgorithm)
            };

            var collection = _lazyCollection.Value;

            return(collection.ReplaceOneAsync(r => r.Id == record.Id, record, new ReplaceOptions {
                IsUpsert = true
            }));
        }
Ejemplo n.º 6
0
            public void GivenNullSignatureAlgorithm_ThrowsArgumentNullException()
            {
                Action act = () => SignatureAlgorithmDataRecord.FromSignatureAlgorithm(null);

                act.Should().Throw <ArgumentNullException>();
            }