< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.Tokens.BinarySecretSecurityToken
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/Tokens/BinarySecretSecurityToken.cs
Line coverage
62%
Covered lines: 17
Uncovered lines: 10
Coverable lines: 27
Total lines: 95
Line coverage: 62.9%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%110%
.ctor(...)50%4481.81%
GetKeyBytes()100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/Tokens/BinarySecretSecurityToken.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.Collections.ObjectModel;
 6using CoreWCF.IdentityModel;
 7using CoreWCF.IdentityModel.Tokens;
 8
 9namespace CoreWCF.Security.Tokens
 10{
 11    public class BinarySecretSecurityToken : SecurityToken
 12    {
 13        private readonly string _id;
 14        private readonly DateTime _effectiveTime;
 15        private readonly byte[] _key;
 16        private readonly ReadOnlyCollection<SecurityKey> _securityKeys;
 17
 18        public BinarySecretSecurityToken(int keySizeInBits)
 019            : this(SecurityUniqueId.Create().Value, keySizeInBits)
 20        {
 021        }
 22
 23        public BinarySecretSecurityToken(string id, int keySizeInBits)
 024            : this(id, keySizeInBits, true)
 25        {
 026        }
 27
 28        public BinarySecretSecurityToken(byte[] key)
 229            : this(SecurityUniqueId.Create().Value, key)
 30        {
 231        }
 32
 33        public BinarySecretSecurityToken(string id, byte[] key)
 234            : this(id, key, true)
 35        {
 236        }
 37
 038        protected BinarySecretSecurityToken(string id, int keySizeInBits, bool allowCrypto)
 39        {
 040            throw new NotImplementedException();
 41        }
 42
 2243        protected BinarySecretSecurityToken(string id, byte[] key, bool allowCrypto)
 44        {
 2245            if (key == null)
 46            {
 047                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(key));
 48            }
 49
 2250            _id = id;
 2251            _effectiveTime = DateTime.UtcNow;
 2252            _key = new byte[key.Length];
 2253            Buffer.BlockCopy(key, 0, _key, 0, key.Length);
 2254            if (allowCrypto)
 55            {
 256                _securityKeys = SecurityUtils.CreateSymmetricSecurityKeys(_key);
 57            }
 58            else
 59            {
 2060                _securityKeys = EmptyReadOnlyCollection<SecurityKey>.Instance;
 61            }
 2062        }
 63
 64        public override string Id
 65        {
 2066            get { return _id; }
 67        }
 68
 69        public override DateTime ValidFrom
 70        {
 071            get { return _effectiveTime; }
 72        }
 73
 74        public override DateTime ValidTo
 75        {
 76            // Never expire
 077            get { return DateTime.MaxValue; }
 78        }
 79
 80        public int KeySize
 81        {
 082            get { return (_key.Length * 8); }
 83        }
 84
 85        public override ReadOnlyCollection<SecurityKey> SecurityKeys
 86        {
 287            get { return _securityKeys; }
 88        }
 89
 90        public byte[] GetKeyBytes()
 91        {
 2092            return SecurityUtils.CloneBuffer(_key);
 93        }
 94    }
 95}