@@ -219,19 +219,27 @@ export function getCacheEntryId(
219
219
}
220
220
221
221
export async function getBranchKeyMaterials (
222
- { keyStore , cacheLimitTtl } : IKmsHierarchicalKeyRingNode ,
222
+ hKeyring : IKmsHierarchicalKeyRingNode ,
223
223
cmc : CryptographicMaterialsCache < NodeAlgorithmSuite > ,
224
224
branchKeyId : string ,
225
225
cacheEntryId : string ,
226
226
branchKeyVersion ?: string
227
227
) : Promise < NodeBranchKeyMaterial > {
228
+ const { keyStore, cacheLimitTtl } = hKeyring
229
+
228
230
//= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-hierarchical-keyring.md#onencrypt
229
231
//# The hierarchical keyring MUST attempt to find [branch key materials](../structures.md#branch-key-materials)
230
232
//# from the underlying [cryptographic materials cache](../local-cryptographic-materials-cache.md).
231
233
const cacheEntry = cmc . getBranchKeyMaterial ( cacheEntryId )
232
234
let branchKeyMaterials : NodeBranchKeyMaterial
233
235
// if the cache entry is false, branch key materials were not found
234
- if ( ! cacheEntry ) {
236
+ if ( ! cacheEntry || hKeyring . cacheEntryHasExceededLimits ( cacheEntry ) ) {
237
+ //= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-hierarchical-keyring.md#onencrypt
238
+ //# If this is NOT true, then we MUST treat the cache entry as expired.
239
+
240
+ //= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-hierarchical-keyring.md#ondecrypt
241
+ //# If this is NOT true, then we MUST treat the cache entry as expired.
242
+
235
243
//= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-hierarchical-keyring.md#onencrypt
236
244
//# If a cache entry is not found or the cache entry is expired, the hierarchical keyring MUST attempt to obtain the branch key materials
237
245
//# by querying the backing branch keystore specified in the [retrieve OnEncrypt branch key materials](#query-branch-keystore-onencrypt) section.
@@ -245,8 +253,8 @@ export async function getBranchKeyMaterials(
245
253
//= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-hierarchical-keyring.md#getitem-branch-keystore-ondecrypt
246
254
//# Otherwise, OnDecrypt MUST fail.
247
255
248
- // get them from the keystore, whether we need the active or versioned
249
- // material
256
+ //= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-hierarchical-keyring.md#query-branch- keystore-onencrypt
257
+ //# OnEncrypt MUST call the Keystore's [GetActiveBranchKey](../branch-key-store.md#getactivebranchkey) operation with the following inputs:
250
258
251
259
//= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-hierarchical-keyring.md#getitem-branch-keystore-ondecrypt
252
260
//# OnDecrypt MUST call the Keystore's [GetBranchKeyVersion](../branch-key-store.md#getbranchkeyversion) operation with the following inputs:
0 commit comments