| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.ComponentModel; |
| | 7 | |
|
| | 8 | | namespace Azure.Security.KeyVault.Keys |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Model factory that enables mocking for the Key Vault Keys library. |
| | 12 | | /// </summary> |
| | 13 | | public static class KeyModelFactory |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Initializes a new instance of the <see cref="Keys.JsonWebKey"/> for mocking purposes. |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="keyType">Sets the <see cref="Keys.JsonWebKey.KeyType"/> property.</param> |
| | 19 | | /// <param name="id">Sets the <see cref="Keys.JsonWebKey.Id"/> property.</param> |
| | 20 | | /// <param name="keyOps">Sets the <see cref="Keys.JsonWebKey.KeyOps"/> property.</param> |
| | 21 | | /// <param name="curveName">Sets the <see cref="Keys.JsonWebKey.CurveName"/> property.</param> |
| | 22 | | /// <param name="d">Sets the <see cref="Keys.JsonWebKey.D"/> property.</param> |
| | 23 | | /// <param name="dp">Sets the <see cref="Keys.JsonWebKey.DP"/> property.</param> |
| | 24 | | /// <param name="dq">Sets the <see cref="Keys.JsonWebKey.DQ"/> property.</param> |
| | 25 | | /// <param name="e">Sets the <see cref="Keys.JsonWebKey.E"/> property.</param> |
| | 26 | | /// <param name="k">Sets the <see cref="Keys.JsonWebKey.K"/> property.</param> |
| | 27 | | /// <param name="n">Sets the <see cref="Keys.JsonWebKey.N"/> property.</param> |
| | 28 | | /// <param name="p">Sets the <see cref="Keys.JsonWebKey.P"/> property.</param> |
| | 29 | | /// <param name="q">Sets the <see cref="Keys.JsonWebKey.Q"/> property.</param> |
| | 30 | | /// <param name="qi">Sets the <see cref="Keys.JsonWebKey.QI"/> property.</param> |
| | 31 | | /// <param name="t">Sets the <see cref="Keys.JsonWebKey.T"/> property.</param> |
| | 32 | | /// <param name="x">Sets the <see cref="Keys.JsonWebKey.X"/> property.</param> |
| | 33 | | /// <param name="y">Sets the <see cref="Keys.JsonWebKey.Y"/> property.</param> |
| | 34 | | /// <returns>A new instance of the <see cref="Keys.JsonWebKey"/> for mocking purposes.</returns> |
| | 35 | | public static JsonWebKey JsonWebKey( |
| | 36 | | KeyType keyType, |
| | 37 | | string id = default, |
| | 38 | | IEnumerable<KeyOperation> keyOps = default, |
| | 39 | | KeyCurveName? curveName = default, |
| | 40 | | byte[] d = default, |
| | 41 | | byte[] dp = default, |
| | 42 | | byte[] dq = default, |
| | 43 | | byte[] e = default, |
| | 44 | | byte[] k = default, |
| | 45 | | byte[] n = default, |
| | 46 | | byte[] p = default, |
| | 47 | | byte[] q = default, |
| | 48 | | byte[] qi = default, |
| | 49 | | byte[] t = default, |
| | 50 | | byte[] x = default, |
| | 51 | | byte[] y = default) |
| | 52 | | { |
| 20 | 53 | | return new JsonWebKey(keyOps) |
| 20 | 54 | | { |
| 20 | 55 | | KeyType = keyType, |
| 20 | 56 | | Id = id, |
| 20 | 57 | | CurveName = curveName, |
| 20 | 58 | | D = d, |
| 20 | 59 | | DP = dp, |
| 20 | 60 | | DQ = dq, |
| 20 | 61 | | E = e, |
| 20 | 62 | | K = k, |
| 20 | 63 | | N = n, |
| 20 | 64 | | P = p, |
| 20 | 65 | | Q = q, |
| 20 | 66 | | QI = qi, |
| 20 | 67 | | T = t, |
| 20 | 68 | | X = x, |
| 20 | 69 | | Y = y, |
| 20 | 70 | | }; |
| | 71 | | } |
| | 72 | |
|
| | 73 | | /// <summary> |
| | 74 | | /// Initializes a new instance of the <see cref="Keys.KeyProperties"/> for mocking purposes. |
| | 75 | | /// </summary> |
| | 76 | | /// <param name="id">Sets the <see cref="Keys.KeyProperties.Id"/> property.</param> |
| | 77 | | /// <param name="vaultUri">Sets the <see cref="Keys.KeyProperties.VaultUri"/> property.</param> |
| | 78 | | /// <param name="name">Sets the <see cref="Keys.KeyProperties.Name"/> property.</param> |
| | 79 | | /// <param name="version">Sets the <see cref="Keys.KeyProperties.Version"/> property.</param> |
| | 80 | | /// <param name="managed">Sets the <see cref="Keys.KeyProperties.Managed"/> property.</param> |
| | 81 | | /// <param name="createdOn">Sets the <see cref="Keys.KeyProperties.CreatedOn"/> property.</param> |
| | 82 | | /// <param name="updatedOn">Sets the <see cref="Keys.KeyProperties.UpdatedOn"/> property.</param> |
| | 83 | | /// <param name="recoveryLevel">Sets the <see cref="Keys.KeyProperties.RecoveryLevel"/> property.</param> |
| | 84 | | /// <returns>A new instance of the <see cref="Keys.KeyProperties"/> for mocking purposes.</returns> |
| | 85 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 86 | | public static KeyProperties KeyProperties( |
| | 87 | | Uri id, |
| | 88 | | Uri vaultUri, |
| | 89 | | string name, |
| | 90 | | string version, |
| | 91 | | bool managed, |
| | 92 | | DateTimeOffset? createdOn, |
| | 93 | | DateTimeOffset? updatedOn, |
| 0 | 94 | | string recoveryLevel) => KeyProperties( |
| 0 | 95 | | id, |
| 0 | 96 | | vaultUri, |
| 0 | 97 | | name, |
| 0 | 98 | | version, |
| 0 | 99 | | managed, |
| 0 | 100 | | createdOn, |
| 0 | 101 | | updatedOn, |
| 0 | 102 | | recoveryLevel, |
| 0 | 103 | | default); |
| | 104 | |
|
| | 105 | | /// <summary> |
| | 106 | | /// Initializes a new instance of the <see cref="Keys.KeyProperties"/> for mocking purposes. |
| | 107 | | /// </summary> |
| | 108 | | /// <param name="id">Sets the <see cref="Keys.KeyProperties.Id"/> property.</param> |
| | 109 | | /// <param name="vaultUri">Sets the <see cref="Keys.KeyProperties.VaultUri"/> property.</param> |
| | 110 | | /// <param name="name">Sets the <see cref="Keys.KeyProperties.Name"/> property.</param> |
| | 111 | | /// <param name="version">Sets the <see cref="Keys.KeyProperties.Version"/> property.</param> |
| | 112 | | /// <param name="managed">Sets the <see cref="Keys.KeyProperties.Managed"/> property.</param> |
| | 113 | | /// <param name="createdOn">Sets the <see cref="Keys.KeyProperties.CreatedOn"/> property.</param> |
| | 114 | | /// <param name="updatedOn">Sets the <see cref="Keys.KeyProperties.UpdatedOn"/> property.</param> |
| | 115 | | /// <param name="recoveryLevel">Sets the <see cref="Keys.KeyProperties.RecoveryLevel"/> property.</param> |
| | 116 | | /// <param name="recoverableDays">Sets the <see cref="Keys.KeyProperties.RecoverableDays"/> property.</param> |
| | 117 | | /// <returns>A new instance of the <see cref="Keys.KeyProperties"/> for mocking purposes.</returns> |
| | 118 | | public static KeyProperties KeyProperties( |
| | 119 | | Uri id = default, |
| | 120 | | Uri vaultUri = default, |
| | 121 | | string name = default, |
| | 122 | | string version = default, |
| | 123 | | bool managed = default, |
| | 124 | | DateTimeOffset? createdOn = default, |
| | 125 | | DateTimeOffset? updatedOn = default, |
| | 126 | | string recoveryLevel = default, |
| | 127 | | int? recoverableDays = default) |
| | 128 | | { |
| 0 | 129 | | return new KeyProperties |
| 0 | 130 | | { |
| 0 | 131 | | Id = id, |
| 0 | 132 | | VaultUri = vaultUri, |
| 0 | 133 | | Name = name, |
| 0 | 134 | | Version = version, |
| 0 | 135 | | Managed = managed, |
| 0 | 136 | | CreatedOn = createdOn, |
| 0 | 137 | | UpdatedOn = updatedOn, |
| 0 | 138 | | RecoveryLevel = recoveryLevel, |
| 0 | 139 | | RecoverableDays = recoverableDays, |
| 0 | 140 | | }; |
| | 141 | | } |
| | 142 | |
|
| | 143 | | /// <summary> |
| | 144 | | /// Initializes a new instance of the <see cref="Keys.KeyVaultKey"/> for mocking purposes. |
| | 145 | | /// </summary> |
| | 146 | | /// <param name="properties">Sets the <see cref="Keys.KeyVaultKey.Properties"/> property, which provides the <se |
| | 147 | | /// <param name="key">Sets the <see cref="Keys.KeyVaultKey.Key"/> property, which provides the <see cref="Keys.K |
| | 148 | | /// <returns>A new instance of the <see cref="Keys.KeyVaultKey"/> for mocking purposes.</returns> |
| 0 | 149 | | public static KeyVaultKey KeyVaultKey(KeyProperties properties, JsonWebKey key) => new KeyVaultKey(properties) |
| 0 | 150 | | { |
| 0 | 151 | | Key = key, |
| 0 | 152 | | }; |
| | 153 | |
|
| | 154 | | /// <summary> |
| | 155 | | /// Initializes a new instance of the <see cref="Keys.DeletedKey"/> for mocking purposes. |
| | 156 | | /// </summary> |
| | 157 | | /// <param name="properties">Sets the <see cref="Keys.KeyVaultKey.Properties"/> property, which provides the <se |
| | 158 | | /// <param name="key">Sets the <see cref="Keys.KeyVaultKey.Key"/> property, which provides the <see cref="Keys.K |
| | 159 | | /// <param name="recoveryId">Sets the <see cref="Keys.DeletedKey.RecoveryId"/> property.</param> |
| | 160 | | /// <param name="deletedOn">Sets the <see cref="Keys.DeletedKey.DeletedOn"/> property.</param> |
| | 161 | | /// <param name="scheduledPurgeDate">Sets the <see cref="Keys.DeletedKey.ScheduledPurgeDate"/> property.</param> |
| | 162 | | /// <returns>A new instance of the <see cref="Keys.DeletedKey"/> for mocking purposes.</returns> |
| 0 | 163 | | public static DeletedKey DeletedKey(KeyProperties properties, JsonWebKey key, Uri recoveryId = default, DateTime |
| 0 | 164 | | { |
| 0 | 165 | | Key = key, |
| 0 | 166 | | RecoveryId = recoveryId, |
| 0 | 167 | | DeletedOn = deletedOn, |
| 0 | 168 | | ScheduledPurgeDate = scheduledPurgeDate, |
| 0 | 169 | | }; |
| | 170 | | } |
| | 171 | | } |