< Summary

Class:Microsoft.Azure.KeyVault.Cryptography.Algorithms.Rsa15
Assembly:Microsoft.Azure.KeyVault.Cryptography
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault.Cryptography\src\Algorithms\Rsa15.cs
Covered lines:20
Uncovered lines:12
Coverable lines:32
Total lines:170
Line coverage:62.5% (20 of 32)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
CreateEncryptor(...)-75%50%
CreateDecryptor(...)-75%50%
.ctor(...)-100%100%
get_CanReuseTransform()-0%100%
get_CanTransformMultipleBlocks()-0%100%
get_InputBlockSize()-0%100%
get_OutputBlockSize()-0%100%
TransformBlock(...)-0%100%
TransformFinalBlock(...)-100%100%
Dispose()-100%100%
.ctor(...)-100%100%
get_CanReuseTransform()-0%100%
get_CanTransformMultipleBlocks()-0%100%
get_InputBlockSize()-0%100%
get_OutputBlockSize()-0%100%
TransformBlock(...)-0%100%
TransformFinalBlock(...)-100%100%
Dispose()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault.Cryptography\src\Algorithms\Rsa15.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.Linq;
 7using System.Security.Cryptography;
 8
 9namespace Microsoft.Azure.KeyVault.Cryptography.Algorithms
 10{
 11    public class Rsa15 : RsaEncryption
 12    {
 13        public const string AlgorithmName = "RSA_15";
 14
 15        public Rsa15()
 216            : base( AlgorithmName )
 17        {
 218        }
 19
 20        public override ICryptoTransform CreateEncryptor( AsymmetricAlgorithm key )
 21        {
 422            RSA csp = key as RSA;
 23
 424            if ( csp == null )
 025                throw new ArgumentException( "key must be an instance of RSA", "key" );
 26
 427            return new Rsa15Encryptor( csp );
 28        }
 29
 30        public override ICryptoTransform CreateDecryptor( AsymmetricAlgorithm key )
 31        {
 432            RSA csp = key as RSA;
 33
 434            if ( csp == null )
 035                throw new ArgumentException( "key must be an instance of RSA", "key" );
 36
 437            return new Rsa15Decryptor( csp );
 38        }
 39
 40        /// <summary>
 41        /// RSA 15 Decryptor
 42        /// </summary>
 43        /// <remarks>
 44        /// While this class has a reference to an IDisposable object,
 45        /// it is not the owner of the object and will not Dispose it.
 46        /// </remarks>
 47        class Rsa15Decryptor : ICryptoTransform
 48        {
 49            private readonly RSA _csp;
 50
 451            internal Rsa15Decryptor( RSA csp )
 52            {
 453                _csp = csp;
 454            }
 55
 56            public bool CanReuseTransform
 57            {
 058                get { throw new NotImplementedException(); }
 59            }
 60
 61            public bool CanTransformMultipleBlocks
 62            {
 063                get { throw new NotImplementedException(); }
 64            }
 65
 66            public int InputBlockSize
 67            {
 068                get { throw new NotImplementedException(); }
 69            }
 70
 71            public int OutputBlockSize
 72            {
 073                get { throw new NotImplementedException(); }
 74            }
 75
 76            public int TransformBlock( byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int out
 77            {
 078                throw new NotImplementedException();
 79            }
 80
 81            public byte[] TransformFinalBlock( byte[] inputBuffer, int inputOffset, int inputCount )
 82            {
 483                byte[] block = inputBuffer.Skip( inputOffset ).Take( inputCount ).ToArray();
 84
 85#if FullNetFx
 86                if ( _csp is RSACryptoServiceProvider )
 87                {
 88                    return ( ( RSACryptoServiceProvider )_csp ).Decrypt( block, false );
 89                }
 90
 91                throw new CryptographicException( string.Format( "{0} is not supported", _csp.GetType().FullName ) );
 92#elif NETSTANDARD
 493                return _csp.Decrypt( block, RSAEncryptionPadding.Pkcs1 );
 94#else
 95                #error Unknown Framework
 96#endif
 97            }
 98
 99            public void Dispose()
 100            {
 101                // Intentionally empty
 4102            }
 103        }
 104
 105        /// <summary>
 106        /// RSA 15 Encryptor
 107        /// </summary>
 108        /// <remarks>
 109        /// While this class has a reference to an IDisposable object,
 110        /// it is not the owner of the object and will not Dispose it.
 111        /// </remarks>
 112        class Rsa15Encryptor : ICryptoTransform
 113        {
 114            private readonly RSA _csp;
 115
 4116            internal Rsa15Encryptor( RSA csp )
 117            {
 4118                _csp = csp;
 4119            }
 120
 121            public bool CanReuseTransform
 122            {
 0123                get { throw new NotImplementedException(); }
 124            }
 125
 126            public bool CanTransformMultipleBlocks
 127            {
 0128                get { throw new NotImplementedException(); }
 129            }
 130
 131            public int InputBlockSize
 132            {
 0133                get { throw new NotImplementedException(); }
 134            }
 135
 136            public int OutputBlockSize
 137            {
 0138                get { throw new NotImplementedException(); }
 139            }
 140
 141            public int TransformBlock( byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int out
 142            {
 0143                throw new NotImplementedException();
 144            }
 145
 146            public byte[] TransformFinalBlock( byte[] inputBuffer, int inputOffset, int inputCount )
 147            {
 4148                byte[] block = inputBuffer.Skip( inputOffset ).Take( inputCount ).ToArray();
 149
 150#if FullNetFx
 151                if ( _csp is RSACryptoServiceProvider )
 152                {
 153                    return ( ( RSACryptoServiceProvider )_csp ).Encrypt( block, false );
 154                }
 155
 156                throw new CryptographicException( string.Format( "{0} is not supported", _csp.GetType().FullName ) );
 157#elif NETSTANDARD
 4158                return _csp.Encrypt( block, RSAEncryptionPadding.Pkcs1 );
 159#else
 160                #error Unknown Framework
 161#endif
 162            }
 163
 164            public void Dispose()
 165            {
 166                // Intentionally empty
 4167            }
 168        }
 169    }
 170}