Skip to content

Commit d8220e3

Browse files
committed
even better name
1 parent 9d3283e commit d8220e3

6 files changed

+105
-105
lines changed

modules/cache-material/src/build_cryptographic_materials_cache_key_helpers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ export function buildCryptographicMaterialsCacheKeyHelpers<S extends SupportedAl
3737
} = serializeFactory(fromUtf8)
3838

3939
return {
40-
buildEncryptionResponseCacheKey,
41-
buildDecryptionResponseCacheKey,
40+
buildEncryptionMaterialCacheKey,
41+
buildDecryptionMaterialCacheKey,
4242
encryptedDataKeysHash,
4343
encryptionContextHash
4444
}
4545

46-
async function buildEncryptionResponseCacheKey (
46+
async function buildEncryptionMaterialCacheKey (
4747
partition: string,
4848
{ suite, encryptionContext }: EncryptionRequest<S>
4949
) {
@@ -59,7 +59,7 @@ export function buildCryptographicMaterialsCacheKeyHelpers<S extends SupportedAl
5959
return toUtf8(key)
6060
}
6161

62-
async function buildDecryptionResponseCacheKey (
62+
async function buildDecryptionMaterialCacheKey (
6363
partition: string,
6464
{ suite, encryptedDataKeys, encryptionContext }: DecryptionRequest<S>
6565
) {
@@ -96,11 +96,11 @@ export function buildCryptographicMaterialsCacheKeyHelpers<S extends SupportedAl
9696
}
9797

9898
export interface CryptographicMaterialsCacheKeyHelpersInterface<S extends SupportedAlgorithmSuites> {
99-
buildEncryptionResponseCacheKey(
99+
buildEncryptionMaterialCacheKey(
100100
partition: string,
101101
{ suite, encryptionContext }: EncryptionRequest<S>
102102
): Promise<string>
103-
buildDecryptionResponseCacheKey(
103+
buildDecryptionMaterialCacheKey(
104104
partition: string,
105105
{ suite, encryptedDataKeys, encryptionContext }: DecryptionRequest<S>
106106
): Promise<string>

modules/cache-material/src/caching_cryptographic_materials_decorators.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ export function decorateProperties<S extends SupportedAlgorithmSuites> (
6464
}
6565

6666
export function getEncryptionMaterials<S extends SupportedAlgorithmSuites> (
67-
{ buildEncryptionResponseCacheKey }: CryptographicMaterialsCacheKeyHelpersInterface<S>
67+
{ buildEncryptionMaterialCacheKey }: CryptographicMaterialsCacheKeyHelpersInterface<S>
6868
): GetEncryptionMaterials<S> {
6969
return async function getEncryptionMaterials (
7070
this: CachingMaterialsManager<S>,
7171
request: EncryptionRequest<S>
7272
): Promise<EncryptionMaterial<S>> {
7373
const { suite, encryptionContext, frameLength, plaintextLength } = request
74-
/* Check for early return (Postcondition): If I can not cache the EncryptionResponse, do not even look. */
74+
/* Check for early return (Postcondition): If I can not cache the EncryptionMaterial, do not even look. */
7575
if ((suite && !suite.cacheSafe) || typeof plaintextLength !== 'number' || plaintextLength < 0) {
7676
return this
7777
._backingMaterialsManager
7878
.getEncryptionMaterials(request)
7979
}
8080

81-
const cacheKey = await buildEncryptionResponseCacheKey(this._partition, { suite, encryptionContext })
82-
const entry = this._cache.getEncryptionResponse(cacheKey, plaintextLength)
83-
/* Check for early return (Postcondition): If I have a valid EncryptionResponse, return it. */
81+
const cacheKey = await buildEncryptionMaterialCacheKey(this._partition, { suite, encryptionContext })
82+
const entry = this._cache.getEncryptionMaterial(cacheKey, plaintextLength)
83+
/* Check for early return (Postcondition): If I have a valid EncryptionMaterial, return it. */
8484
if (entry && !this._cacheEntryHasExceededLimits(entry)) {
8585
return cloneResponse(entry.response)
8686
} else {
@@ -94,7 +94,7 @@ export function getEncryptionMaterials<S extends SupportedAlgorithmSuites> (
9494
*/
9595
.getEncryptionMaterials({ suite, encryptionContext, frameLength })
9696

97-
/* Check for early return (Postcondition): If I can not cache the EncryptionResponse, just return it. */
97+
/* Check for early return (Postcondition): If I can not cache the EncryptionMaterial, just return it. */
9898
if (!material.suite.cacheSafe) return material
9999

100100
/* It is possible for an entry to exceed limits immediately.
@@ -109,31 +109,31 @@ export function getEncryptionMaterials<S extends SupportedAlgorithmSuites> (
109109
bytesEncrypted: plaintextLength
110110
}
111111
if (!this._cacheEntryHasExceededLimits(testEntry)) {
112-
this._cache.putEncryptionResponse(cacheKey, material, plaintextLength, this._maxAge)
112+
this._cache.putEncryptionMaterial(cacheKey, material, plaintextLength, this._maxAge)
113113
}
114114

115115
return cloneResponse(material)
116116
}
117117
}
118118

119119
export function decryptMaterials<S extends SupportedAlgorithmSuites> (
120-
{ buildDecryptionResponseCacheKey }: CryptographicMaterialsCacheKeyHelpersInterface<S>
120+
{ buildDecryptionMaterialCacheKey }: CryptographicMaterialsCacheKeyHelpersInterface<S>
121121
): GetDecryptMaterials<S> {
122122
return async function decryptMaterials (
123123
this: CachingMaterialsManager<S>,
124124
request: DecryptionRequest<S>
125125
): Promise<DecryptionMaterial<S>> {
126126
const { suite } = request
127-
/* Check for early return (Postcondition): If I can not cache the DecryptionResponse, do not even look. */
127+
/* Check for early return (Postcondition): If I can not cache the DecryptionMaterial, do not even look. */
128128
if (!suite.cacheSafe) {
129129
return this
130130
._backingMaterialsManager
131131
.decryptMaterials(request)
132132
}
133133

134-
const cacheKey = await buildDecryptionResponseCacheKey(this._partition, request)
135-
const entry = this._cache.getDecryptionResponse(cacheKey)
136-
/* Check for early return (Postcondition): If I have a valid DecryptionResponse, return it. */
134+
const cacheKey = await buildDecryptionMaterialCacheKey(this._partition, request)
135+
const entry = this._cache.getDecryptionMaterial(cacheKey)
136+
/* Check for early return (Postcondition): If I have a valid DecryptionMaterial, return it. */
137137
if (entry && !this._cacheEntryHasExceededLimits(entry)) {
138138
return cloneResponse(entry.response)
139139
} else {
@@ -144,7 +144,7 @@ export function decryptMaterials<S extends SupportedAlgorithmSuites> (
144144
._backingMaterialsManager
145145
.decryptMaterials(request)
146146

147-
this._cache.putDecryptionResponse(cacheKey, material, this._maxAge)
147+
this._cache.putDecryptionMaterial(cacheKey, material, this._maxAge)
148148
return cloneResponse(material)
149149
}
150150
}
@@ -166,8 +166,8 @@ export function cacheEntryHasExceededLimits<S extends SupportedAlgorithmSuites>
166166
* Because when the Encryption SDK is done with material, it will zero it out.
167167
* Plucking off the material and cloning just that and then returning the rest of the response
168168
* can just be handled in one place.
169-
* @param material EncryptionResponse|DecryptionResponse
170-
* @return EncryptionResponse|DecryptionResponse
169+
* @param material EncryptionMaterial|DecryptionMaterial
170+
* @return EncryptionMaterial|DecryptionMaterial
171171
*/
172172
function cloneResponse<S extends SupportedAlgorithmSuites, M extends EncryptionMaterial<S>|DecryptionMaterial<S>> (
173173
material: M

modules/cache-material/src/cryptographic_materials_cache.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ import {
2020
} from '@aws-crypto/material-management'
2121

2222
export interface CryptographicMaterialsCache<S extends SupportedAlgorithmSuites> {
23-
putEncryptionResponse(
23+
putEncryptionMaterial(
2424
key: string,
2525
response: EncryptionMaterial<S>,
2626
plaintextLength: number,
2727
maxAge?: number
2828
): void
29-
putDecryptionResponse(
29+
putDecryptionMaterial(
3030
key: string,
3131
response: DecryptionMaterial<S>,
3232
maxAge?: number
3333
): void
34-
getEncryptionResponse(key: string, plaintextLength: number): EncryptionResponseEntry<S>|false
35-
getDecryptionResponse(key: string): DecryptionResponseEntry<S>|false
34+
getEncryptionMaterial(key: string, plaintextLength: number): EncryptionMaterialEntry<S>|false
35+
getDecryptionMaterial(key: string): DecryptionMaterialEntry<S>|false
3636
del(key: string): void
3737
}
3838

@@ -43,10 +43,10 @@ export interface Entry<S extends SupportedAlgorithmSuites> {
4343
readonly now: number
4444
}
4545

46-
export interface EncryptionResponseEntry<S extends SupportedAlgorithmSuites> extends Entry<S> {
46+
export interface EncryptionMaterialEntry<S extends SupportedAlgorithmSuites> extends Entry<S> {
4747
readonly response: EncryptionMaterial<S>
4848
}
4949

50-
export interface DecryptionResponseEntry<S extends SupportedAlgorithmSuites> extends Entry<S> {
50+
export interface DecryptionMaterialEntry<S extends SupportedAlgorithmSuites> extends Entry<S> {
5151
readonly response: DecryptionMaterial<S>
5252
}

modules/cache-material/src/get_local_cryptographic_materials_cache.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import {
2626
import {
2727
CryptographicMaterialsCache, // eslint-disable-line no-unused-vars
2828
Entry, // eslint-disable-line no-unused-vars
29-
EncryptionResponseEntry, // eslint-disable-line no-unused-vars
30-
DecryptionResponseEntry // eslint-disable-line no-unused-vars
29+
EncryptionMaterialEntry, // eslint-disable-line no-unused-vars
30+
DecryptionMaterialEntry // eslint-disable-line no-unused-vars
3131
} from './cryptographic_materials_cache'
3232

3333
export function getLocalCryptographicMaterialsCache<S extends SupportedAlgorithmSuites> (
@@ -71,13 +71,13 @@ export function getLocalCryptographicMaterialsCache<S extends SupportedAlgorithm
7171
})()
7272

7373
return {
74-
putEncryptionResponse (
74+
putEncryptionMaterial (
7575
key: string,
7676
material: EncryptionMaterial<S>,
7777
plaintextLength: number,
7878
maxAge?: number
7979
) {
80-
/* Precondition: putEncryptionResponse plaintextLength can not be negative. */
80+
/* Precondition: putEncryptionMaterial plaintextLength can not be negative. */
8181
needs(plaintextLength >= 0, 'Malformed plaintextLength')
8282
/* Precondition: Only cache EncryptionMaterial. */
8383
needs(isEncryptionMaterial(material), 'Malformed response.')
@@ -92,7 +92,7 @@ export function getLocalCryptographicMaterialsCache<S extends SupportedAlgorithm
9292

9393
cache.set(key, entry, maxAge)
9494
},
95-
putDecryptionResponse (
95+
putDecryptionMaterial (
9696
key: string,
9797
material: DecryptionMaterial<S>,
9898
maxAge?: number
@@ -110,7 +110,7 @@ export function getLocalCryptographicMaterialsCache<S extends SupportedAlgorithm
110110

111111
cache.set(key, entry, maxAge)
112112
},
113-
getEncryptionResponse (key: string, plaintextLength: number) {
113+
getEncryptionMaterial (key: string, plaintextLength: number) {
114114
/* Precondition: plaintextLength can not be negative. */
115115
needs(plaintextLength >= 0, 'Malformed plaintextLength')
116116
const entry = cache.get(key)
@@ -122,16 +122,16 @@ export function getLocalCryptographicMaterialsCache<S extends SupportedAlgorithm
122122
entry.bytesEncrypted += plaintextLength
123123
entry.messagesEncrypted += 1
124124

125-
return <EncryptionResponseEntry<S>>entry
125+
return <EncryptionMaterialEntry<S>>entry
126126
},
127-
getDecryptionResponse (key: string) {
127+
getDecryptionMaterial (key: string) {
128128
const entry = cache.get(key)
129129
/* Check for early return (Postcondition): If this key does not have a DecryptionMaterial, return false. */
130130
if (!entry) return false
131131
/* Postcondition: Only return DecryptionMaterial. */
132132
needs(isDecryptionMaterial(entry.response), 'Malformed response.')
133133

134-
return <DecryptionResponseEntry<S>>entry
134+
return <DecryptionMaterialEntry<S>>entry
135135
},
136136
del (key: string) {
137137
cache.del(key)

modules/cache-material/test/build_cryptographic_materials_cache_key_helpers.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const sha512 = async (...data: (Uint8Array|string)[]) => data
3131
const {
3232
encryptionContextHash,
3333
encryptedDataKeysHash,
34-
buildEncryptionResponseCacheKey,
35-
buildDecryptionResponseCacheKey
34+
buildEncryptionMaterialCacheKey,
35+
buildDecryptionMaterialCacheKey
3636
} = buildCryptographicMaterialsCacheKeyHelpers(fromUtf8, toUtf8, sha512)
3737

3838
describe('buildCryptographicMaterialsCacheKeyHelpers::encryptionContextHash', () => {
@@ -54,19 +54,19 @@ describe('buildCryptographicMaterialsCacheKeyHelpers::encryptedDataKeysHash', ()
5454
}
5555
})
5656

57-
describe('buildCryptographicMaterialsCacheKeyHelpers::buildEncryptionResponseCacheKey', () => {
57+
describe('buildCryptographicMaterialsCacheKeyHelpers::buildEncryptionMaterialCacheKey', () => {
5858
for (const vector of encryptCacheKeyVectors) {
5959
it(`${vector.id}`, async () => {
60-
const test = await buildEncryptionResponseCacheKey(...vector.arguments)
60+
const test = await buildEncryptionMaterialCacheKey(...vector.arguments)
6161
expect(test).to.equal(Buffer.from(vector.id, 'base64').toString())
6262
})
6363
}
6464
})
6565

66-
describe('buildCryptographicMaterialsCacheKeyHelpers::buildEncryptionResponseCacheKey', () => {
66+
describe('buildCryptographicMaterialsCacheKeyHelpers::buildEncryptionMaterialCacheKey', () => {
6767
for (const vector of decryptCacheKeyVectors) {
6868
it(`${vector.id}`, async () => {
69-
const test = await buildDecryptionResponseCacheKey(...vector.arguments)
69+
const test = await buildDecryptionMaterialCacheKey(...vector.arguments)
7070
expect(test).to.equal(Buffer.from(vector.id, 'base64').toString())
7171
})
7272
}

0 commit comments

Comments
 (0)