|   |  | 1 |  | // Copyright (c) Microsoft Corporation. All rights reserved. | 
|   |  | 2 |  | // Licensed under the MIT License. | 
|   |  | 3 |  |  | 
|   |  | 4 |  | using System; | 
|   |  | 5 |  | using System.Globalization; | 
|   |  | 6 |  |  | 
|   |  | 7 |  | namespace Azure.Security.KeyVault | 
|   |  | 8 |  | { | 
|   |  | 9 |  |     internal struct KeyVaultIdentifier | 
|   |  | 10 |  |     { | 
|   |  | 11 |  |         public const string SecretsCollection = "secrets"; | 
|   |  | 12 |  |         public const string KeysCollection = "keys"; | 
|   |  | 13 |  |         public const string CertificatesCollection = "certificates"; | 
|   |  | 14 |  |  | 
|   | 0 | 15 |  |         public Uri Id { get; private set; } | 
|   |  | 16 |  |  | 
|   | 0 | 17 |  |         public Uri VaultUri { get; set; } | 
|   |  | 18 |  |  | 
|   | 0 | 19 |  |         public string Name { get; set; } | 
|   |  | 20 |  |  | 
|   | 0 | 21 |  |         public string Collection { get; set; } | 
|   |  | 22 |  |  | 
|   | 0 | 23 |  |         public string Version { get; set; } | 
|   |  | 24 |  |  | 
|   |  | 25 |  |         public static KeyVaultIdentifier Parse(string collection, Uri id) | 
|   |  | 26 |  |         { | 
|   | 0 | 27 |  |             KeyVaultIdentifier identifier = Parse(id); | 
|   |  | 28 |  |  | 
|   | 0 | 29 |  |             if (!string.Equals(identifier.Collection, collection + "/", StringComparison.OrdinalIgnoreCase)) | 
|   | 0 | 30 |  |                 throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ObjectIdentifier: {0}.  | 
|   |  | 31 |  |  | 
|   | 0 | 32 |  |             return identifier; | 
|   |  | 33 |  |         } | 
|   |  | 34 |  |  | 
|   |  | 35 |  |         public static KeyVaultIdentifier Parse(Uri id) | 
|   |  | 36 |  |         { | 
|   |  | 37 |  |             // We expect an identifier with either 3 or 4 segments: host + collection + name [+ version] | 
|   | 0 | 38 |  |             if (id.Segments.Length != 3 && id.Segments.Length != 4) | 
|   | 0 | 39 |  |                 throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ObjectIdentifier: {0}.  | 
|   |  | 40 |  |  | 
|   | 0 | 41 |  |             KeyVaultIdentifier identifier = new KeyVaultIdentifier | 
|   | 0 | 42 |  |             { | 
|   | 0 | 43 |  |  | 
|   | 0 | 44 |  |                 Id = id, | 
|   | 0 | 45 |  |                 VaultUri = new Uri($"{id.Scheme}://{id.Authority}"), | 
|   | 0 | 46 |  |                 Collection = id.Segments[1].Trim('/'), | 
|   | 0 | 47 |  |                 Name = id.Segments[2].Trim('/'), | 
|   | 0 | 48 |  |                 Version = (id.Segments.Length == 4) ? id.Segments[3].TrimEnd('/') : null | 
|   | 0 | 49 |  |             }; | 
|   |  | 50 |  |  | 
|   | 0 | 51 |  |             return identifier; | 
|   |  | 52 |  |         } | 
|   |  | 53 |  |     } | 
|   |  | 54 |  | } |