forked from aws/aws-encryption-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkms_mrk_keyring_browser.ts
57 lines (49 loc) · 1.65 KB
/
kms_mrk_keyring_browser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
AwsKmsMrkAwareSymmetricKeyringClass,
AwsKmsMrkAwareSymmetricKeyringInput,
AwsEsdkKMSInterface,
} from '@aws-crypto/kms-keyring'
import {
WebCryptoAlgorithmSuite,
WebCryptoEncryptionMaterial,
WebCryptoDecryptionMaterial,
EncryptedDataKey,
immutableClass,
importForWebCryptoEncryptionMaterial,
importForWebCryptoDecryptionMaterial,
KeyringWebCrypto,
Newable,
} from '@aws-crypto/material-management-browser'
export type AwsKmsMrkAwareSymmetricKeyringWebCryptoInput =
AwsKmsMrkAwareSymmetricKeyringInput<AwsEsdkKMSInterface>
export class AwsKmsMrkAwareSymmetricKeyringBrowser extends AwsKmsMrkAwareSymmetricKeyringClass<
WebCryptoAlgorithmSuite,
AwsEsdkKMSInterface
>(KeyringWebCrypto as Newable<KeyringWebCrypto>) {
declare client: AwsEsdkKMSInterface
declare keyId: string
declare grantTokens?: string[]
constructor({
client,
keyId,
grantTokens,
}: AwsKmsMrkAwareSymmetricKeyringWebCryptoInput) {
super({ client, keyId, grantTokens })
}
async _onEncrypt(
material: WebCryptoEncryptionMaterial
): Promise<WebCryptoEncryptionMaterial> {
const _material = await super._onEncrypt(material)
return importForWebCryptoEncryptionMaterial(_material)
}
async _onDecrypt(
material: WebCryptoDecryptionMaterial,
encryptedDataKeys: EncryptedDataKey[]
): Promise<WebCryptoDecryptionMaterial> {
const _material = await super._onDecrypt(material, encryptedDataKeys)
return importForWebCryptoDecryptionMaterial(_material)
}
}
immutableClass(AwsKmsMrkAwareSymmetricKeyringBrowser)