| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System.Text.Json; |
| | | 5 | | |
| | | 6 | | namespace Azure.Security.KeyVault.Keys.Cryptography |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Represents information about an unwrap operation. |
| | | 10 | | /// </summary> |
| | | 11 | | public class UnwrapResult : IJsonDeserializable |
| | | 12 | | { |
| | | 13 | | private const string KeyIdPropertyName = "kid"; |
| | | 14 | | private const string KeyPropertyName = "value"; |
| | | 15 | | |
| | 40 | 16 | | internal UnwrapResult() |
| | | 17 | | { |
| | 40 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets the <see cref="KeyProperties.Id"/> of the <see cref="Key"/> used to uwrap. |
| | | 22 | | /// </summary> |
| | 52 | 23 | | public string KeyId { get; internal set; } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets the unwrapped key. |
| | | 27 | | /// </summary> |
| | 72 | 28 | | public byte[] Key { get; internal set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets the algorithm used. |
| | | 32 | | /// </summary> |
| | 52 | 33 | | public KeyWrapAlgorithm Algorithm { get; internal set; } |
| | | 34 | | |
| | | 35 | | void IJsonDeserializable.ReadProperties(JsonElement json) |
| | | 36 | | { |
| | 216 | 37 | | foreach (JsonProperty prop in json.EnumerateObject()) |
| | | 38 | | { |
| | 72 | 39 | | switch (prop.Name) |
| | | 40 | | { |
| | | 41 | | case KeyIdPropertyName: |
| | 36 | 42 | | KeyId = prop.Value.GetString(); |
| | 36 | 43 | | break; |
| | | 44 | | case KeyPropertyName: |
| | 36 | 45 | | Key = Base64Url.Decode(prop.Value.GetString()); |
| | | 46 | | break; |
| | | 47 | | } |
| | | 48 | | } |
| | 36 | 49 | | } |
| | | 50 | | } |
| | | 51 | | } |