< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.InMemorySymmetricSecurityKey
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SymmetricKey.cs
Line coverage
65%
Covered lines: 17
Uncovered lines: 9
Coverable lines: 26
Total lines: 101
Line coverage: 65.3%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
.ctor(...)50%6663.63%
DecryptKey(...)100%110%
EncryptKey(...)100%110%
GenerateDerivedKey(...)100%110%
GetDecryptionTransform(...)100%110%
GetEncryptionTransform(...)100%110%
GetIVSize(...)100%110%
GetKeyedHashAlgorithm(...)100%11100%
GetSymmetricAlgorithm(...)100%110%
GetSymmetricKey()100%11100%
IsSupportedAlgorithm(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SymmetricKey.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Security.Cryptography;
 6
 7namespace CoreWCF.IdentityModel.Tokens
 8{
 9    internal class InMemorySymmetricSecurityKey : SymmetricSecurityKey
 10    {
 11        private readonly int _keySize;
 12        private readonly byte[] _symmetricKey;
 13
 14        public InMemorySymmetricSecurityKey(byte[] symmetricKey)
 215            : this(symmetricKey, true)
 16        {
 217        }
 18
 4219        public InMemorySymmetricSecurityKey(byte[] symmetricKey, bool cloneBuffer)
 20        {
 4221            if (symmetricKey == null)
 22            {
 023                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(symmetricKey)
 24            }
 25
 4226            if (symmetricKey.Length == 0)
 27            {
 028                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format("SymmetricKeyL
 29            }
 4230            _keySize = symmetricKey.Length * 8;
 31
 4232            if (cloneBuffer)
 33            {
 234                _symmetricKey = new byte[symmetricKey.Length];
 235                Buffer.BlockCopy(symmetricKey, 0, _symmetricKey, 0, symmetricKey.Length);
 36            }
 37            else
 38            {
 4039                _symmetricKey = symmetricKey;
 40            }
 4041        }
 42
 43        public override int KeySize
 44        {
 4045            get { return _keySize; }
 46        }
 47
 48        public override byte[] DecryptKey(string algorithm, byte[] keyData)
 49        {
 050            return CryptoHelper.UnwrapKey(_symmetricKey, keyData, algorithm);
 51        }
 52
 53        public override byte[] EncryptKey(string algorithm, byte[] keyData)
 54        {
 055            return CryptoHelper.WrapKey(_symmetricKey, keyData, algorithm);
 56        }
 57
 58        public override byte[] GenerateDerivedKey(string algorithm, byte[] label, byte[] nonce, int derivedKeyLength, in
 59        {
 060            return CryptoHelper.GenerateDerivedKey(_symmetricKey, algorithm, label, nonce, derivedKeyLength, offset);
 61        }
 62
 63        public override ICryptoTransform GetDecryptionTransform(string algorithm, byte[] iv)
 64        {
 065            return CryptoHelper.CreateDecryptor(_symmetricKey, iv, algorithm);
 66        }
 67
 68        public override ICryptoTransform GetEncryptionTransform(string algorithm, byte[] iv)
 69        {
 070            return CryptoHelper.CreateEncryptor(_symmetricKey, iv, algorithm);
 71        }
 72
 73        public override int GetIVSize(string algorithm)
 74        {
 075            return CryptoHelper.GetIVSize(algorithm);
 76        }
 77
 78        public override KeyedHashAlgorithm GetKeyedHashAlgorithm(string algorithm)
 79        {
 2080            return CryptoHelper.CreateKeyedHashAlgorithm(_symmetricKey, algorithm);
 81        }
 82
 83        public override SymmetricAlgorithm GetSymmetricAlgorithm(string algorithm)
 84        {
 085            return CryptoHelper.GetSymmetricAlgorithm(_symmetricKey, algorithm);
 86        }
 87
 88        public override byte[] GetSymmetricKey()
 89        {
 290            byte[] local = new byte[_symmetricKey.Length];
 291            Buffer.BlockCopy(_symmetricKey, 0, local, 0, _symmetricKey.Length);
 92
 293            return local;
 94        }
 95
 96        public override bool IsSupportedAlgorithm(string algorithm)
 97        {
 2098            return (CryptoHelper.IsSymmetricSupportedAlgorithm(algorithm, KeySize));
 99        }
 100    }
 101}