| | | 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 | | |
| | | 4 | | using System.Xml; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.Security |
| | | 7 | | { |
| | | 8 | | internal sealed class BinaryNegotiation |
| | | 9 | | { |
| | | 10 | | private readonly byte[] _negotiationData; |
| | | 11 | | private XmlDictionaryString _valueTypeUriDictionaryString; |
| | | 12 | | |
| | 0 | 13 | | public BinaryNegotiation( |
| | 0 | 14 | | string valueTypeUri, |
| | 0 | 15 | | byte[] negotiationData) |
| | | 16 | | { |
| | 0 | 17 | | _valueTypeUriDictionaryString = null; |
| | 0 | 18 | | ValueTypeUri = valueTypeUri ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value |
| | 0 | 19 | | _negotiationData = negotiationData ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameo |
| | 0 | 20 | | } |
| | | 21 | | |
| | 0 | 22 | | public BinaryNegotiation( |
| | 0 | 23 | | XmlDictionaryString valueTypeDictionaryString, |
| | 0 | 24 | | byte[] negotiationData) |
| | | 25 | | { |
| | 0 | 26 | | _valueTypeUriDictionaryString = valueTypeDictionaryString ?? throw DiagnosticUtility.ExceptionUtility.ThrowH |
| | 0 | 27 | | ValueTypeUri = valueTypeDictionaryString.Value; |
| | 0 | 28 | | _negotiationData = negotiationData ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameo |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | public void Validate(XmlDictionaryString valueTypeUriDictionaryString) |
| | | 32 | | { |
| | 0 | 33 | | if (ValueTypeUri != valueTypeUriDictionaryString.Value) |
| | | 34 | | { |
| | 0 | 35 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityNegotiationException(SR.Format(SR. |
| | | 36 | | } |
| | 0 | 37 | | _valueTypeUriDictionaryString = valueTypeUriDictionaryString; |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | public void WriteTo(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryStrin |
| | | 41 | | { |
| | 0 | 42 | | writer.WriteStartElement(prefix, localName, ns); |
| | 0 | 43 | | writer.WriteStartAttribute(valueTypeLocalName, valueTypeNs); |
| | 0 | 44 | | if (_valueTypeUriDictionaryString != null) |
| | | 45 | | { |
| | 0 | 46 | | writer.WriteString(_valueTypeUriDictionaryString); |
| | | 47 | | } |
| | | 48 | | else |
| | | 49 | | { |
| | 0 | 50 | | writer.WriteString(ValueTypeUri); |
| | | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | writer.WriteEndAttribute(); |
| | 0 | 54 | | writer.WriteStartAttribute(XD.SecurityJan2004Dictionary.EncodingType, null); |
| | 0 | 55 | | writer.WriteString(XD.SecurityJan2004Dictionary.EncodingTypeValueBase64Binary); |
| | 0 | 56 | | writer.WriteEndAttribute(); |
| | 0 | 57 | | writer.WriteBase64(_negotiationData, 0, _negotiationData.Length); |
| | 0 | 58 | | writer.WriteEndElement(); |
| | 0 | 59 | | } |
| | | 60 | | |
| | 0 | 61 | | public string ValueTypeUri { get; } |
| | | 62 | | |
| | | 63 | | public byte[] GetNegotiationData() |
| | | 64 | | { |
| | | 65 | | // avoid copying since this is internal and callers use it as read-only |
| | 0 | 66 | | return _negotiationData; |
| | | 67 | | } |
| | | 68 | | } |
| | | 69 | | } |