| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | using System.Linq; |
| | | 7 | | using System.Security.Authentication; |
| | | 8 | | using Azure.Core.Pipeline; |
| | | 9 | | |
| | | 10 | | namespace Azure.Storage |
| | | 11 | | { |
| | | 12 | | // These error messages are only used by client libraries and not by the common |
| | | 13 | | internal partial class Errors |
| | | 14 | | { |
| | | 15 | | public static ArgumentException CannotBothBeNotNull(string param0, string param1) |
| | 0 | 16 | | => new ArgumentException($"{param0} and {param1} cannot both be set"); |
| | | 17 | | |
| | | 18 | | public static ArgumentException InvalidArgument(string paramName) |
| | 0 | 19 | | => new ArgumentException($"{paramName} is invalid"); |
| | | 20 | | |
| | | 21 | | public static ArgumentOutOfRangeException MustBeGreaterThanOrEqualTo(string paramName, long value) |
| | 0 | 22 | | => new ArgumentOutOfRangeException(paramName, $"Value must be greater than or equal to {value}"); |
| | | 23 | | |
| | | 24 | | public static ArgumentOutOfRangeException MustBeLessThanOrEqualTo(string paramName, long value) |
| | 0 | 25 | | => new ArgumentOutOfRangeException(paramName, $"Value must be less than or equal to {value}"); |
| | | 26 | | |
| | | 27 | | public static ArgumentOutOfRangeException MustBeBetweenInclusive( |
| | | 28 | | string paramName, |
| | | 29 | | long lower, |
| | | 30 | | long upper, |
| | | 31 | | long actual) |
| | 0 | 32 | | => new ArgumentOutOfRangeException(paramName, $"Value must be between {lower} and {upper} inclusive, not {ac |
| | | 33 | | |
| | | 34 | | public static ArgumentOutOfRangeException MustBeGreaterThanValueOrEqualToOtherValue( |
| | | 35 | | string paramName, |
| | | 36 | | long value0, |
| | | 37 | | long value1) |
| | 0 | 38 | | => new ArgumentOutOfRangeException(paramName, $"Value must be greater than {value0} or equal to {value1}"); |
| | | 39 | | |
| | | 40 | | public static ArgumentException StreamMustBeReadable(string paramName) |
| | 0 | 41 | | => new ArgumentException("Stream must be readable", paramName); |
| | | 42 | | |
| | | 43 | | public static InvalidOperationException StreamMustBeAtPosition0() |
| | 0 | 44 | | => new InvalidOperationException("Stream must be set to position 0"); |
| | | 45 | | |
| | | 46 | | public static InvalidOperationException TokenCredentialsRequireHttps() |
| | 0 | 47 | | => new InvalidOperationException("Use of token credentials requires HTTPS"); |
| | | 48 | | |
| | | 49 | | public static InvalidOperationException SasMissingData(string paramName) |
| | 0 | 50 | | => new InvalidOperationException($"SAS is missing required parameter: {paramName}"); |
| | | 51 | | |
| | | 52 | | public static InvalidOperationException SasDataNotAllowed(string paramName, string paramNameNotAllowed) |
| | 0 | 53 | | => new InvalidOperationException($"SAS cannot have the {paramNameNotAllowed} parameter when the {paramName} |
| | | 54 | | |
| | | 55 | | public static ArgumentException InvalidPermission(char s) |
| | 0 | 56 | | => new ArgumentException($"Invalid permission: '{s}'"); |
| | | 57 | | |
| | | 58 | | public static ArgumentException ParsingHttpRangeFailed() |
| | 0 | 59 | | => new ArgumentException("Could not parse the serialized range."); |
| | | 60 | | |
| | | 61 | | public static AccessViolationException UnableAccessArray() |
| | 0 | 62 | | => new AccessViolationException("Unable to get array from memory pool"); |
| | | 63 | | |
| | | 64 | | public static NotImplementedException NotImplemented() |
| | 0 | 65 | | => new NotImplementedException(); |
| | | 66 | | |
| | | 67 | | public static AuthenticationException InvalidCredentials(string fullName) |
| | 0 | 68 | | => new AuthenticationException($"Cannot authenticate credentials with {fullName}"); |
| | | 69 | | |
| | | 70 | | public static ArgumentException SeekOutsideBufferRange(long index, long inclusiveRangeStart, long exclusiveRange |
| | 0 | 71 | | => new ArgumentException($"Tried to seek ouside buffer range. Gave index {index}, range is [{inclusiveRangeS |
| | | 72 | | |
| | | 73 | | public static ArgumentException VersionNotSupported(string paramName) |
| | 0 | 74 | | => new ArgumentException($"The version specified by {paramName} is not supported by this library."); |
| | | 75 | | |
| | | 76 | | public static RequestFailedException ClientRequestIdMismatch(ClientDiagnostics clientDiagnostics, Response respo |
| | 0 | 77 | | => clientDiagnostics.CreateRequestFailedExceptionWithContent( |
| | 0 | 78 | | response, |
| | 0 | 79 | | $"Response x-ms-client-request-id '{echo}' does not match the original expected request id, '{original}' |
| | | 80 | | |
| | | 81 | | public static void VerifyHttpsTokenAuth(Uri uri) |
| | | 82 | | { |
| | 100 | 83 | | if (uri.Scheme != Constants.Https) |
| | | 84 | | { |
| | 28 | 85 | | throw new ArgumentException("Cannot use TokenCredential without HTTPS."); |
| | | 86 | | } |
| | 72 | 87 | | } |
| | | 88 | | |
| | | 89 | | public static class ClientSideEncryption |
| | | 90 | | { |
| | | 91 | | public static InvalidOperationException ClientSideEncryptionVersionNotSupported(string versionString = defau |
| | 0 | 92 | | => new InvalidOperationException("This library does not support the given version of client-side encrypt |
| | 0 | 93 | | versionString == default ? "" : $" Version ID = {versionString}"); |
| | | 94 | | |
| | | 95 | | public static InvalidOperationException TypeNotSupported(Type type) |
| | 0 | 96 | | => new InvalidOperationException( |
| | 0 | 97 | | $"Client-side encryption is not supported for type \"{type.FullName}\". " + |
| | 0 | 98 | | "Please use a supported client type or create this client without specifying client-side encryption |
| | | 99 | | |
| | | 100 | | public static InvalidOperationException MissingRequiredEncryptionResources(params string[] resourceNames) |
| | 0 | 101 | | => new InvalidOperationException("Cannot encrypt without specifying " + string.Join(",", resourceNames.A |
| | | 102 | | |
| | | 103 | | public static ArgumentException KeyNotFound(string keyId) |
| | 0 | 104 | | => new ArgumentException($"Resolution of id {keyId} returned null."); |
| | | 105 | | |
| | | 106 | | public static ArgumentException BadEncryptionAgent(string agent) |
| | 0 | 107 | | => new ArgumentException("Invalid Encryption Agent. This version of the client library does not understa |
| | 0 | 108 | | $"the Encryption Agent protocol \"{agent}\" set on the blob."); |
| | | 109 | | |
| | | 110 | | public static ArgumentException BadEncryptionAlgorithm(string algorithm) |
| | 0 | 111 | | => new ArgumentException($"Invalid Encryption Algorithm \"{algorithm}\" found on the resource. This vers |
| | 0 | 112 | | "library does not support the given encryption algorithm."); |
| | | 113 | | |
| | | 114 | | public static InvalidOperationException MissingEncryptionMetadata(string field) |
| | 0 | 115 | | => new InvalidOperationException($"Missing field \"{field}\" in encryption metadata"); |
| | | 116 | | } |
| | | 117 | | } |
| | | 118 | | } |