in modules/cache-material/src/caching_cryptographic_materials_decorators.ts [25:78]
export function decorateProperties<S extends SupportedAlgorithmSuites>(
obj: CachingMaterialsManager<S>,
input: CachingMaterialsManagerDecorateInput<S>
) {
const {
cache,
backingMaterialsManager,
maxAge,
maxBytesEncrypted,
maxMessagesEncrypted,
partition,
} = input
/* Precondition: A caching material manager needs a cache. */
needs(cache, 'You must provide a cache.')
/* Precondition: A caching material manager needs a way to get material. */
needs(backingMaterialsManager, 'You must provide a backing material source.')
/* Precondition: You *can not* cache something forever. */
needs(maxAge > 0, 'You must configure a maxAge')
/* Precondition: maxBytesEncrypted must be inside bounds. i.e. positive and not more than the maximum. */
needs(
!maxBytesEncrypted ||
(maxBytesEncrypted > 0 &&
Maximum.BYTES_PER_CACHED_KEY_LIMIT >= maxBytesEncrypted),
'maxBytesEncrypted is outside of bounds.'
)
/* Precondition: maxMessagesEncrypted must be inside bounds. i.e. positive and not more than the maximum. */
needs(
!maxMessagesEncrypted ||
(maxMessagesEncrypted > 0 &&
Maximum.MESSAGES_PER_CACHED_KEY_LIMIT >= maxMessagesEncrypted),
'maxMessagesEncrypted is outside of bounds.'
)
/* Precondition: partition must be a string. */
needs(
partition && typeof partition === 'string',
'partition must be a string.'
)
readOnlyProperty(obj, '_cache', cache)
readOnlyProperty(obj, '_backingMaterialsManager', backingMaterialsManager)
readOnlyProperty(obj, '_maxAge', maxAge)
readOnlyProperty(
obj,
'_maxBytesEncrypted',
maxBytesEncrypted || Maximum.BYTES_PER_CACHED_KEY_LIMIT
)
readOnlyProperty(
obj,
'_maxMessagesEncrypted',
maxMessagesEncrypted || Maximum.MESSAGES_PER_CACHED_KEY_LIMIT
)
readOnlyProperty(obj, '_partition', partition)
}