| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using Azure.Storage.Cryptography; |
| | 6 | |
|
| | 7 | | #pragma warning disable SA1402 // File may only contain a single type |
| | 8 | |
|
| | 9 | | namespace Azure.Storage.Queues.Specialized |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Contains Queues-specific options for client-side encryption. |
| | 13 | | /// </summary> |
| | 14 | | public class QueueClientSideEncryptionOptions : ClientSideEncryptionOptions |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Initializes a new instance of the <see cref="QueueClientSideEncryptionOptions"/> class. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="version">The version of clientside encryption to use.</param> |
| | 20 | | public QueueClientSideEncryptionOptions(ClientSideEncryptionVersion version) : base(version) |
| | 21 | | { |
| | 22 | | } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Event when failure to decrypt a message occurs. |
| | 26 | | /// </summary> |
| | 27 | | public event EventHandler<ClientSideDecryptionFailureEventArgs> DecryptionFailed; |
| | 28 | |
|
| | 29 | | internal bool UsingDecryptionFailureHandler => DecryptionFailed.GetInvocationList().Length > 0; |
| | 30 | |
|
| | 31 | | internal void OnDecryptionFailed(object message, Exception e) |
| | 32 | | { |
| | 33 | | DecryptionFailed?.Invoke(message, new ClientSideDecryptionFailureEventArgs(e)); |
| | 34 | | } |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Clones the given <see cref="ClientSideEncryptionOptions"/> as an instance of |
| | 38 | | /// <see cref="QueueClientSideEncryptionOptions"/>. If the given instance is also a |
| | 39 | | /// <see cref="QueueClientSideEncryptionOptions"/>, this clones it's specialty data as well. |
| | 40 | | /// </summary> |
| | 41 | | /// <returns></returns> |
| | 42 | | internal static QueueClientSideEncryptionOptions CloneFrom(ClientSideEncryptionOptions options) |
| | 43 | | { |
| | 44 | | if (options == default) |
| | 45 | | { |
| | 46 | | return default; |
| | 47 | | } |
| | 48 | | var newOptions = new QueueClientSideEncryptionOptions(options.EncryptionVersion); |
| | 49 | | ClientSideEncryptionOptionsExtensions.CopyOptions(options, newOptions); |
| | 50 | | if (options is QueueClientSideEncryptionOptions queueOptions) |
| | 51 | | { |
| | 52 | | newOptions.DecryptionFailed = queueOptions.DecryptionFailed; |
| | 53 | | } |
| | 54 | | return newOptions; |
| | 55 | | } |
| | 56 | | } |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Event args for when a queue message decryption fails. |
| | 60 | | /// </summary> |
| | 61 | | public class ClientSideDecryptionFailureEventArgs |
| | 62 | | { |
| | 63 | | /// <summary> |
| | 64 | | /// The exception thrown. |
| | 65 | | /// </summary> |
| 0 | 66 | | public Exception Exception { get; } |
| | 67 | |
|
| 0 | 68 | | internal ClientSideDecryptionFailureEventArgs(Exception exception) |
| | 69 | | { |
| 0 | 70 | | Exception = exception; |
| 0 | 71 | | } |
| | 72 | | } |
| | 73 | | } |