< Summary

Class:Microsoft.Azure.KeyVault.Cryptography.AlgorithmResolver
Assembly:Microsoft.Azure.KeyVault.Cryptography
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault.Cryptography\src\AlgorithmResolver.cs
Covered lines:24
Uncovered lines:5
Coverable lines:29
Total lines:87
Line coverage:82.7% (24 of 29)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor()-100%100%
get_Item(...)-100%100%
set_Item(...)-0%100%
AddAlgorithm(...)-66.67%50%
RemoveAlgorithm(...)-0%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Diagnostics.CodeAnalysis;
 8using Microsoft.Azure.KeyVault.Cryptography.Algorithms;
 9
 10namespace Microsoft.Azure.KeyVault.Cryptography
 11{
 12    /// <summary>
 13    /// Resolves algorithm name to implementations.
 14    /// </summary>
 15    public class AlgorithmResolver
 16    {
 17        static AlgorithmResolver()
 18        {
 219            Default.AddAlgorithm( Aes128CbcHmacSha256.AlgorithmName, new Aes128CbcHmacSha256() );
 220            Default.AddAlgorithm( Aes192CbcHmacSha384.AlgorithmName, new Aes192CbcHmacSha384() );
 221            Default.AddAlgorithm( Aes256CbcHmacSha512.AlgorithmName, new Aes256CbcHmacSha512() );
 22
 223            Default.AddAlgorithm( Aes128Cbc.AlgorithmName, new Aes128Cbc() );
 224            Default.AddAlgorithm( Aes192Cbc.AlgorithmName, new Aes192Cbc() );
 225            Default.AddAlgorithm( Aes256Cbc.AlgorithmName, new Aes256Cbc() );
 26
 227            Default.AddAlgorithm( AesKw128.AlgorithmName, new AesKw128() );
 228            Default.AddAlgorithm( AesKw192.AlgorithmName, new AesKw192() );
 229            Default.AddAlgorithm( AesKw256.AlgorithmName, new AesKw256() );
 30
 231            Default.AddAlgorithm( Rsa15.AlgorithmName, new Rsa15() );
 232            Default.AddAlgorithm( RsaOaep.AlgorithmName, new RsaOaep() );
 33
 234            Default.AddAlgorithm( Rs256.AlgorithmName, new Rs256() );
 35
 36#if FullNetFx
 37            Default.AddAlgorithm( RsNull.AlgorithmName, new RsNull() );
 38#endif
 39
 240            Default.AddAlgorithm( Es256.AlgorithmName, new Es256() );
 241            Default.AddAlgorithm( Es384.AlgorithmName, new Es384() );
 242            Default.AddAlgorithm( Es512.AlgorithmName, new Es512() );
 243            Default.AddAlgorithm( ES256K.AlgorithmName, new ES256K() );
 244        }
 45
 46        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
 247        public static readonly AlgorithmResolver Default = new AlgorithmResolver();
 48
 249        private readonly Dictionary<string, Algorithm> _algorithms = new Dictionary<string, Algorithm>();
 50
 51        /// <summary>
 52        /// Returns the implementation for an algorithm name
 53        /// </summary>
 54        /// <param name="algorithmName">The algorithm name</param>
 55        /// <returns></returns>
 56        public Algorithm this[ string algorithmName ]
 57        {
 11858            get { return _algorithms[algorithmName]; }
 059            set { _algorithms[algorithmName] = value;  }
 60        }
 61
 62        /// <summary>
 63        /// Adds an algorithm to the resolver
 64        /// </summary>
 65        /// <param name="algorithmName">The algorithm name</param>
 66        /// <param name="provider">The provider for the algorithm</param>
 67        public void AddAlgorithm( string algorithmName, Algorithm provider )
 68        {
 3269            if ( string.IsNullOrWhiteSpace( algorithmName ) )
 070                throw new ArgumentNullException( nameof( algorithmName ) );
 71
 3272            if ( provider == null )
 073                throw new ArgumentNullException( nameof( provider ) );
 74
 3275            _algorithms[algorithmName] = provider;
 3276        }
 77
 78        /// <summary>
 79        /// Removes an algorithm from the resolver
 80        /// </summary>
 81        /// <param name="algorithmName">The algorithm name</param>
 82        public void RemoveAlgorithm( string algorithmName )
 83        {
 084            _algorithms.Remove( algorithmName );
 085        }
 86    }
 87}