@azure/keyvault-keys 4.10.1-alpha.20250717.1 → 4.10.1-alpha.20250730.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/browser/cryptography/remoteCryptographyProvider.js +34 -11
  2. package/dist/browser/cryptography/remoteCryptographyProvider.js.map +1 -1
  3. package/dist/browser/cryptographyClient.js +12 -5
  4. package/dist/browser/cryptographyClient.js.map +1 -1
  5. package/dist/browser/generated/src/api/keyVaultContext.js +12 -9
  6. package/dist/browser/generated/src/api/keyVaultContext.js.map +1 -1
  7. package/dist/browser/generated/src/api/operations.js +229 -78
  8. package/dist/browser/generated/src/api/operations.js.map +1 -1
  9. package/dist/browser/generated/src/keyVaultClient.js +8 -3
  10. package/dist/browser/generated/src/keyVaultClient.js.map +1 -1
  11. package/dist/browser/generated/src/static-helpers/pagingHelpers.js +31 -50
  12. package/dist/browser/generated/src/static-helpers/pagingHelpers.js.map +1 -1
  13. package/dist/browser/generated/src/static-helpers/urlTemplate.js +2 -2
  14. package/dist/browser/generated/src/static-helpers/urlTemplate.js.map +1 -1
  15. package/dist/browser/identifier.js +4 -1
  16. package/dist/browser/identifier.js.map +1 -1
  17. package/dist/browser/index.js +43 -29
  18. package/dist/browser/index.js.map +1 -1
  19. package/dist/browser/lro/delete/operation.js +3 -0
  20. package/dist/browser/lro/delete/operation.js.map +1 -1
  21. package/dist/browser/lro/delete/poller.js +4 -1
  22. package/dist/browser/lro/delete/poller.js.map +1 -1
  23. package/dist/browser/lro/keyVaultKeyPoller.js +6 -8
  24. package/dist/browser/lro/keyVaultKeyPoller.js.map +1 -1
  25. package/dist/browser/lro/recover/operation.js +5 -2
  26. package/dist/browser/lro/recover/operation.js.map +1 -1
  27. package/dist/browser/lro/recover/poller.js +4 -1
  28. package/dist/browser/lro/recover/poller.js.map +1 -1
  29. package/dist/browser/transformations.js +30 -41
  30. package/dist/browser/transformations.js.map +1 -1
  31. package/dist/commonjs/cryptography/aesCryptographyProvider.js +25 -25
  32. package/dist/commonjs/cryptography/aesCryptographyProvider.js.map +1 -1
  33. package/dist/commonjs/cryptography/remoteCryptographyProvider.js +34 -11
  34. package/dist/commonjs/cryptography/remoteCryptographyProvider.js.map +1 -1
  35. package/dist/commonjs/cryptography/rsaCryptographyProvider.js +39 -36
  36. package/dist/commonjs/cryptography/rsaCryptographyProvider.js.map +1 -1
  37. package/dist/commonjs/cryptographyClient.js +12 -5
  38. package/dist/commonjs/cryptographyClient.js.map +1 -1
  39. package/dist/commonjs/generated/src/api/keyVaultContext.js +12 -9
  40. package/dist/commonjs/generated/src/api/keyVaultContext.js.map +1 -1
  41. package/dist/commonjs/generated/src/api/operations.js +229 -78
  42. package/dist/commonjs/generated/src/api/operations.js.map +1 -1
  43. package/dist/commonjs/generated/src/keyVaultClient.js +8 -3
  44. package/dist/commonjs/generated/src/keyVaultClient.js.map +1 -1
  45. package/dist/commonjs/generated/src/static-helpers/pagingHelpers.js +31 -50
  46. package/dist/commonjs/generated/src/static-helpers/pagingHelpers.js.map +1 -1
  47. package/dist/commonjs/generated/src/static-helpers/urlTemplate.js +2 -2
  48. package/dist/commonjs/generated/src/static-helpers/urlTemplate.js.map +1 -1
  49. package/dist/commonjs/identifier.js +4 -1
  50. package/dist/commonjs/identifier.js.map +1 -1
  51. package/dist/commonjs/index.js +43 -29
  52. package/dist/commonjs/index.js.map +1 -1
  53. package/dist/commonjs/lro/delete/operation.js +3 -0
  54. package/dist/commonjs/lro/delete/operation.js.map +1 -1
  55. package/dist/commonjs/lro/delete/poller.js +4 -1
  56. package/dist/commonjs/lro/delete/poller.js.map +1 -1
  57. package/dist/commonjs/lro/keyVaultKeyPoller.js +6 -8
  58. package/dist/commonjs/lro/keyVaultKeyPoller.js.map +1 -1
  59. package/dist/commonjs/lro/recover/operation.js +5 -2
  60. package/dist/commonjs/lro/recover/operation.js.map +1 -1
  61. package/dist/commonjs/lro/recover/poller.js +4 -1
  62. package/dist/commonjs/lro/recover/poller.js.map +1 -1
  63. package/dist/commonjs/transformations.js +30 -41
  64. package/dist/commonjs/transformations.js.map +1 -1
  65. package/dist/commonjs/tsdoc-metadata.json +11 -11
  66. package/dist/esm/cryptography/aesCryptographyProvider.js +25 -25
  67. package/dist/esm/cryptography/aesCryptographyProvider.js.map +1 -1
  68. package/dist/esm/cryptography/remoteCryptographyProvider.js +34 -11
  69. package/dist/esm/cryptography/remoteCryptographyProvider.js.map +1 -1
  70. package/dist/esm/cryptography/rsaCryptographyProvider.js +39 -36
  71. package/dist/esm/cryptography/rsaCryptographyProvider.js.map +1 -1
  72. package/dist/esm/cryptographyClient.js +12 -5
  73. package/dist/esm/cryptographyClient.js.map +1 -1
  74. package/dist/esm/generated/src/api/keyVaultContext.js +12 -9
  75. package/dist/esm/generated/src/api/keyVaultContext.js.map +1 -1
  76. package/dist/esm/generated/src/api/operations.js +229 -78
  77. package/dist/esm/generated/src/api/operations.js.map +1 -1
  78. package/dist/esm/generated/src/keyVaultClient.js +8 -3
  79. package/dist/esm/generated/src/keyVaultClient.js.map +1 -1
  80. package/dist/esm/generated/src/static-helpers/pagingHelpers.js +31 -50
  81. package/dist/esm/generated/src/static-helpers/pagingHelpers.js.map +1 -1
  82. package/dist/esm/generated/src/static-helpers/urlTemplate.js +2 -2
  83. package/dist/esm/generated/src/static-helpers/urlTemplate.js.map +1 -1
  84. package/dist/esm/identifier.js +4 -1
  85. package/dist/esm/identifier.js.map +1 -1
  86. package/dist/esm/index.js +43 -29
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/lro/delete/operation.js +3 -0
  89. package/dist/esm/lro/delete/operation.js.map +1 -1
  90. package/dist/esm/lro/delete/poller.js +4 -1
  91. package/dist/esm/lro/delete/poller.js.map +1 -1
  92. package/dist/esm/lro/keyVaultKeyPoller.js +6 -8
  93. package/dist/esm/lro/keyVaultKeyPoller.js.map +1 -1
  94. package/dist/esm/lro/recover/operation.js +5 -2
  95. package/dist/esm/lro/recover/operation.js.map +1 -1
  96. package/dist/esm/lro/recover/poller.js +4 -1
  97. package/dist/esm/lro/recover/poller.js.map +1 -1
  98. package/dist/esm/transformations.js +30 -41
  99. package/dist/esm/transformations.js.map +1 -1
  100. package/package.json +2 -2
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { __asyncGenerator, __asyncValues, __await } from "tslib";
4
3
  import { parseKeyVaultKeyIdentifier } from "./identifier.js";
5
4
  /**
6
5
  * @internal
@@ -58,7 +57,12 @@ export function getDeletedKeyFromDeletedKeyItem(keyItem) {
58
57
  },
59
58
  id: keyItem.kid,
60
59
  name: commonProperties.name,
61
- properties: Object.assign(Object.assign({}, commonProperties), { recoveryId: keyItem.recoveryId, scheduledPurgeDate: keyItem.scheduledPurgeDate, deletedOn: keyItem.deletedDate }),
60
+ properties: {
61
+ ...commonProperties,
62
+ recoveryId: keyItem.recoveryId,
63
+ scheduledPurgeDate: keyItem.scheduledPurgeDate,
64
+ deletedOn: keyItem.deletedDate,
65
+ },
62
66
  };
63
67
  }
64
68
  /**
@@ -70,15 +74,15 @@ export function getKeyPropertiesFromKeyItem(keyItem) {
70
74
  const attributes = keyItem.attributes || {};
71
75
  const resultObject = {
72
76
  createdOn: attributes.created,
73
- enabled: attributes === null || attributes === void 0 ? void 0 : attributes.enabled,
74
- expiresOn: attributes === null || attributes === void 0 ? void 0 : attributes.expires,
77
+ enabled: attributes?.enabled,
78
+ expiresOn: attributes?.expires,
75
79
  id: keyItem.kid,
76
80
  managed: keyItem.managed,
77
81
  name: parsedId.name,
78
- notBefore: attributes === null || attributes === void 0 ? void 0 : attributes.notBefore,
79
- recoverableDays: attributes === null || attributes === void 0 ? void 0 : attributes.recoverableDays,
80
- recoveryLevel: attributes === null || attributes === void 0 ? void 0 : attributes.recoveryLevel,
81
- hsmPlatform: attributes === null || attributes === void 0 ? void 0 : attributes.hsmPlatform,
82
+ notBefore: attributes?.notBefore,
83
+ recoverableDays: attributes?.recoverableDays,
84
+ recoveryLevel: attributes?.recoveryLevel,
85
+ hsmPlatform: attributes?.hsmPlatform,
82
86
  tags: keyItem.tags,
83
87
  updatedOn: attributes.updated,
84
88
  vaultUrl: parsedId.vaultUrl,
@@ -102,12 +106,11 @@ function getNormalizedActionType(caseInsensitiveActionType) {
102
106
  */
103
107
  export const keyRotationTransformations = {
104
108
  propertiesToGenerated: function (parameters) {
105
- var _a;
106
109
  const policy = {
107
110
  attributes: {
108
111
  expiryTime: parameters.expiresIn,
109
112
  },
110
- lifetimeActions: (_a = parameters.lifetimeActions) === null || _a === void 0 ? void 0 : _a.map((action) => {
113
+ lifetimeActions: parameters.lifetimeActions?.map((action) => {
111
114
  const generatedAction = {
112
115
  action: { type: action.action },
113
116
  trigger: {},
@@ -124,18 +127,16 @@ export const keyRotationTransformations = {
124
127
  return policy;
125
128
  },
126
129
  generatedToPublic(generated) {
127
- var _a, _b, _c, _d;
128
130
  const policy = {
129
131
  id: generated.id,
130
- createdOn: (_a = generated.attributes) === null || _a === void 0 ? void 0 : _a.created,
131
- updatedOn: (_b = generated.attributes) === null || _b === void 0 ? void 0 : _b.updated,
132
- expiresIn: (_c = generated.attributes) === null || _c === void 0 ? void 0 : _c.expiryTime,
133
- lifetimeActions: (_d = generated.lifetimeActions) === null || _d === void 0 ? void 0 : _d.map((action) => {
134
- var _a, _b;
132
+ createdOn: generated.attributes?.created,
133
+ updatedOn: generated.attributes?.updated,
134
+ expiresIn: generated.attributes?.expiryTime,
135
+ lifetimeActions: generated.lifetimeActions?.map((action) => {
135
136
  return {
136
137
  action: getNormalizedActionType(action.action.type),
137
- timeAfterCreate: (_a = action.trigger) === null || _a === void 0 ? void 0 : _a.timeAfterCreate,
138
- timeBeforeExpiry: (_b = action.trigger) === null || _b === void 0 ? void 0 : _b.timeBeforeExpiry,
138
+ timeAfterCreate: action.trigger?.timeAfterCreate,
139
+ timeBeforeExpiry: action.trigger?.timeBeforeExpiry,
139
140
  };
140
141
  }),
141
142
  };
@@ -155,34 +156,22 @@ export function mapPagedAsyncIterable(options, operation, mapper) {
155
156
  let iter = undefined;
156
157
  return {
157
158
  async next() {
158
- iter !== null && iter !== void 0 ? iter : (iter = operation(Object.assign(Object.assign({}, options), { maxresults: undefined })));
159
+ iter ??= operation({ ...options, maxresults: undefined });
159
160
  const result = await iter.next();
160
- return Object.assign(Object.assign({}, result), { value: result.value && mapper(result.value) });
161
+ return {
162
+ ...result,
163
+ value: result.value && mapper(result.value),
164
+ };
161
165
  },
162
166
  [Symbol.asyncIterator]() {
163
167
  return this;
164
168
  },
165
- byPage(settings) {
166
- return __asyncGenerator(this, arguments, function* byPage_1() {
167
- var _a, e_1, _b, _c;
168
- // Pass the maxPageSize value to the underlying page operation
169
- const iteratorByPage = operation(Object.assign(Object.assign({}, options), { maxresults: settings === null || settings === void 0 ? void 0 : settings.maxPageSize })).byPage(settings);
170
- try {
171
- for (var _d = true, iteratorByPage_1 = __asyncValues(iteratorByPage), iteratorByPage_1_1; iteratorByPage_1_1 = yield __await(iteratorByPage_1.next()), _a = iteratorByPage_1_1.done, !_a; _d = true) {
172
- _c = iteratorByPage_1_1.value;
173
- _d = false;
174
- const page = _c;
175
- yield yield __await(page.map(mapper));
176
- }
177
- }
178
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
179
- finally {
180
- try {
181
- if (!_d && !_a && (_b = iteratorByPage_1.return)) yield __await(_b.call(iteratorByPage_1));
182
- }
183
- finally { if (e_1) throw e_1.error; }
184
- }
185
- });
169
+ async *byPage(settings) {
170
+ // Pass the maxPageSize value to the underlying page operation
171
+ const iteratorByPage = operation({ ...options, maxresults: settings?.maxPageSize }).byPage(settings);
172
+ for await (const page of iteratorByPage) {
173
+ yield page.map(mapper);
174
+ }
186
175
  },
187
176
  };
188
177
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transformations.js","sourceRoot":"","sources":["../../src/transformations.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAWlC,OAAO,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CACF,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAKnC,OAAiB,EACjB,SAAwE,EACxE,MAAkC;IAElC,IAAI,IAAI,GAA6C,SAAS,CAAC;IAC/D,OAAO;QACL,KAAK,CAAC,IAAI;YACR,IAAI,aAAJ,IAAI,cAAJ,IAAI,IAAJ,IAAI,GAAK,SAAS,iCAAM,OAAO,KAAE,UAAU,EAAE,SAAS,IAAG,EAAC;YAC1D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAEjC,uCACK,MAAM,KACT,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAC3C;QACJ,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QACM,MAAM,CAA4D,QAAoB;;;gBAC3F,8DAA8D;gBAC9D,MAAM,cAAc,GAAG,SAAS,iCAAM,OAAO,KAAE,UAAU,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,IAAG,CAAC,MAAM,CACxF,QAAQ,CACT,CAAC;;oBACF,KAAyB,eAAA,mBAAA,cAAA,cAAc,CAAA,oBAAA,6GAAE,CAAC;wBAAjB,8BAAc;wBAAd,WAAc;wBAA5B,MAAM,IAAI,KAAA,CAAA;wBACnB,oBAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA,CAAC;oBACzB,CAAC;;;;;;;;;YACH,CAAC;SAAA;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n DeletedKeyBundle,\n DeletedKeyItem,\n KeyRotationPolicy as GeneratedPolicy,\n KeyAttributes,\n KeyBundle,\n KeyItem,\n LifetimeActions,\n} from \"./generated/src/models/index.js\";\nimport { parseKeyVaultKeyIdentifier } from \"./identifier.js\";\nimport type {\n DeletedKey,\n KeyProperties,\n KeyRotationPolicy,\n KeyRotationPolicyAction,\n KeyRotationPolicyProperties,\n KeyVaultKey,\n} from \"./keysModels.js\";\nimport type { PagedAsyncIterableIterator, PageSettings } from \"./generated/src/index.js\";\nimport type { OperationOptions } from \"@azure-rest/core-client\";\n\n/**\n * @internal\n * Shapes the exposed {@link KeyVaultKey} based on either a received key bundle or deleted key bundle.\n */\nexport function getKeyFromKeyBundle(\n bundle: KeyBundle | DeletedKeyBundle,\n): KeyVaultKey | DeletedKey {\n const keyBundle = bundle as KeyBundle;\n const deletedKeyBundle = bundle as DeletedKeyBundle;\n\n const parsedId = parseKeyVaultKeyIdentifier(keyBundle.key!.kid!);\n\n const attributes: KeyAttributes = keyBundle.attributes || {};\n\n const resultObject: KeyVaultKey | DeletedKey = {\n key: keyBundle.key,\n id: keyBundle.key ? keyBundle.key.kid : undefined,\n name: parsedId.name,\n keyOperations: keyBundle.key ? keyBundle.key.keyOps : undefined,\n keyType: keyBundle.key ? keyBundle.key.kty : undefined,\n properties: {\n tags: keyBundle.tags,\n\n enabled: attributes.enabled,\n notBefore: attributes.notBefore,\n expiresOn: attributes.expires,\n createdOn: attributes.created,\n updatedOn: attributes.updated,\n recoverableDays: attributes.recoverableDays,\n recoveryLevel: attributes.recoveryLevel,\n exportable: attributes.exportable,\n releasePolicy: keyBundle.releasePolicy,\n hsmPlatform: attributes.hsmPlatform,\n\n vaultUrl: parsedId.vaultUrl,\n version: parsedId.version,\n name: parsedId.name,\n managed: keyBundle.managed,\n\n id: keyBundle.key ? keyBundle.key.kid : undefined,\n },\n };\n\n if (deletedKeyBundle.recoveryId) {\n (resultObject as any).properties.recoveryId = deletedKeyBundle.recoveryId;\n (resultObject as any).properties.scheduledPurgeDate = deletedKeyBundle.scheduledPurgeDate;\n (resultObject as any).properties.deletedOn = deletedKeyBundle.deletedDate;\n }\n\n if (attributes.attestation) {\n resultObject.properties.attestation = attributes.attestation;\n }\n\n return resultObject;\n}\n\n/**\n * @internal\n * Shapes the exposed {@link DeletedKey} based on a received KeyItem.\n */\nexport function getDeletedKeyFromDeletedKeyItem(keyItem: DeletedKeyItem): DeletedKey {\n const commonProperties = getKeyPropertiesFromKeyItem(keyItem);\n\n return {\n key: {\n kid: keyItem.kid,\n },\n id: keyItem.kid,\n name: commonProperties.name,\n properties: {\n ...commonProperties,\n recoveryId: keyItem.recoveryId,\n scheduledPurgeDate: keyItem.scheduledPurgeDate,\n deletedOn: keyItem.deletedDate,\n },\n };\n}\n\n/**\n * @internal\n * Shapes the exposed {@link KeyProperties} based on a received KeyItem.\n */\nexport function getKeyPropertiesFromKeyItem(keyItem: KeyItem): KeyProperties {\n const parsedId = parseKeyVaultKeyIdentifier(keyItem.kid!);\n const attributes = keyItem.attributes || {};\n\n const resultObject: KeyProperties = {\n createdOn: attributes.created,\n enabled: attributes?.enabled,\n expiresOn: attributes?.expires,\n id: keyItem.kid,\n managed: keyItem.managed,\n name: parsedId.name,\n notBefore: attributes?.notBefore,\n recoverableDays: attributes?.recoverableDays,\n recoveryLevel: attributes?.recoveryLevel,\n hsmPlatform: attributes?.hsmPlatform,\n tags: keyItem.tags,\n updatedOn: attributes.updated,\n vaultUrl: parsedId.vaultUrl,\n version: parsedId.version,\n };\n\n return resultObject;\n}\n\nconst actionTypeCaseInsensitiveMapping: Record<string, KeyRotationPolicyAction> = {\n rotate: \"Rotate\",\n notify: \"Notify\",\n};\n\nfunction getNormalizedActionType(caseInsensitiveActionType: string): KeyRotationPolicyAction {\n const result = actionTypeCaseInsensitiveMapping[caseInsensitiveActionType.toLowerCase()];\n if (result) {\n return result;\n }\n\n throw new Error(`Unrecognized action type: ${caseInsensitiveActionType}`);\n}\n\n/**\n * @internal\n */\nexport const keyRotationTransformations = {\n propertiesToGenerated: function (\n parameters: KeyRotationPolicyProperties,\n ): Partial<GeneratedPolicy> {\n const policy: GeneratedPolicy = {\n attributes: {\n expiryTime: parameters.expiresIn,\n },\n lifetimeActions: parameters.lifetimeActions?.map((action) => {\n const generatedAction: LifetimeActions = {\n action: { type: action.action },\n trigger: {},\n };\n\n if (action.timeAfterCreate) {\n generatedAction.trigger!.timeAfterCreate = action.timeAfterCreate;\n }\n\n if (action.timeBeforeExpiry) {\n generatedAction.trigger!.timeBeforeExpiry = action.timeBeforeExpiry;\n }\n\n return generatedAction;\n }),\n };\n return policy;\n },\n generatedToPublic(generated: GeneratedPolicy): KeyRotationPolicy {\n const policy: KeyRotationPolicy = {\n id: generated.id,\n createdOn: generated.attributes?.created,\n updatedOn: generated.attributes?.updated,\n expiresIn: generated.attributes?.expiryTime,\n lifetimeActions: generated.lifetimeActions?.map((action) => {\n return {\n action: getNormalizedActionType(action.action!.type!),\n timeAfterCreate: action.trigger?.timeAfterCreate,\n timeBeforeExpiry: action.trigger?.timeBeforeExpiry,\n };\n }),\n };\n return policy;\n },\n};\n\n/**\n * A helper supporting compatibility between modular and legacy paged async iterables.\n *\n * Provides the following compatibility:\n * 1. Maps the values of the paged async iterable using the provided mapper function.\n * 2. Supports `maxPageSize` operation on the paged async iterable.\n *\n * TODO: move this to keyvault-common once everything is merged\n */\nexport function mapPagedAsyncIterable<\n TGenerated,\n TPublic,\n TOptions extends OperationOptions & { maxresults?: number },\n>(\n options: TOptions,\n operation: (options: TOptions) => PagedAsyncIterableIterator<TGenerated>,\n mapper: (x: TGenerated) => TPublic,\n): PagedAsyncIterableIterator<TPublic> {\n let iter: ReturnType<typeof operation> | undefined = undefined;\n return {\n async next() {\n iter ??= operation({ ...options, maxresults: undefined });\n const result = await iter.next();\n\n return {\n ...result,\n value: result.value && mapper(result.value),\n };\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n async *byPage<TSettings extends PageSettings & { maxPageSize?: number }>(settings?: TSettings) {\n // Pass the maxPageSize value to the underlying page operation\n const iteratorByPage = operation({ ...options, maxresults: settings?.maxPageSize }).byPage(\n settings,\n );\n for await (const page of iteratorByPage) {\n yield page.map(mapper);\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"transformations.js","sourceRoot":"","sources":["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AS,CAAC;IAC/D,OAAO;QACL,KAAK,CAAC,IAAI;YACR,IAAI,KAAK,SAAS,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;YAC1D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAEjC,OAAO;gBACL,GAAG,MAAM;gBACT,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC5C,CAAC;QACJ,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,CAAC,CAAC,MAAM,CAA4D,QAAoB;YAC3F,8DAA8D;YAC9D,MAAM,cAAc,GAAG,SAAS,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,CACxF,QAAQ,CACT,CAAC;YACF,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;gBACxC,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n DeletedKeyBundle,\n DeletedKeyItem,\n KeyRotationPolicy as GeneratedPolicy,\n KeyAttributes,\n KeyBundle,\n KeyItem,\n LifetimeActions,\n} from \"./generated/src/models/index.js\";\nimport { parseKeyVaultKeyIdentifier } from \"./identifier.js\";\nimport type {\n DeletedKey,\n KeyProperties,\n KeyRotationPolicy,\n KeyRotationPolicyAction,\n KeyRotationPolicyProperties,\n KeyVaultKey,\n} from \"./keysModels.js\";\nimport type { PagedAsyncIterableIterator, PageSettings } from \"./generated/src/index.js\";\nimport type { OperationOptions } from \"@azure-rest/core-client\";\n\n/**\n * @internal\n * Shapes the exposed {@link KeyVaultKey} based on either a received key bundle or deleted key bundle.\n */\nexport function getKeyFromKeyBundle(\n bundle: KeyBundle | DeletedKeyBundle,\n): KeyVaultKey | DeletedKey {\n const keyBundle = bundle as KeyBundle;\n const deletedKeyBundle = bundle as DeletedKeyBundle;\n\n const parsedId = parseKeyVaultKeyIdentifier(keyBundle.key!.kid!);\n\n const attributes: KeyAttributes = keyBundle.attributes || {};\n\n const resultObject: KeyVaultKey | DeletedKey = {\n key: keyBundle.key,\n id: keyBundle.key ? keyBundle.key.kid : undefined,\n name: parsedId.name,\n keyOperations: keyBundle.key ? keyBundle.key.keyOps : undefined,\n keyType: keyBundle.key ? keyBundle.key.kty : undefined,\n properties: {\n tags: keyBundle.tags,\n\n enabled: attributes.enabled,\n notBefore: attributes.notBefore,\n expiresOn: attributes.expires,\n createdOn: attributes.created,\n updatedOn: attributes.updated,\n recoverableDays: attributes.recoverableDays,\n recoveryLevel: attributes.recoveryLevel,\n exportable: attributes.exportable,\n releasePolicy: keyBundle.releasePolicy,\n hsmPlatform: attributes.hsmPlatform,\n\n vaultUrl: parsedId.vaultUrl,\n version: parsedId.version,\n name: parsedId.name,\n managed: keyBundle.managed,\n\n id: keyBundle.key ? keyBundle.key.kid : undefined,\n },\n };\n\n if (deletedKeyBundle.recoveryId) {\n (resultObject as any).properties.recoveryId = deletedKeyBundle.recoveryId;\n (resultObject as any).properties.scheduledPurgeDate = deletedKeyBundle.scheduledPurgeDate;\n (resultObject as any).properties.deletedOn = deletedKeyBundle.deletedDate;\n }\n\n if (attributes.attestation) {\n resultObject.properties.attestation = attributes.attestation;\n }\n\n return resultObject;\n}\n\n/**\n * @internal\n * Shapes the exposed {@link DeletedKey} based on a received KeyItem.\n */\nexport function getDeletedKeyFromDeletedKeyItem(keyItem: DeletedKeyItem): DeletedKey {\n const commonProperties = getKeyPropertiesFromKeyItem(keyItem);\n\n return {\n key: {\n kid: keyItem.kid,\n },\n id: keyItem.kid,\n name: commonProperties.name,\n properties: {\n ...commonProperties,\n recoveryId: keyItem.recoveryId,\n scheduledPurgeDate: keyItem.scheduledPurgeDate,\n deletedOn: keyItem.deletedDate,\n },\n };\n}\n\n/**\n * @internal\n * Shapes the exposed {@link KeyProperties} based on a received KeyItem.\n */\nexport function getKeyPropertiesFromKeyItem(keyItem: KeyItem): KeyProperties {\n const parsedId = parseKeyVaultKeyIdentifier(keyItem.kid!);\n const attributes = keyItem.attributes || {};\n\n const resultObject: KeyProperties = {\n createdOn: attributes.created,\n enabled: attributes?.enabled,\n expiresOn: attributes?.expires,\n id: keyItem.kid,\n managed: keyItem.managed,\n name: parsedId.name,\n notBefore: attributes?.notBefore,\n recoverableDays: attributes?.recoverableDays,\n recoveryLevel: attributes?.recoveryLevel,\n hsmPlatform: attributes?.hsmPlatform,\n tags: keyItem.tags,\n updatedOn: attributes.updated,\n vaultUrl: parsedId.vaultUrl,\n version: parsedId.version,\n };\n\n return resultObject;\n}\n\nconst actionTypeCaseInsensitiveMapping: Record<string, KeyRotationPolicyAction> = {\n rotate: \"Rotate\",\n notify: \"Notify\",\n};\n\nfunction getNormalizedActionType(caseInsensitiveActionType: string): KeyRotationPolicyAction {\n const result = actionTypeCaseInsensitiveMapping[caseInsensitiveActionType.toLowerCase()];\n if (result) {\n return result;\n }\n\n throw new Error(`Unrecognized action type: ${caseInsensitiveActionType}`);\n}\n\n/**\n * @internal\n */\nexport const keyRotationTransformations = {\n propertiesToGenerated: function (\n parameters: KeyRotationPolicyProperties,\n ): Partial<GeneratedPolicy> {\n const policy: GeneratedPolicy = {\n attributes: {\n expiryTime: parameters.expiresIn,\n },\n lifetimeActions: parameters.lifetimeActions?.map((action) => {\n const generatedAction: LifetimeActions = {\n action: { type: action.action },\n trigger: {},\n };\n\n if (action.timeAfterCreate) {\n generatedAction.trigger!.timeAfterCreate = action.timeAfterCreate;\n }\n\n if (action.timeBeforeExpiry) {\n generatedAction.trigger!.timeBeforeExpiry = action.timeBeforeExpiry;\n }\n\n return generatedAction;\n }),\n };\n return policy;\n },\n generatedToPublic(generated: GeneratedPolicy): KeyRotationPolicy {\n const policy: KeyRotationPolicy = {\n id: generated.id,\n createdOn: generated.attributes?.created,\n updatedOn: generated.attributes?.updated,\n expiresIn: generated.attributes?.expiryTime,\n lifetimeActions: generated.lifetimeActions?.map((action) => {\n return {\n action: getNormalizedActionType(action.action!.type!),\n timeAfterCreate: action.trigger?.timeAfterCreate,\n timeBeforeExpiry: action.trigger?.timeBeforeExpiry,\n };\n }),\n };\n return policy;\n },\n};\n\n/**\n * A helper supporting compatibility between modular and legacy paged async iterables.\n *\n * Provides the following compatibility:\n * 1. Maps the values of the paged async iterable using the provided mapper function.\n * 2. Supports `maxPageSize` operation on the paged async iterable.\n *\n * TODO: move this to keyvault-common once everything is merged\n */\nexport function mapPagedAsyncIterable<\n TGenerated,\n TPublic,\n TOptions extends OperationOptions & { maxresults?: number },\n>(\n options: TOptions,\n operation: (options: TOptions) => PagedAsyncIterableIterator<TGenerated>,\n mapper: (x: TGenerated) => TPublic,\n): PagedAsyncIterableIterator<TPublic> {\n let iter: ReturnType<typeof operation> | undefined = undefined;\n return {\n async next() {\n iter ??= operation({ ...options, maxresults: undefined });\n const result = await iter.next();\n\n return {\n ...result,\n value: result.value && mapper(result.value),\n };\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n async *byPage<TSettings extends PageSettings & { maxPageSize?: number }>(settings?: TSettings) {\n // Pass the maxPageSize value to the underlying page operation\n const iteratorByPage = operation({ ...options, maxresults: settings?.maxPageSize }).byPage(\n settings,\n );\n for await (const page of iteratorByPage) {\n yield page.map(mapper);\n }\n },\n };\n}\n"]}
@@ -11,29 +11,8 @@ const models_js_1 = require("./models.js");
11
11
  * @internal
12
12
  */
13
13
  class AesCryptographyProvider {
14
+ key;
14
15
  constructor(key) {
15
- /**
16
- * The set of algorithms this provider supports.
17
- * For AES encryption, the values include the underlying algorithm used in crypto
18
- * as well as the key size in bytes.
19
- *
20
- * We start with support for A[SIZE]CBCPAD which uses the PKCS padding (the default padding scheme in node crypto)
21
- */
22
- this.supportedAlgorithms = {
23
- A128CBCPAD: {
24
- algorithm: "aes-128-cbc",
25
- keySizeInBytes: 128 >> 3,
26
- },
27
- A192CBCPAD: {
28
- algorithm: "aes-192-cbc",
29
- keySizeInBytes: 192 >> 3,
30
- },
31
- A256CBCPAD: {
32
- algorithm: "aes-256-cbc",
33
- keySizeInBytes: 256 >> 3,
34
- },
35
- };
36
- this.supportedOperations = ["encrypt", "decrypt"];
37
16
  this.key = key;
38
17
  }
39
18
  encrypt(encryptParameters, _options) {
@@ -72,6 +51,28 @@ class AesCryptographyProvider {
72
51
  }
73
52
  return true;
74
53
  }
54
+ /**
55
+ * The set of algorithms this provider supports.
56
+ * For AES encryption, the values include the underlying algorithm used in crypto
57
+ * as well as the key size in bytes.
58
+ *
59
+ * We start with support for A[SIZE]CBCPAD which uses the PKCS padding (the default padding scheme in node crypto)
60
+ */
61
+ supportedAlgorithms = {
62
+ A128CBCPAD: {
63
+ algorithm: "aes-128-cbc",
64
+ keySizeInBytes: 128 >> 3,
65
+ },
66
+ A192CBCPAD: {
67
+ algorithm: "aes-192-cbc",
68
+ keySizeInBytes: 192 >> 3,
69
+ },
70
+ A256CBCPAD: {
71
+ algorithm: "aes-256-cbc",
72
+ keySizeInBytes: 256 >> 3,
73
+ },
74
+ };
75
+ supportedOperations = ["encrypt", "decrypt"];
75
76
  wrapKey(_algorithm, _keyToWrap, _options) {
76
77
  throw new models_js_1.LocalCryptographyUnsupportedError("Wrapping a key using a local JsonWebKey is not supported for AES.");
77
78
  }
@@ -91,10 +92,9 @@ class AesCryptographyProvider {
91
92
  throw new models_js_1.LocalCryptographyUnsupportedError("Verifying using a local JsonWebKey is not supported for AES.");
92
93
  }
93
94
  ensureValid(keySizeInBytes) {
94
- var _a, _b;
95
95
  if (this.key &&
96
- ((_a = this.key.kty) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== "OCT" &&
97
- ((_b = this.key.kty) === null || _b === void 0 ? void 0 : _b.toUpperCase()) !== "OCT-HSM") {
96
+ this.key.kty?.toUpperCase() !== "OCT" &&
97
+ this.key.kty?.toUpperCase() !== "OCT-HSM") {
98
98
  throw new Error("Key type does not match the key type oct or oct-hsm");
99
99
  }
100
100
  if (!this.key.k) {
@@ -1 +1 @@
1
- {"version":3,"file":"aesCryptographyProvider.js","sourceRoot":"","sources":["../../../src/cryptography/aesCryptographyProvider.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAGlC,sEAAiC;AAoBjC,2CAAgE;AAEhE;;;GAGG;AACH,MAAa,uBAAuB;IAElC,YAAY,GAAe;QA6D3B;;;;;;WAMG;QACK,wBAAmB,GAAmE;YAC5F,UAAU,EAAE;gBACV,SAAS,EAAE,aAAa;gBACxB,cAAc,EAAE,GAAG,IAAI,CAAC;aACzB;YACD,UAAU,EAAE;gBACV,SAAS,EAAE,aAAa;gBACxB,cAAc,EAAE,GAAG,IAAI,CAAC;aACzB;YACD,UAAU,EAAE;gBACV,SAAS,EAAE,aAAa;gBACxB,cAAc,EAAE,GAAG,IAAI,CAAC;aACzB;SACF,CAAC;QAEM,wBAAmB,GAAoC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAlFpF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IACD,OAAO,CACL,iBAA0C,EAC1C,QAAyB;QAEzB,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC5F,MAAM,EAAE,GAAG,iBAAiB,CAAC,EAAE,IAAI,qBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAE1D,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAEjC,MAAM,MAAM,GAAG,qBAAM,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC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C;YACD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,cAAc,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,wBAAwB,cAAc,IAAI,CAAC,OAAO,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF;AA7JD,0DA6JC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions } from \"@azure-rest/core-client\";\nimport crypto from \"node:crypto\";\nimport type {\n AesCbcEncryptParameters,\n DecryptOptions,\n DecryptResult,\n EncryptOptions,\n EncryptResult,\n JsonWebKey,\n KeyWrapAlgorithm,\n SignOptions,\n SignResult,\n UnwrapKeyOptions,\n UnwrapResult,\n VerifyOptions,\n VerifyResult,\n WrapKeyOptions,\n WrapResult,\n} from \"../index.js\";\nimport type { AesCbcDecryptParameters } from \"../cryptographyClientModels.js\";\nimport type { CryptographyProvider, CryptographyProviderOperation } from \"./models.js\";\nimport { LocalCryptographyUnsupportedError } from \"./models.js\";\n\n/**\n * An AES cryptography provider supporting AES algorithms.\n * @internal\n */\nexport class AesCryptographyProvider implements CryptographyProvider {\n private key: JsonWebKey;\n constructor(key: JsonWebKey) {\n this.key = key;\n }\n encrypt(\n encryptParameters: AesCbcEncryptParameters,\n _options?: EncryptOptions,\n ): Promise<EncryptResult> {\n const { algorithm, keySizeInBytes } = this.supportedAlgorithms[encryptParameters.algorithm];\n const iv = encryptParameters.iv || crypto.randomBytes(16);\n\n this.ensureValid(keySizeInBytes);\n\n const cipher = crypto.createCipheriv(algorithm, this.key.k!.subarray(0, keySizeInBytes), iv);\n let encrypted = cipher.update(Buffer.from(encryptParameters.plaintext));\n encrypted = Buffer.concat([encrypted, cipher.final()]);\n\n return Promise.resolve({\n algorithm: encryptParameters.algorithm,\n result: encrypted,\n iv: iv,\n });\n }\n\n decrypt(\n decryptParameters: AesCbcDecryptParameters,\n _options?: DecryptOptions,\n ): Promise<DecryptResult> {\n const { algorithm, keySizeInBytes } = this.supportedAlgorithms[decryptParameters.algorithm];\n\n this.ensureValid(keySizeInBytes);\n\n const decipher = crypto.createDecipheriv(\n algorithm,\n this.key.k!.subarray(0, keySizeInBytes),\n decryptParameters.iv,\n );\n let dec = decipher.update(Buffer.from(decryptParameters.ciphertext));\n dec = Buffer.concat([dec, decipher.final()]);\n\n return Promise.resolve({\n algorithm: decryptParameters.algorithm,\n result: dec,\n });\n }\n\n isSupported(algorithm: string, operation: CryptographyProviderOperation): boolean {\n if (!this.key.k) {\n return false;\n }\n\n if (!Object.keys(this.supportedAlgorithms).includes(algorithm)) {\n return false;\n }\n\n if (!this.supportedOperations.includes(operation)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * The set of algorithms this provider supports.\n * For AES encryption, the values include the underlying algorithm used in crypto\n * as well as the key size in bytes.\n *\n * We start with support for A[SIZE]CBCPAD which uses the PKCS padding (the default padding scheme in node crypto)\n */\n private supportedAlgorithms: { [s: string]: { algorithm: string; keySizeInBytes: number } } = {\n A128CBCPAD: {\n algorithm: \"aes-128-cbc\",\n keySizeInBytes: 128 >> 3,\n },\n A192CBCPAD: {\n algorithm: \"aes-192-cbc\",\n keySizeInBytes: 192 >> 3,\n },\n A256CBCPAD: {\n algorithm: \"aes-256-cbc\",\n keySizeInBytes: 256 >> 3,\n },\n };\n\n private supportedOperations: CryptographyProviderOperation[] = [\"encrypt\", \"decrypt\"];\n\n wrapKey(\n _algorithm: KeyWrapAlgorithm,\n _keyToWrap: Uint8Array,\n _options?: WrapKeyOptions,\n ): Promise<WrapResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Wrapping a key using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n unwrapKey(\n _algorithm: KeyWrapAlgorithm,\n _encryptedKey: Uint8Array,\n _options?: UnwrapKeyOptions,\n ): Promise<UnwrapResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Unwrapping a key using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n sign(_algorithm: string, _digest: Uint8Array, _options?: SignOptions): Promise<SignResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Signing using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n signData(_algorithm: string, _data: Uint8Array, _options?: SignOptions): Promise<SignResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Signing using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n verify(\n _algorithm: string,\n _digest: Uint8Array,\n _signature: Uint8Array,\n _options?: VerifyOptions,\n ): Promise<VerifyResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Verifying using a local JsonWebKey is not supported for AES.\",\n );\n }\n verifyData(\n _algorithm: string,\n _data: Uint8Array,\n _signature: Uint8Array,\n _updatedOptions: OperationOptions,\n ): Promise<VerifyResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Verifying using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n private ensureValid(keySizeInBytes: number): void {\n if (\n this.key &&\n this.key.kty?.toUpperCase() !== \"OCT\" &&\n this.key.kty?.toUpperCase() !== \"OCT-HSM\"\n ) {\n throw new Error(\"Key type does not match the key type oct or oct-hsm\");\n }\n\n if (!this.key.k) {\n throw new Error(\"Symmetric key is required\");\n }\n\n if (this.key.k.length < keySizeInBytes) {\n throw new Error(`Key must be at least ${keySizeInBytes << 3} bits`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"aesCryptographyProvider.js","sourceRoot":"","sources":["../../../src/cryptography/aesCryptographyProvider.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAGlC,sEAAiC;AAoBjC,2CAAgE;AAEhE;;;GAGG;AACH,MAAa,uBAAuB;IAC1B,GAAG,CAAa;IACxB,YAAY,GAAe;QACzB,IAAI,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n// Licensed under the MIT License.\n\nimport type { OperationOptions } from \"@azure-rest/core-client\";\nimport crypto from \"node:crypto\";\nimport type {\n AesCbcEncryptParameters,\n DecryptOptions,\n DecryptResult,\n EncryptOptions,\n EncryptResult,\n JsonWebKey,\n KeyWrapAlgorithm,\n SignOptions,\n SignResult,\n UnwrapKeyOptions,\n UnwrapResult,\n VerifyOptions,\n VerifyResult,\n WrapKeyOptions,\n WrapResult,\n} from \"../index.js\";\nimport type { AesCbcDecryptParameters } from \"../cryptographyClientModels.js\";\nimport type { CryptographyProvider, CryptographyProviderOperation } from \"./models.js\";\nimport { LocalCryptographyUnsupportedError } from \"./models.js\";\n\n/**\n * An AES cryptography provider supporting AES algorithms.\n * @internal\n */\nexport class AesCryptographyProvider implements CryptographyProvider {\n private key: JsonWebKey;\n constructor(key: JsonWebKey) {\n this.key = key;\n }\n encrypt(\n encryptParameters: AesCbcEncryptParameters,\n _options?: EncryptOptions,\n ): Promise<EncryptResult> {\n const { algorithm, keySizeInBytes } = this.supportedAlgorithms[encryptParameters.algorithm];\n const iv = encryptParameters.iv || crypto.randomBytes(16);\n\n this.ensureValid(keySizeInBytes);\n\n const cipher = crypto.createCipheriv(algorithm, this.key.k!.subarray(0, keySizeInBytes), iv);\n let encrypted = cipher.update(Buffer.from(encryptParameters.plaintext));\n encrypted = Buffer.concat([encrypted, cipher.final()]);\n\n return Promise.resolve({\n algorithm: encryptParameters.algorithm,\n result: encrypted,\n iv: iv,\n });\n }\n\n decrypt(\n decryptParameters: AesCbcDecryptParameters,\n _options?: DecryptOptions,\n ): Promise<DecryptResult> {\n const { algorithm, keySizeInBytes } = this.supportedAlgorithms[decryptParameters.algorithm];\n\n this.ensureValid(keySizeInBytes);\n\n const decipher = crypto.createDecipheriv(\n algorithm,\n this.key.k!.subarray(0, keySizeInBytes),\n decryptParameters.iv,\n );\n let dec = decipher.update(Buffer.from(decryptParameters.ciphertext));\n dec = Buffer.concat([dec, decipher.final()]);\n\n return Promise.resolve({\n algorithm: decryptParameters.algorithm,\n result: dec,\n });\n }\n\n isSupported(algorithm: string, operation: CryptographyProviderOperation): boolean {\n if (!this.key.k) {\n return false;\n }\n\n if (!Object.keys(this.supportedAlgorithms).includes(algorithm)) {\n return false;\n }\n\n if (!this.supportedOperations.includes(operation)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * The set of algorithms this provider supports.\n * For AES encryption, the values include the underlying algorithm used in crypto\n * as well as the key size in bytes.\n *\n * We start with support for A[SIZE]CBCPAD which uses the PKCS padding (the default padding scheme in node crypto)\n */\n private supportedAlgorithms: { [s: string]: { algorithm: string; keySizeInBytes: number } } = {\n A128CBCPAD: {\n algorithm: \"aes-128-cbc\",\n keySizeInBytes: 128 >> 3,\n },\n A192CBCPAD: {\n algorithm: \"aes-192-cbc\",\n keySizeInBytes: 192 >> 3,\n },\n A256CBCPAD: {\n algorithm: \"aes-256-cbc\",\n keySizeInBytes: 256 >> 3,\n },\n };\n\n private supportedOperations: CryptographyProviderOperation[] = [\"encrypt\", \"decrypt\"];\n\n wrapKey(\n _algorithm: KeyWrapAlgorithm,\n _keyToWrap: Uint8Array,\n _options?: WrapKeyOptions,\n ): Promise<WrapResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Wrapping a key using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n unwrapKey(\n _algorithm: KeyWrapAlgorithm,\n _encryptedKey: Uint8Array,\n _options?: UnwrapKeyOptions,\n ): Promise<UnwrapResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Unwrapping a key using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n sign(_algorithm: string, _digest: Uint8Array, _options?: SignOptions): Promise<SignResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Signing using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n signData(_algorithm: string, _data: Uint8Array, _options?: SignOptions): Promise<SignResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Signing using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n verify(\n _algorithm: string,\n _digest: Uint8Array,\n _signature: Uint8Array,\n _options?: VerifyOptions,\n ): Promise<VerifyResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Verifying using a local JsonWebKey is not supported for AES.\",\n );\n }\n verifyData(\n _algorithm: string,\n _data: Uint8Array,\n _signature: Uint8Array,\n _updatedOptions: OperationOptions,\n ): Promise<VerifyResult> {\n throw new LocalCryptographyUnsupportedError(\n \"Verifying using a local JsonWebKey is not supported for AES.\",\n );\n }\n\n private ensureValid(keySizeInBytes: number): void {\n if (\n this.key &&\n this.key.kty?.toUpperCase() !== \"OCT\" &&\n this.key.kty?.toUpperCase() !== \"OCT-HSM\"\n ) {\n throw new Error(\"Key type does not match the key type oct or oct-hsm\");\n }\n\n if (!this.key.k) {\n throw new Error(\"Symmetric key is required\");\n }\n\n if (this.key.k.length < keySizeInBytes) {\n throw new Error(`Key must be at least ${keySizeInBytes << 3} bits`);\n }\n }\n}\n"]}
@@ -3,7 +3,6 @@
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.RemoteCryptographyProvider = void 0;
6
- const tslib_1 = require("tslib");
7
6
  const constants_js_1 = require("../constants.js");
8
7
  const index_js_1 = require("../generated/src/index.js");
9
8
  const identifier_js_1 = require("../identifier.js");
@@ -20,7 +19,6 @@ const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
20
19
  */
21
20
  class RemoteCryptographyProvider {
22
21
  constructor(key, credential, pipelineOptions = {}) {
23
- var _a;
24
22
  this.key = key;
25
23
  let keyId;
26
24
  if (typeof key === "string") {
@@ -39,7 +37,7 @@ class RemoteCryptographyProvider {
39
37
  }
40
38
  this.vaultUrl = parsed.vaultUrl;
41
39
  this.name = parsed.name;
42
- this.version = (_a = parsed.version) !== null && _a !== void 0 ? _a : "";
40
+ this.version = parsed.version ?? "";
43
41
  this.client = getOrInitializeClient(this.vaultUrl, credential, pipelineOptions);
44
42
  }
45
43
  catch (err) {
@@ -52,8 +50,8 @@ class RemoteCryptographyProvider {
52
50
  return true;
53
51
  }
54
52
  encrypt(encryptParameters, options = {}) {
55
- const { algorithm, plaintext } = encryptParameters, params = tslib_1.__rest(encryptParameters, ["algorithm", "plaintext"]);
56
- const requestOptions = Object.assign(Object.assign({}, options), params);
53
+ const { algorithm, plaintext, ...params } = encryptParameters;
54
+ const requestOptions = { ...options, ...params };
57
55
  return tracing_js_1.tracingClient.withSpan("RemoteCryptographyProvider.encrypt", requestOptions, async (updatedOptions) => {
58
56
  const result = await this.client.encrypt(this.name, this.version, {
59
57
  algorithm,
@@ -74,8 +72,8 @@ class RemoteCryptographyProvider {
74
72
  });
75
73
  }
76
74
  decrypt(decryptParameters, options = {}) {
77
- const { algorithm, ciphertext } = decryptParameters, params = tslib_1.__rest(decryptParameters, ["algorithm", "ciphertext"]);
78
- const requestOptions = Object.assign(Object.assign({}, options), params);
75
+ const { algorithm, ciphertext, ...params } = decryptParameters;
76
+ const requestOptions = { ...options, ...params };
79
77
  return tracing_js_1.tracingClient.withSpan("RemoteCryptographyProvider.decrypt", requestOptions, async (updatedOptions) => {
80
78
  const result = await this.client.decrypt(this.name, this.version, {
81
79
  algorithm,
@@ -159,6 +157,10 @@ class RemoteCryptographyProvider {
159
157
  return { result: result.result, algorithm, keyID: this.getKeyID() };
160
158
  });
161
159
  }
160
+ /**
161
+ * The base URL to the vault.
162
+ */
163
+ vaultUrl;
162
164
  /**
163
165
  * The ID of the key used to perform cryptographic operations for the client.
164
166
  */
@@ -182,6 +184,24 @@ class RemoteCryptographyProvider {
182
184
  return this.key;
183
185
  });
184
186
  }
187
+ /**
188
+ * A reference to the auto-generated KeyVault HTTP client.
189
+ */
190
+ client;
191
+ /**
192
+ * A reference to the key used for the cryptographic operations.
193
+ * Based on what was provided to the CryptographyClient constructor,
194
+ * it can be either a string with the URL of a Key Vault Key, or an already parsed {@link KeyVaultKey}.
195
+ */
196
+ key;
197
+ /**
198
+ * Name of the key the client represents
199
+ */
200
+ name;
201
+ /**
202
+ * Version of the key the client represents
203
+ */
204
+ version;
185
205
  /**
186
206
  * Attempts to retrieve the ID of the key.
187
207
  */
@@ -217,14 +237,18 @@ function getOrInitializeClient(vaultUrl, credential, options) {
217
237
  ? `${userAgentOptions.userAgentPrefix} ${libInfo}`
218
238
  : libInfo,
219
239
  };
220
- const internalPipelineOptions = Object.assign(Object.assign({}, options), { apiVersion: options.serviceVersion || keysModels_js_1.LATEST_API_VERSION, loggingOptions: {
240
+ const internalPipelineOptions = {
241
+ ...options,
242
+ apiVersion: options.serviceVersion || keysModels_js_1.LATEST_API_VERSION,
243
+ loggingOptions: {
221
244
  logger: log_js_1.logger.info,
222
245
  additionalAllowedHeaderNames: [
223
246
  "x-ms-keyvault-region",
224
247
  "x-ms-keyvault-network-info",
225
248
  "x-ms-keyvault-service-version",
226
249
  ],
227
- } });
250
+ },
251
+ };
228
252
  const client = new index_js_1.KeyVaultClient(vaultUrl, credential, internalPipelineOptions);
229
253
  client.pipeline.removePolicy({ name: core_rest_pipeline_1.bearerTokenAuthenticationPolicyName });
230
254
  client.pipeline.addPolicy((0, keyvault_common_1.keyVaultAuthenticationPolicy)(credential, options));
@@ -232,8 +256,7 @@ function getOrInitializeClient(vaultUrl, credential, options) {
232
256
  client.pipeline.addPolicy({
233
257
  name: "ContentTypePolicy",
234
258
  sendRequest(request, next) {
235
- var _a;
236
- const contentType = (_a = request.headers.get("Content-Type")) !== null && _a !== void 0 ? _a : "";
259
+ const contentType = request.headers.get("Content-Type") ?? "";
237
260
  if (contentType.startsWith("application/json")) {
238
261
  request.headers.set("Content-Type", "application/json");
239
262
  }
@@ -1 +1 @@
1
- {"version":3,"file":"remoteCryptographyProvider.js","sourceRoot":"","sources":["../../../src/cryptography/remoteCryptographyProvider.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAoBlC,kDAA8C;AAG9C,wDAA2D;AAC3D,oDAA8D;AAE9D,oDAAsD;AACtD,8DAA4D;AAC5D,2CAAyC;AAEzC,sCAAm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OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TokenCredential } from \"@azure/core-auth\";\n\nimport type {\n DecryptOptions,\n DecryptParameters,\n DecryptResult,\n EncryptOptions,\n EncryptParameters,\n EncryptResult,\n KeyWrapAlgorithm,\n SignOptions,\n SignResult,\n UnwrapKeyOptions,\n VerifyOptions,\n VerifyResult,\n WrapKeyOptions,\n WrapResult,\n} from \"../cryptographyClientModels.js\";\nimport { SDK_VERSION } from \"../constants.js\";\nimport type { UnwrapResult } from \"../cryptographyClientModels.js\";\nimport type { KeyVaultClientOptionalParams } from \"../generated/src/index.js\";\nimport { KeyVaultClient } from \"../generated/src/index.js\";\nimport { parseKeyVaultKeyIdentifier } from \"../identifier.js\";\nimport type { CryptographyClientOptions, GetKeyOptions, KeyVaultKey } from \"../keysModels.js\";\nimport { LATEST_API_VERSION } from \"../keysModels.js\";\nimport { getKeyFromKeyBundle } from \"../transformations.js\";\nimport { createHash } from \"./crypto.js\";\nimport type { CryptographyProvider, CryptographyProviderOperation } from \"./models.js\";\nimport { logger } from \"../log.js\";\nimport { keyVaultAuthenticationPolicy } from \"@azure/keyvault-common\";\nimport { tracingClient } from \"../tracing.js\";\nimport { bearerTokenAuthenticationPolicyName } from \"@azure/core-rest-pipeline\";\n\n/**\n * The remote cryptography provider is used to run crypto operations against KeyVault.\n * @internal\n */\nexport class RemoteCryptographyProvider implements CryptographyProvider {\n constructor(\n key: string | KeyVaultKey,\n credential: TokenCredential,\n pipelineOptions: CryptographyClientOptions = {},\n ) {\n this.key = key;\n\n let keyId: string;\n if (typeof key === \"string\") {\n keyId = key;\n } else {\n keyId = key.id!;\n }\n\n try {\n const parsed = parseKeyVaultKeyIdentifier(keyId);\n if (parsed.name === \"\") {\n throw new Error(\"Could not find 'name' of key in key URL\");\n }\n\n if (!parsed.vaultUrl || parsed.vaultUrl === \"\") {\n throw new Error(\"Could not find 'vaultUrl' of key in key URL\");\n }\n\n this.vaultUrl = parsed.vaultUrl;\n this.name = parsed.name;\n this.version = parsed.version ?? \"\";\n\n this.client = getOrInitializeClient(this.vaultUrl, credential, pipelineOptions);\n } catch (err: any) {\n logger.error(err);\n\n throw new Error(`${keyId} is not a valid Key Vault key ID`);\n }\n }\n\n // The remote client supports all algorithms and all operations.\n isSupported(_algorithm: string, _operation: CryptographyProviderOperation): boolean {\n return true;\n }\n\n encrypt(\n encryptParameters: EncryptParameters,\n options: EncryptOptions = {},\n ): Promise<EncryptResult> {\n const { algorithm, plaintext, ...params } = encryptParameters;\n const requestOptions = { ...options, ...params };\n\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.encrypt\",\n requestOptions,\n async (updatedOptions) => {\n const result = await this.client.encrypt(\n this.name,\n this.version,\n {\n algorithm,\n value: plaintext,\n aad:\n \"additionalAuthenticatedData\" in encryptParameters\n ? encryptParameters.additionalAuthenticatedData\n : undefined,\n iv: \"iv\" in encryptParameters ? encryptParameters.iv : undefined,\n },\n updatedOptions,\n );\n\n return {\n algorithm: encryptParameters.algorithm,\n result: result.result!,\n keyID: this.getKeyID(),\n additionalAuthenticatedData: result.additionalAuthenticatedData,\n authenticationTag: result.authenticationTag,\n iv: result.iv,\n };\n },\n );\n }\n\n decrypt(\n decryptParameters: DecryptParameters,\n options: DecryptOptions = {},\n ): Promise<DecryptResult> {\n const { algorithm, ciphertext, ...params } = decryptParameters;\n const requestOptions = { ...options, ...params };\n\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.decrypt\",\n requestOptions,\n async (updatedOptions) => {\n const result = await this.client.decrypt(\n this.name,\n this.version,\n {\n algorithm,\n value: ciphertext,\n aad:\n \"additionalAuthenticatedData\" in decryptParameters\n ? decryptParameters.additionalAuthenticatedData\n : undefined,\n iv: \"iv\" in decryptParameters ? decryptParameters.iv : undefined,\n tag:\n \"authenticationTag\" in decryptParameters\n ? decryptParameters.authenticationTag\n : undefined,\n },\n updatedOptions,\n );\n return {\n result: result.result!,\n keyID: this.getKeyID(),\n algorithm,\n };\n },\n );\n }\n\n wrapKey(\n algorithm: KeyWrapAlgorithm,\n keyToWrap: Uint8Array,\n options: WrapKeyOptions = {},\n ): Promise<WrapResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.wrapKey\",\n options,\n async (updatedOptions) => {\n const result = await this.client.wrapKey(\n this.name,\n this.version,\n {\n algorithm,\n value: keyToWrap,\n },\n updatedOptions,\n );\n\n return {\n result: result.result!,\n algorithm,\n keyID: this.getKeyID(),\n };\n },\n );\n }\n\n unwrapKey(\n algorithm: KeyWrapAlgorithm,\n encryptedKey: Uint8Array,\n options: UnwrapKeyOptions = {},\n ): Promise<UnwrapResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.unwrapKey\",\n options,\n async (updatedOptions) => {\n const result = await this.client.unwrapKey(\n this.name,\n this.version,\n {\n algorithm,\n value: encryptedKey,\n },\n updatedOptions,\n );\n\n return {\n result: result.result!,\n algorithm,\n keyID: this.getKeyID(),\n };\n },\n );\n }\n\n sign(algorithm: string, digest: Uint8Array, options: SignOptions = {}): Promise<SignResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.sign\",\n options,\n async (updatedOptions) => {\n const result = await this.client.sign(\n this.name,\n this.version,\n {\n algorithm,\n value: digest,\n },\n updatedOptions,\n );\n\n return { result: result.result!, algorithm, keyID: this.getKeyID() };\n },\n );\n }\n\n verifyData(\n algorithm: string,\n data: Uint8Array,\n signature: Uint8Array,\n options: VerifyOptions = {},\n ): Promise<VerifyResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.verifyData\",\n options,\n async (updatedOptions) => {\n const hash = await createHash(algorithm, data);\n return this.verify(algorithm, hash, signature, updatedOptions);\n },\n );\n }\n\n verify(\n algorithm: string,\n digest: Uint8Array,\n signature: Uint8Array,\n options: VerifyOptions = {},\n ): Promise<VerifyResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.verify\",\n options,\n async (updatedOptions) => {\n const response = await this.client.verify(\n this.name,\n this.version,\n {\n algorithm,\n digest,\n signature,\n },\n updatedOptions,\n );\n return {\n result: response.value ? response.value : false,\n keyID: this.getKeyID(),\n };\n },\n );\n }\n\n signData(algorithm: string, data: Uint8Array, options: SignOptions = {}): Promise<SignResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.signData\",\n options,\n async (updatedOptions) => {\n const digest = await createHash(algorithm, data);\n const result = await this.client.sign(\n this.name,\n this.version,\n {\n algorithm,\n value: digest,\n },\n updatedOptions,\n );\n return { result: result.result!, algorithm, keyID: this.getKeyID() };\n },\n );\n }\n\n /**\n * The base URL to the vault.\n */\n readonly vaultUrl: string;\n\n /**\n * The ID of the key used to perform cryptographic operations for the client.\n */\n get keyId(): string | undefined {\n return this.getKeyID();\n }\n\n /**\n * Gets the {@link KeyVaultKey} used for cryptography operations, fetching it\n * from KeyVault if necessary.\n * @param options - Additional options.\n */\n getKey(options: GetKeyOptions = {}): Promise<KeyVaultKey> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.getKey\",\n options,\n async (updatedOptions) => {\n if (typeof this.key === \"string\") {\n if (!this.name || this.name === \"\") {\n throw new Error(\"getKey requires a key with a name\");\n }\n const response = await this.client.getKey(\n this.name,\n options && options.version ? options.version : this.version ? this.version : \"\",\n updatedOptions,\n );\n this.key = getKeyFromKeyBundle(response);\n }\n return this.key;\n },\n );\n }\n\n /**\n * A reference to the auto-generated KeyVault HTTP client.\n */\n private client: KeyVaultClient;\n\n /**\n * A reference to the key used for the cryptographic operations.\n * Based on what was provided to the CryptographyClient constructor,\n * it can be either a string with the URL of a Key Vault Key, or an already parsed {@link KeyVaultKey}.\n */\n private key: string | KeyVaultKey;\n\n /**\n * Name of the key the client represents\n */\n private name: string;\n\n /**\n * Version of the key the client represents\n */\n private version: string;\n\n /**\n * Attempts to retrieve the ID of the key.\n */\n private getKeyID(): string | undefined {\n let kid;\n if (typeof this.key !== \"string\") {\n kid = this.key.id;\n } else {\n kid = this.key;\n }\n\n return kid;\n }\n}\n\n/**\n * A helper method to either get the passed down generated client or initialize a new one.\n * An already constructed generated client may be passed down from {@link KeyClient} in which case we should reuse it.\n *\n * @internal\n * @param credential - The credential to use when initializing a new client.\n * @param options - The options for constructing a client or the underlying client if one already exists.\n * @returns - A generated client instance\n */\nfunction getOrInitializeClient(\n vaultUrl: string,\n credential: TokenCredential,\n options: CryptographyClientOptions & { generatedClient?: KeyVaultClient },\n): KeyVaultClient {\n if (options.generatedClient) {\n return options.generatedClient;\n }\n\n const libInfo = `azsdk-js-keyvault-keys/${SDK_VERSION}`;\n\n const userAgentOptions = options.userAgentOptions;\n\n options.userAgentOptions = {\n userAgentPrefix:\n userAgentOptions && userAgentOptions.userAgentPrefix\n ? `${userAgentOptions.userAgentPrefix} ${libInfo}`\n : libInfo,\n };\n\n const internalPipelineOptions: KeyVaultClientOptionalParams = {\n ...options,\n apiVersion: options.serviceVersion || LATEST_API_VERSION,\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [\n \"x-ms-keyvault-region\",\n \"x-ms-keyvault-network-info\",\n \"x-ms-keyvault-service-version\",\n ],\n },\n };\n\n const client = new KeyVaultClient(vaultUrl, credential, internalPipelineOptions);\n\n client.pipeline.removePolicy({ name: bearerTokenAuthenticationPolicyName });\n client.pipeline.addPolicy(keyVaultAuthenticationPolicy(credential, options));\n // Workaround for: https://github.com/Azure/azure-sdk-for-js/issues/31843\n client.pipeline.addPolicy({\n name: \"ContentTypePolicy\",\n sendRequest(request, next) {\n const contentType = request.headers.get(\"Content-Type\") ?? \"\";\n if (contentType.startsWith(\"application/json\")) {\n request.headers.set(\"Content-Type\", \"application/json\");\n }\n return next(request);\n },\n });\n\n return client;\n}\n"]}
1
+ {"version":3,"file":"remoteCryptographyProvider.js","sourceRoot":"","sources":["../../../src/cryptography/remoteCryptographyProvider.ts"],"names":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CAAC,OAAO,EAAE,IAAI;YACvB,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;YAC9D,IAAI,WAAW,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;gBAC/C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;YAC1D,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TokenCredential } from \"@azure/core-auth\";\n\nimport type {\n DecryptOptions,\n DecryptParameters,\n DecryptResult,\n EncryptOptions,\n EncryptParameters,\n EncryptResult,\n KeyWrapAlgorithm,\n SignOptions,\n SignResult,\n UnwrapKeyOptions,\n VerifyOptions,\n VerifyResult,\n WrapKeyOptions,\n WrapResult,\n} from \"../cryptographyClientModels.js\";\nimport { SDK_VERSION } from \"../constants.js\";\nimport type { UnwrapResult } from \"../cryptographyClientModels.js\";\nimport type { KeyVaultClientOptionalParams } from \"../generated/src/index.js\";\nimport { KeyVaultClient } from \"../generated/src/index.js\";\nimport { parseKeyVaultKeyIdentifier } from \"../identifier.js\";\nimport type { CryptographyClientOptions, GetKeyOptions, KeyVaultKey } from \"../keysModels.js\";\nimport { LATEST_API_VERSION } from \"../keysModels.js\";\nimport { getKeyFromKeyBundle } from \"../transformations.js\";\nimport { createHash } from \"./crypto.js\";\nimport type { CryptographyProvider, CryptographyProviderOperation } from \"./models.js\";\nimport { logger } from \"../log.js\";\nimport { keyVaultAuthenticationPolicy } from \"@azure/keyvault-common\";\nimport { tracingClient } from \"../tracing.js\";\nimport { bearerTokenAuthenticationPolicyName } from \"@azure/core-rest-pipeline\";\n\n/**\n * The remote cryptography provider is used to run crypto operations against KeyVault.\n * @internal\n */\nexport class RemoteCryptographyProvider implements CryptographyProvider {\n constructor(\n key: string | KeyVaultKey,\n credential: TokenCredential,\n pipelineOptions: CryptographyClientOptions = {},\n ) {\n this.key = key;\n\n let keyId: string;\n if (typeof key === \"string\") {\n keyId = key;\n } else {\n keyId = key.id!;\n }\n\n try {\n const parsed = parseKeyVaultKeyIdentifier(keyId);\n if (parsed.name === \"\") {\n throw new Error(\"Could not find 'name' of key in key URL\");\n }\n\n if (!parsed.vaultUrl || parsed.vaultUrl === \"\") {\n throw new Error(\"Could not find 'vaultUrl' of key in key URL\");\n }\n\n this.vaultUrl = parsed.vaultUrl;\n this.name = parsed.name;\n this.version = parsed.version ?? \"\";\n\n this.client = getOrInitializeClient(this.vaultUrl, credential, pipelineOptions);\n } catch (err: any) {\n logger.error(err);\n\n throw new Error(`${keyId} is not a valid Key Vault key ID`);\n }\n }\n\n // The remote client supports all algorithms and all operations.\n isSupported(_algorithm: string, _operation: CryptographyProviderOperation): boolean {\n return true;\n }\n\n encrypt(\n encryptParameters: EncryptParameters,\n options: EncryptOptions = {},\n ): Promise<EncryptResult> {\n const { algorithm, plaintext, ...params } = encryptParameters;\n const requestOptions = { ...options, ...params };\n\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.encrypt\",\n requestOptions,\n async (updatedOptions) => {\n const result = await this.client.encrypt(\n this.name,\n this.version,\n {\n algorithm,\n value: plaintext,\n aad:\n \"additionalAuthenticatedData\" in encryptParameters\n ? encryptParameters.additionalAuthenticatedData\n : undefined,\n iv: \"iv\" in encryptParameters ? encryptParameters.iv : undefined,\n },\n updatedOptions,\n );\n\n return {\n algorithm: encryptParameters.algorithm,\n result: result.result!,\n keyID: this.getKeyID(),\n additionalAuthenticatedData: result.additionalAuthenticatedData,\n authenticationTag: result.authenticationTag,\n iv: result.iv,\n };\n },\n );\n }\n\n decrypt(\n decryptParameters: DecryptParameters,\n options: DecryptOptions = {},\n ): Promise<DecryptResult> {\n const { algorithm, ciphertext, ...params } = decryptParameters;\n const requestOptions = { ...options, ...params };\n\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.decrypt\",\n requestOptions,\n async (updatedOptions) => {\n const result = await this.client.decrypt(\n this.name,\n this.version,\n {\n algorithm,\n value: ciphertext,\n aad:\n \"additionalAuthenticatedData\" in decryptParameters\n ? decryptParameters.additionalAuthenticatedData\n : undefined,\n iv: \"iv\" in decryptParameters ? decryptParameters.iv : undefined,\n tag:\n \"authenticationTag\" in decryptParameters\n ? decryptParameters.authenticationTag\n : undefined,\n },\n updatedOptions,\n );\n return {\n result: result.result!,\n keyID: this.getKeyID(),\n algorithm,\n };\n },\n );\n }\n\n wrapKey(\n algorithm: KeyWrapAlgorithm,\n keyToWrap: Uint8Array,\n options: WrapKeyOptions = {},\n ): Promise<WrapResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.wrapKey\",\n options,\n async (updatedOptions) => {\n const result = await this.client.wrapKey(\n this.name,\n this.version,\n {\n algorithm,\n value: keyToWrap,\n },\n updatedOptions,\n );\n\n return {\n result: result.result!,\n algorithm,\n keyID: this.getKeyID(),\n };\n },\n );\n }\n\n unwrapKey(\n algorithm: KeyWrapAlgorithm,\n encryptedKey: Uint8Array,\n options: UnwrapKeyOptions = {},\n ): Promise<UnwrapResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.unwrapKey\",\n options,\n async (updatedOptions) => {\n const result = await this.client.unwrapKey(\n this.name,\n this.version,\n {\n algorithm,\n value: encryptedKey,\n },\n updatedOptions,\n );\n\n return {\n result: result.result!,\n algorithm,\n keyID: this.getKeyID(),\n };\n },\n );\n }\n\n sign(algorithm: string, digest: Uint8Array, options: SignOptions = {}): Promise<SignResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.sign\",\n options,\n async (updatedOptions) => {\n const result = await this.client.sign(\n this.name,\n this.version,\n {\n algorithm,\n value: digest,\n },\n updatedOptions,\n );\n\n return { result: result.result!, algorithm, keyID: this.getKeyID() };\n },\n );\n }\n\n verifyData(\n algorithm: string,\n data: Uint8Array,\n signature: Uint8Array,\n options: VerifyOptions = {},\n ): Promise<VerifyResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.verifyData\",\n options,\n async (updatedOptions) => {\n const hash = await createHash(algorithm, data);\n return this.verify(algorithm, hash, signature, updatedOptions);\n },\n );\n }\n\n verify(\n algorithm: string,\n digest: Uint8Array,\n signature: Uint8Array,\n options: VerifyOptions = {},\n ): Promise<VerifyResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.verify\",\n options,\n async (updatedOptions) => {\n const response = await this.client.verify(\n this.name,\n this.version,\n {\n algorithm,\n digest,\n signature,\n },\n updatedOptions,\n );\n return {\n result: response.value ? response.value : false,\n keyID: this.getKeyID(),\n };\n },\n );\n }\n\n signData(algorithm: string, data: Uint8Array, options: SignOptions = {}): Promise<SignResult> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.signData\",\n options,\n async (updatedOptions) => {\n const digest = await createHash(algorithm, data);\n const result = await this.client.sign(\n this.name,\n this.version,\n {\n algorithm,\n value: digest,\n },\n updatedOptions,\n );\n return { result: result.result!, algorithm, keyID: this.getKeyID() };\n },\n );\n }\n\n /**\n * The base URL to the vault.\n */\n readonly vaultUrl: string;\n\n /**\n * The ID of the key used to perform cryptographic operations for the client.\n */\n get keyId(): string | undefined {\n return this.getKeyID();\n }\n\n /**\n * Gets the {@link KeyVaultKey} used for cryptography operations, fetching it\n * from KeyVault if necessary.\n * @param options - Additional options.\n */\n getKey(options: GetKeyOptions = {}): Promise<KeyVaultKey> {\n return tracingClient.withSpan(\n \"RemoteCryptographyProvider.getKey\",\n options,\n async (updatedOptions) => {\n if (typeof this.key === \"string\") {\n if (!this.name || this.name === \"\") {\n throw new Error(\"getKey requires a key with a name\");\n }\n const response = await this.client.getKey(\n this.name,\n options && options.version ? options.version : this.version ? this.version : \"\",\n updatedOptions,\n );\n this.key = getKeyFromKeyBundle(response);\n }\n return this.key;\n },\n );\n }\n\n /**\n * A reference to the auto-generated KeyVault HTTP client.\n */\n private client: KeyVaultClient;\n\n /**\n * A reference to the key used for the cryptographic operations.\n * Based on what was provided to the CryptographyClient constructor,\n * it can be either a string with the URL of a Key Vault Key, or an already parsed {@link KeyVaultKey}.\n */\n private key: string | KeyVaultKey;\n\n /**\n * Name of the key the client represents\n */\n private name: string;\n\n /**\n * Version of the key the client represents\n */\n private version: string;\n\n /**\n * Attempts to retrieve the ID of the key.\n */\n private getKeyID(): string | undefined {\n let kid;\n if (typeof this.key !== \"string\") {\n kid = this.key.id;\n } else {\n kid = this.key;\n }\n\n return kid;\n }\n}\n\n/**\n * A helper method to either get the passed down generated client or initialize a new one.\n * An already constructed generated client may be passed down from {@link KeyClient} in which case we should reuse it.\n *\n * @internal\n * @param credential - The credential to use when initializing a new client.\n * @param options - The options for constructing a client or the underlying client if one already exists.\n * @returns - A generated client instance\n */\nfunction getOrInitializeClient(\n vaultUrl: string,\n credential: TokenCredential,\n options: CryptographyClientOptions & { generatedClient?: KeyVaultClient },\n): KeyVaultClient {\n if (options.generatedClient) {\n return options.generatedClient;\n }\n\n const libInfo = `azsdk-js-keyvault-keys/${SDK_VERSION}`;\n\n const userAgentOptions = options.userAgentOptions;\n\n options.userAgentOptions = {\n userAgentPrefix:\n userAgentOptions && userAgentOptions.userAgentPrefix\n ? `${userAgentOptions.userAgentPrefix} ${libInfo}`\n : libInfo,\n };\n\n const internalPipelineOptions: KeyVaultClientOptionalParams = {\n ...options,\n apiVersion: options.serviceVersion || LATEST_API_VERSION,\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [\n \"x-ms-keyvault-region\",\n \"x-ms-keyvault-network-info\",\n \"x-ms-keyvault-service-version\",\n ],\n },\n };\n\n const client = new KeyVaultClient(vaultUrl, credential, internalPipelineOptions);\n\n client.pipeline.removePolicy({ name: bearerTokenAuthenticationPolicyName });\n client.pipeline.addPolicy(keyVaultAuthenticationPolicy(credential, options));\n // Workaround for: https://github.com/Azure/azure-sdk-for-js/issues/31843\n client.pipeline.addPolicy({\n name: \"ContentTypePolicy\",\n sendRequest(request, next) {\n const contentType = request.headers.get(\"Content-Type\") ?? \"\";\n if (contentType.startsWith(\"application/json\")) {\n request.headers.set(\"Content-Type\", \"application/json\");\n }\n return next(request);\n },\n });\n\n return client;\n}\n"]}
@@ -13,39 +13,6 @@ const models_js_1 = require("./models.js");
13
13
  */
14
14
  class RsaCryptographyProvider {
15
15
  constructor(key) {
16
- /**
17
- * The set of algorithms this provider supports
18
- */
19
- this.applicableAlgorithms = [
20
- "RSA1_5",
21
- "RSA-OAEP",
22
- "PS256",
23
- "RS256",
24
- "PS384",
25
- "RS384",
26
- "PS512",
27
- "RS512",
28
- ];
29
- /**
30
- * The set of operations this provider supports
31
- */
32
- this.applicableOperations = [
33
- "encrypt",
34
- "wrapKey",
35
- "verifyData",
36
- ];
37
- /**
38
- * Mapping between signature algorithms and their corresponding hash algorithms. Externally used for testing.
39
- * @internal
40
- */
41
- this.signatureAlgorithmToHashAlgorithm = {
42
- PS256: "SHA256",
43
- RS256: "SHA256",
44
- PS384: "SHA384",
45
- RS384: "SHA384",
46
- PS512: "SHA512",
47
- RS512: "SHA512",
48
- };
49
16
  this.key = key;
50
17
  }
51
18
  isSupported(algorithm, operation) {
@@ -95,11 +62,47 @@ class RsaCryptographyProvider {
95
62
  keyID: this.key.kid,
96
63
  });
97
64
  }
65
+ /**
66
+ * The {@link JsonWebKey} used to perform crypto operations.
67
+ */
68
+ key;
69
+ /**
70
+ * The set of algorithms this provider supports
71
+ */
72
+ applicableAlgorithms = [
73
+ "RSA1_5",
74
+ "RSA-OAEP",
75
+ "PS256",
76
+ "RS256",
77
+ "PS384",
78
+ "RS384",
79
+ "PS512",
80
+ "RS512",
81
+ ];
82
+ /**
83
+ * The set of operations this provider supports
84
+ */
85
+ applicableOperations = [
86
+ "encrypt",
87
+ "wrapKey",
88
+ "verifyData",
89
+ ];
90
+ /**
91
+ * Mapping between signature algorithms and their corresponding hash algorithms. Externally used for testing.
92
+ * @internal
93
+ */
94
+ signatureAlgorithmToHashAlgorithm = {
95
+ PS256: "SHA256",
96
+ RS256: "SHA256",
97
+ PS384: "SHA384",
98
+ RS384: "SHA384",
99
+ PS512: "SHA512",
100
+ RS512: "SHA512",
101
+ };
98
102
  ensureValid() {
99
- var _a, _b;
100
103
  if (this.key &&
101
- ((_a = this.key.kty) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== "RSA" &&
102
- ((_b = this.key.kty) === null || _b === void 0 ? void 0 : _b.toUpperCase()) !== "RSA-HSM") {
104
+ this.key.kty?.toUpperCase() !== "RSA" &&
105
+ this.key.kty?.toUpperCase() !== "RSA-HSM") {
103
106
  throw new Error("Key type does not match the algorithm RSA");
104
107
  }
105
108
  }