| | | 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 | | using CoreWCF.Runtime; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | internal static class ByteStreamMessageUtility |
| | | 10 | | { |
| | | 11 | | public const string StreamElementName = "Binary"; |
| | | 12 | | public const string XmlNamespace = "http://www.w3.org/XML/1998/namespace"; |
| | | 13 | | public const string XmlNamespaceNamespace = "http://www.w3.org/2000/xmlns/"; |
| | | 14 | | |
| | | 15 | | // used when doing message tracing |
| | | 16 | | internal const string EncoderName = "ByteStreamMessageEncoder"; |
| | | 17 | | |
| | | 18 | | internal static void EnsureByteBoundaries(byte[] buffer, int index, int count, bool isRead) |
| | | 19 | | { |
| | 15 | 20 | | if (buffer == null) |
| | | 21 | | { |
| | 0 | 22 | | throw Fx.Exception.ArgumentNull(nameof(buffer)); |
| | | 23 | | } |
| | | 24 | | |
| | 15 | 25 | | if (index < 0) |
| | | 26 | | { |
| | 0 | 27 | | throw Fx.Exception.ArgumentOutOfRange(nameof(index), index, SR.Format(SR.ArgumentOutOfMinRange, 0)); |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | // we explicitly allow the case for index = 0, buffer.Length = 0 and count = 0 when it is write |
| | | 31 | | // Note that we rely on the last check of count > buffer.Length - index to cover count > 0 && index == buffe |
| | 15 | 32 | | if (index > buffer.Length || (isRead && index == buffer.Length)) |
| | | 33 | | { |
| | 0 | 34 | | throw Fx.Exception.ArgumentOutOfRange(nameof(index), index, SR.Format(SR.OffsetExceedsBufferSize, buffer |
| | | 35 | | } |
| | | 36 | | |
| | 15 | 37 | | if (count < 0) |
| | | 38 | | { |
| | 0 | 39 | | throw Fx.Exception.ArgumentOutOfRange(nameof(count), count, SR.Format(SR.ArgumentOutOfMinRange, 0)); |
| | | 40 | | } |
| | | 41 | | |
| | 15 | 42 | | if (count > buffer.Length - index) |
| | | 43 | | { |
| | 0 | 44 | | throw Fx.Exception.ArgumentOutOfRange(nameof(count), count, SR.Format(SR.SizeExceedsRemainingBufferSpace |
| | | 45 | | } |
| | 15 | 46 | | } |
| | | 47 | | |
| | 18 | 48 | | internal static XmlDictionaryReaderQuotas EnsureQuotas(XmlDictionaryReaderQuotas quotas) => quotas ?? EncoderDef |
| | | 49 | | } |
| | | 50 | | } |