< Summary

Class:Azure.Security.KeyVault.Keys.Cryptography.LocalCryptographyProvider
Assembly:Azure.Security.KeyVault.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\Cryptography\LocalCryptographyProvider.cs
Covered lines:25
Uncovered lines:6
Coverable lines:31
Total lines:109
Line coverage:80.6% (25 of 31)
Covered branches:11
Total branches:14
Branch coverage:78.5% (11 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%50%
get_ShouldRemote()-100%50%
get_KeyMaterial()-100%100%
get_MustRemote()-100%50%
Decrypt(...)-0%100%
DecryptAsync(...)-100%100%
Encrypt(...)-0%100%
EncryptAsync(...)-100%100%
Sign(...)-0%100%
SignAsync(...)-100%100%
UnwrapKey(...)-0%100%
UnwrapKeyAsync(...)-100%100%
Verify(...)-0%100%
VerifyAsync(...)-100%100%
WrapKey(...)-0%100%
WrapKeyAsync(...)-100%100%
ThrowIfTimeInvalid()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\Cryptography\LocalCryptographyProvider.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Threading;
 6using System.Threading.Tasks;
 7
 8namespace Azure.Security.KeyVault.Keys.Cryptography
 9{
 10    internal abstract class LocalCryptographyProvider : ICryptographyProvider
 11    {
 12        private readonly KeyVaultKey _key;
 13
 25014        public LocalCryptographyProvider(KeyVaultKey key)
 15        {
 25016            _key = key ?? throw new ArgumentNullException(nameof(key));
 17
 25018            KeyMaterial = key.Key;
 25019        }
 20
 13421        public bool ShouldRemote => KeyMaterial?.Id != null;
 22
 131823        protected JsonWebKey KeyMaterial { get; set; }
 24
 13425        protected bool MustRemote => ShouldRemote && !KeyMaterial.HasPrivateKey;
 26
 27        public abstract bool SupportsOperation(KeyOperation operation);
 28
 29        public virtual DecryptResult Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancell
 30        {
 031            throw new NotSupportedException();
 32        }
 33
 34        public virtual Task<DecryptResult> DecryptAsync(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationTo
 35        {
 436            DecryptResult result = Decrypt(algorithm, ciphertext, cancellationToken);
 437            return Task.FromResult(result);
 38        }
 39
 40        public virtual EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancella
 41        {
 042            throw new NotSupportedException();
 43        }
 44
 45        public virtual Task<EncryptResult> EncryptAsync(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationTok
 46        {
 247            EncryptResult result = Encrypt(algorithm, plaintext, cancellationToken);
 248            return Task.FromResult(result);
 49        }
 50
 51        public virtual SignResult Sign(SignatureAlgorithm algorithm, byte[] digest, CancellationToken cancellationToken 
 52        {
 053            throw new NotSupportedException();
 54        }
 55
 56        public virtual Task<SignResult> SignAsync(SignatureAlgorithm algorithm, byte[] digest, CancellationToken cancell
 57        {
 4858            SignResult result = Sign(algorithm, digest, cancellationToken);
 4859            return Task.FromResult(result);
 60        }
 61
 62        public virtual UnwrapResult UnwrapKey(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancell
 63        {
 064            throw new NotSupportedException();
 65        }
 66
 67        public virtual Task<UnwrapResult> UnwrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationTo
 68        {
 1069            UnwrapResult result = UnwrapKey(algorithm, encryptedKey, cancellationToken);
 1070            return Task.FromResult(result);
 71        }
 72
 73        public virtual VerifyResult Verify(SignatureAlgorithm algorithm, byte[] digest, byte[] signature, CancellationTo
 74        {
 075            throw new NotSupportedException();
 76        }
 77
 78        public virtual Task<VerifyResult> VerifyAsync(SignatureAlgorithm algorithm, byte[] digest, byte[] signature, Can
 79        {
 2480            VerifyResult result = Verify(algorithm, digest, signature, cancellationToken);
 2481            return Task.FromResult(result);
 82        }
 83
 84        public virtual WrapResult WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken = 
 85        {
 086            throw new NotSupportedException();
 87        }
 88
 89        public virtual Task<WrapResult> WrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellat
 90        {
 891            WrapResult result = WrapKey(algorithm, key, cancellationToken);
 892            return Task.FromResult(result);
 93        }
 94
 95        protected void ThrowIfTimeInvalid()
 96        {
 16097            DateTimeOffset now = DateTimeOffset.Now;
 16098            if (_key.Properties.NotBefore.HasValue && now < _key.Properties.NotBefore.Value)
 99            {
 10100                throw new InvalidOperationException($"The key \"{_key.Name}\" is not valid before {_key.Properties.NotBe
 101            }
 102
 150103            if (_key.Properties.ExpiresOn.HasValue && now > _key.Properties.ExpiresOn.Value)
 104            {
 10105                throw new InvalidOperationException($"The key \"{_key.Name}\" is not valid after {_key.Properties.Expire
 106            }
 140107        }
 108    }
 109}