< Summary

Class:Microsoft.Azure.KeyVault.Cryptography.Algorithms.RsaOaep
Assembly:Microsoft.Azure.KeyVault.Cryptography
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault.Cryptography\src\Algorithms\RsaOaep.cs
Covered lines:20
Uncovered lines:12
Coverable lines:32
Total lines:173
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\RsaOaep.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    /// <summary>
 12    /// RSA-OAEP Encryption.
 13    /// </summary>
 14    public class RsaOaep : RsaEncryption
 15    {
 16        public const string AlgorithmName = "RSA-OAEP";
 17
 18        public RsaOaep()
 219            : base( AlgorithmName )
 20        {
 221        }
 22
 23        public override ICryptoTransform CreateEncryptor( AsymmetricAlgorithm key )
 24        {
 825            RSA csp = key as RSA;
 26
 827            if ( csp == null )
 028                throw new ArgumentException( "key must be an instance of RSA", "key" );
 29
 830            return new RsaOaepEncryptor( csp );
 31        }
 32
 33        public override ICryptoTransform CreateDecryptor( AsymmetricAlgorithm key )
 34        {
 835            RSA csp = key as RSA;
 36
 837            if ( csp == null )
 038                throw new ArgumentException( "key must be an instance of RSA", "key" );
 39
 840            return new RsaOaepDecryptor( csp );
 41        }
 42
 43        /// <summary>
 44        /// RSA 15 Decryptor
 45        /// </summary>
 46        /// <remarks>
 47        /// While this class has a reference to an IDisposable object,
 48        /// it is not the owner of the object and will not Dispose it.
 49        /// </remarks>
 50        class RsaOaepDecryptor : ICryptoTransform
 51        {
 52            private readonly RSA _csp;
 53
 854            internal RsaOaepDecryptor( RSA csp )
 55            {
 856                _csp = csp;
 857            }
 58
 59            public bool CanReuseTransform
 60            {
 061                get { throw new NotImplementedException(); }
 62            }
 63
 64            public bool CanTransformMultipleBlocks
 65            {
 066                get { throw new NotImplementedException(); }
 67            }
 68
 69            public int InputBlockSize
 70            {
 071                get { throw new NotImplementedException(); }
 72            }
 73
 74            public int OutputBlockSize
 75            {
 076                get { throw new NotImplementedException(); }
 77            }
 78
 79            public int TransformBlock( byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int out
 80            {
 081                throw new NotImplementedException();
 82            }
 83
 84            public byte[] TransformFinalBlock( byte[] inputBuffer, int inputOffset, int inputCount )
 85            {
 886                byte[] block = inputBuffer.Skip( inputOffset ).Take( inputCount ).ToArray();
 87
 88#if FullNetFx
 89                if ( _csp is RSACryptoServiceProvider )
 90                {
 91                    return ( ( RSACryptoServiceProvider )_csp ).Decrypt( block, true );
 92                }
 93
 94                throw new CryptographicException( string.Format( "{0} is not supported", _csp.GetType().FullName ) );
 95#elif NETSTANDARD
 896                return _csp.Decrypt( block, RSAEncryptionPadding.OaepSHA1 );
 97#else
 98                #error Unknown Framework
 99#endif
 100            }
 101
 102            public void Dispose()
 103            {
 104                // Intentionally empty
 8105            }
 106        }
 107
 108        /// <summary>
 109        /// RSA 15 Encryptor
 110        /// </summary>
 111        /// <remarks>
 112        /// While this class has a reference to an IDisposable object,
 113        /// it is not the owner of the object and will not Dispose it.
 114        /// </remarks>
 115        class RsaOaepEncryptor : ICryptoTransform
 116        {
 117            private readonly RSA _csp;
 118
 8119            internal RsaOaepEncryptor( RSA csp )
 120            {
 8121                _csp = csp;
 8122            }
 123
 124            public bool CanReuseTransform
 125            {
 0126                get { throw new NotImplementedException(); }
 127            }
 128
 129            public bool CanTransformMultipleBlocks
 130            {
 0131                get { throw new NotImplementedException(); }
 132            }
 133
 134            public int InputBlockSize
 135            {
 0136                get { throw new NotImplementedException(); }
 137            }
 138
 139            public int OutputBlockSize
 140            {
 0141                get { throw new NotImplementedException(); }
 142            }
 143
 144            public int TransformBlock( byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int out
 145            {
 0146                throw new NotImplementedException();
 147            }
 148
 149            public byte[] TransformFinalBlock( byte[] inputBuffer, int inputOffset, int inputCount )
 150            {
 8151                byte[] block = inputBuffer.Skip( inputOffset ).Take( inputCount ).ToArray();
 152
 153#if FullNetFx
 154                if ( _csp is RSACryptoServiceProvider )
 155                {
 156                    return ( ( RSACryptoServiceProvider )_csp ).Encrypt( block, true );
 157                }
 158
 159                throw new CryptographicException( string.Format( "{0} is not supported", _csp.GetType().FullName ) );
 160#elif NETSTANDARD
 8161                return _csp.Encrypt( block, RSAEncryptionPadding.OaepSHA1 );
 162#else
 163                #error Unknown Framework
 164#endif
 165            }
 166
 167            public void Dispose()
 168            {
 169                // Intentionally empty
 8170            }
 171        }
 172    }
 173}