< Summary

Class:Microsoft.Azure.KeyVault.Cryptography.Algorithms.Ecdsa
Assembly:Microsoft.Azure.KeyVault.Cryptography
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault.Cryptography\src\Algorithms\Ecdsa.cs
Covered lines:6
Uncovered lines:2
Coverable lines:8
Total lines:59
Line coverage:75% (6 of 8)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
CreateSignatureTransform(...)-66.67%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault.Cryptography\src\Algorithms\Ecdsa.cs

#LineLine coverage
 1//
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// license information.
 5//
 6
 7using System;
 8using System.Security.Cryptography;
 9
 10namespace Microsoft.Azure.KeyVault.Cryptography.Algorithms
 11{
 12    /// <summary>
 13    /// Abstract Elliptic Curve Digital Signature Algorithm (ECDSA).
 14    /// </summary>
 15    public abstract class Ecdsa : AsymmetricSignatureAlgorithm
 16    {
 817        protected Ecdsa( string name ) : base( name )
 18        {
 819        }
 20
 21        protected static ISignatureTransform CreateSignatureTransform( AsymmetricAlgorithm key, string algorithmName )
 22        {
 6423            if ( key == null )
 024                throw new ArgumentNullException( nameof( key ) );
 25
 6426            var ecdsa = key as ECDsa;
 6427            if ( ecdsa == null )
 028                throw new ArgumentException( "Invalid key type." );
 29
 30#if FullNetFx
 31            if ( ecdsa.SignatureAlgorithm != algorithmName )
 32                throw new ArgumentException( $"Invalid key algorithm. Expected {algorithmName}, found {ecdsa.SignatureAl
 33#endif
 34
 6435            return new EcdsaSignatureTransform( ecdsa );
 36        }
 37    }
 38
 39    internal sealed class EcdsaSignatureTransform : ISignatureTransform
 40    {
 41        private readonly ECDsa _key;
 42
 43        public EcdsaSignatureTransform(ECDsa key)
 44        {
 45            _key = key;
 46        }
 47
 48        public byte[] Sign(byte[] digest)
 49        {
 50            return _key.SignHash(digest);
 51        }
 52
 53        public bool Verify(byte[] digest, byte[] signature)
 54        {
 55            return _key.VerifyHash(digest, signature);
 56        }
 57    }
 58
 59}