< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.EncryptedKeyElement
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/EncryptedKeyElement.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 47
Coverable lines: 47
Total lines: 147
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 28
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
ReadExtensions(...)0%24240%
ReadXml(...)0%440%
GetClause()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/EncryptedKeyElement.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.Collections.Generic;
 5using CoreWCF.IdentityModel.Selectors;
 6using CoreWCF.IdentityModel.Tokens;
 7using System.Xml;
 8
 9namespace CoreWCF.IdentityModel
 10{
 11    /// <summary>
 12    /// This class implements a deserialization for: EncryptedType as defined in section 3.5.1 of http://www.w3.org/TR/2
 13    /// </summary>
 14    internal class EncryptedKeyElement : EncryptedTypeElement
 15    {
 16        private string _recipient;
 17        private List<string> _keyReferences;
 18        private List<string> _dataReferences;
 19
 20        public EncryptedKeyElement( SecurityTokenSerializer keyInfoSerializer )
 021            : base( keyInfoSerializer )
 22        {
 023            _keyReferences = new List<string>();
 024            _dataReferences = new List<string>();
 025        }
 26
 027        public string CarriedName { get; private set; }
 28
 29        public IList<string> DataReferences
 30        {
 031            get { return _dataReferences; }
 32        }
 33
 34        public IList<string> KeyReferences
 35        {
 036            get { return _keyReferences; }
 37        }
 38
 39        public override void ReadExtensions( XmlDictionaryReader reader )
 40        {
 041            reader.MoveToContent();
 042            if ( reader.IsStartElement( XmlEncryptionConstants.Elements.ReferenceList, XmlEncryptionConstants.Namespace 
 43            {
 044                reader.ReadStartElement();
 45
 46                // could have data or key references.  these are the only two possible elements sec 3.6 xml enc.
 47                // 3.6 The ReferenceList Element specifies there is a choice. Once one is chosen, it is fixed.
 048                if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namesp
 49                {
 050                    while ( reader.IsStartElement() )
 51                    {
 052                        if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstant
 53                        {
 054                            string dataRef = reader.GetAttribute( XmlEncryptionConstants.Attributes.Uri );
 055                            if ( !string.IsNullOrEmpty( dataRef ) )
 56                            {
 057                                _dataReferences.Add( dataRef );
 58                            }
 059                            reader.Skip();
 60                        }
 061                        else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionCons
 62                        {
 063                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperXml( reader, SR.Format( SR.ID4189 ) );
 64                        }
 65                        else
 66                        {
 067                            string xml = reader.ReadOuterXml();
 68                            //if ( DiagnosticUtility.ShouldTraceWarning )
 69                            //{
 70                            //    TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.Format( SR.ID8
 71                            //}
 72                        }
 73                    }
 74                }
 075                else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Na
 76                {
 077                    while ( reader.IsStartElement() )
 78                    {
 079                        if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants
 80                        {
 081                            string keyRef = reader.GetAttribute( XmlEncryptionConstants.Attributes.Uri );
 082                            if ( !string.IsNullOrEmpty( keyRef ) )
 83                            {
 084                                _keyReferences.Add( keyRef );
 85                            }
 086                            reader.Skip();
 87                        }
 088                        else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionCon
 89                        {
 090                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperXml( reader, SR.Format( SR.ID4190 ) );
 91                        }
 92                        else
 93                        {
 094                            string xml = reader.ReadOuterXml();
 95                            //if ( DiagnosticUtility.ShouldTraceWarning )
 96                            //{
 97                            //    TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.Format( SR.ID8
 98                            //}
 99                        }
 100                    }
 101                }
 102                else
 103                {
 104                    // there must be at least one reference.
 0105                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperXml( reader, SR.Format( SR.ID4191 ) );
 106                }
 107
 0108                reader.MoveToContent();
 0109                if ( reader.IsStartElement( XmlEncryptionConstants.Elements.CarriedKeyName, XmlEncryptionConstants.Names
 110                {
 0111                    reader.ReadStartElement();
 0112                    CarriedName = reader.ReadString();
 0113                    reader.ReadEndElement();
 114                }
 115
 116                // </ReferenceList>
 0117                reader.ReadEndElement();
 118            }
 0119        }
 120
 121        public override void ReadXml( XmlDictionaryReader reader )
 122        {
 0123            if ( reader == null )
 124            {
 0125                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 126            }
 127
 0128            reader.MoveToContent();
 0129            if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.EncryptedKey, XmlEncryptionConstants.Namespace 
 130            {
 0131                throw DiagnosticUtility.ExceptionUtility.ThrowHelperXml( reader, SR.Format( SR.ID4187 ) );
 132            }
 133
 0134            _recipient = reader.GetAttribute( XmlEncryptionConstants.Attributes.Recipient, null );
 135
 136            //<EncryptedKey> extends <EncryptedType>
 137            // base will read the start element and end elements
 0138            base.ReadXml( reader );
 0139        }
 140
 141        public EncryptedKeyIdentifierClause GetClause()
 142        {
 0143            return new EncryptedKeyIdentifierClause( CipherData.CipherValue, Algorithm, KeyIdentifier );
 144        }
 145
 146    }
 147}