| | | 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 a wrap operation. |
| | | 10 | | /// </summary> |
| | | 11 | | public class WrapResult : IJsonDeserializable |
| | | 12 | | { |
| | | 13 | | private const string KeyIdPropertyName = "kid"; |
| | | 14 | | private const string EncryptedKeyPropertyName = "value"; |
| | | 15 | | |
| | 36 | 16 | | internal WrapResult() |
| | | 17 | | { |
| | 36 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets the <see cref="KeyProperties.Id"/> of the <see cref="KeyVaultKey"/> used to wrap the <see cref="Encrypt |
| | | 22 | | /// </summary> |
| | 48 | 23 | | public string KeyId { get; internal set; } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets the wrapped key. |
| | | 27 | | /// </summary> |
| | 68 | 28 | | public byte[] EncryptedKey { get; internal set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets the <see cref="KeyWrapAlgorithm"/> used. This must be stored alongside the <see cref="EncryptedKey"/> a |
| | | 32 | | /// </summary> |
| | 48 | 33 | | public KeyWrapAlgorithm Algorithm { get; internal set; } |
| | | 34 | | |
| | | 35 | | void IJsonDeserializable.ReadProperties(JsonElement json) |
| | | 36 | | { |
| | 168 | 37 | | foreach (JsonProperty prop in json.EnumerateObject()) |
| | | 38 | | { |
| | 56 | 39 | | switch (prop.Name) |
| | | 40 | | { |
| | | 41 | | case KeyIdPropertyName: |
| | 28 | 42 | | KeyId = prop.Value.GetString(); |
| | 28 | 43 | | break; |
| | | 44 | | case EncryptedKeyPropertyName: |
| | 28 | 45 | | EncryptedKey = Base64Url.Decode(prop.Value.GetString()); |
| | | 46 | | break; |
| | | 47 | | } |
| | | 48 | | } |
| | 28 | 49 | | } |
| | | 50 | | } |
| | | 51 | | } |