| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Text.Json; |
| | 6 | |
|
| | 7 | | namespace Azure.Security.KeyVault.Certificates |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Properties of a <see cref="CertificateIssuer"/>. |
| | 11 | | /// </summary> |
| | 12 | | public class IssuerProperties : IJsonDeserializable, IJsonSerializable |
| | 13 | | { |
| | 14 | | private const string IdPropertyName = "id"; |
| | 15 | | private const string ProviderPropertyName = "provider"; |
| | 16 | |
|
| 2 | 17 | | private static readonly JsonEncodedText s_providerPropertyNameBytes = JsonEncodedText.Encode(ProviderPropertyNam |
| | 18 | |
|
| 68 | 19 | | internal IssuerProperties() |
| | 20 | | { |
| 68 | 21 | | } |
| | 22 | |
|
| 32 | 23 | | internal IssuerProperties(string name) |
| | 24 | | { |
| 32 | 25 | | Name = name; |
| 32 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Gets the identifier of the certificate issuer. |
| | 30 | | /// </summary> |
| 468 | 31 | | public Uri Id { get; internal set; } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Gets the name of the certificate issuer. |
| | 35 | | /// </summary> |
| 176 | 36 | | public string Name { get; internal set; } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Gets or sets the provider name of the certificate issuer. |
| | 40 | | /// </summary> |
| 228 | 41 | | public string Provider { get; set; } |
| | 42 | |
|
| | 43 | | void IJsonDeserializable.ReadProperties(JsonElement json) |
| | 44 | | { |
| 144 | 45 | | foreach (JsonProperty prop in json.EnumerateObject()) |
| | 46 | | { |
| 48 | 47 | | ReadProperty(prop); |
| | 48 | | } |
| 24 | 49 | | } |
| | 50 | |
|
| | 51 | | internal void ReadProperty(JsonProperty prop) |
| | 52 | | { |
| 118 | 53 | | switch (prop.Name) |
| | 54 | | { |
| | 55 | | case IdPropertyName: |
| 58 | 56 | | var id = prop.Value.GetString(); |
| 58 | 57 | | Id = new Uri(id); |
| 58 | 58 | | Name = Id.Segments[Id.Segments.Length - 1]; |
| 58 | 59 | | break; |
| | 60 | |
|
| | 61 | | case ProviderPropertyName: |
| 60 | 62 | | Provider = prop.Value.GetString(); |
| | 63 | | break; |
| | 64 | | } |
| 60 | 65 | | } |
| | 66 | |
|
| 0 | 67 | | void IJsonSerializable.WriteProperties(Utf8JsonWriter json) => WriteProperties(json); |
| | 68 | |
|
| | 69 | | internal void WriteProperties(Utf8JsonWriter json) |
| | 70 | | { |
| 28 | 71 | | if (!string.IsNullOrEmpty(Provider)) |
| | 72 | | { |
| 28 | 73 | | json.WriteString(s_providerPropertyNameBytes, Provider); |
| | 74 | | } |
| 28 | 75 | | } |
| | 76 | | } |
| | 77 | | } |