13
13
* limitations under the License.
14
14
*/
15
15
16
- import { MixedBackendCryptoKey , SupportedAlgorithmSuites } from './types' // eslint-disable-line no-unused-vars
16
+ import { MixedBackendCryptoKey , SupportedAlgorithmSuites , AwsEsdkJsCryptoKey , AwsEsdkJsKeyUsage } from './types' // eslint-disable-line no-unused-vars
17
17
import { EncryptedDataKey } from './encrypted_data_key'
18
18
import { SignatureKey , VerificationKey } from './signature_key'
19
19
import { frozenClass , readOnlyProperty } from './immutable_class'
@@ -97,10 +97,10 @@ export interface DecryptionMaterial<T extends CryptographicMaterial<T>> extends
97
97
}
98
98
99
99
export interface WebCryptoMaterial < T extends CryptographicMaterial < T > > extends CryptographicMaterial < T > {
100
- setCryptoKey : ( dataKey : CryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => T
101
- getCryptoKey : ( ) => CryptoKey | MixedBackendCryptoKey
100
+ setCryptoKey : ( dataKey : AwsEsdkJsCryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => T
101
+ getCryptoKey : ( ) => AwsEsdkJsCryptoKey | MixedBackendCryptoKey
102
102
hasCryptoKey : boolean
103
- validUsages : ReadonlyArray < KeyUsage >
103
+ validUsages : ReadonlyArray < AwsEsdkJsKeyUsage >
104
104
}
105
105
106
106
export class NodeEncryptionMaterial implements
@@ -178,15 +178,15 @@ export class WebCryptoEncryptionMaterial implements
178
178
addEncryptedDataKey ! : ( edk : EncryptedDataKey , flags : KeyringTraceFlag ) => WebCryptoEncryptionMaterial
179
179
setSignatureKey ! : ( key : SignatureKey ) => WebCryptoEncryptionMaterial
180
180
signatureKey ?: SignatureKey
181
- setCryptoKey ! : ( dataKey : CryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => WebCryptoEncryptionMaterial
182
- getCryptoKey ! : ( ) => CryptoKey | MixedBackendCryptoKey
181
+ setCryptoKey ! : ( dataKey : AwsEsdkJsCryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => WebCryptoEncryptionMaterial
182
+ getCryptoKey ! : ( ) => AwsEsdkJsCryptoKey | MixedBackendCryptoKey
183
183
hasCryptoKey ! : boolean
184
- validUsages : ReadonlyArray < KeyUsage >
184
+ validUsages : ReadonlyArray < AwsEsdkJsKeyUsage >
185
185
constructor ( suite : WebCryptoAlgorithmSuite ) {
186
186
/* Precondition: WebCryptoEncryptionMaterial suite must be WebCryptoAlgorithmSuite. */
187
187
needs ( suite instanceof WebCryptoAlgorithmSuite , 'Suite must be a WebCryptoAlgorithmSuite' )
188
188
this . suite = suite
189
- this . validUsages = Object . freeze ( < KeyUsage [ ] > [ 'deriveKey' , 'encrypt' ] )
189
+ this . validUsages = Object . freeze ( < AwsEsdkJsKeyUsage [ ] > [ 'deriveKey' , 'encrypt' ] )
190
190
// EncryptionMaterial have generated a data key on setUnencryptedDataKey
191
191
const setFlag = KeyringTraceFlag . WRAPPING_KEY_GENERATED_DATA_KEY
192
192
decorateCryptographicMaterial < WebCryptoEncryptionMaterial > ( this , setFlag )
@@ -214,15 +214,15 @@ export class WebCryptoDecryptionMaterial implements
214
214
keyringTrace : KeyringTrace [ ] = [ ]
215
215
setVerificationKey ! : ( key : VerificationKey ) => WebCryptoDecryptionMaterial
216
216
verificationKey ?: VerificationKey
217
- setCryptoKey ! : ( dataKey : CryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => WebCryptoDecryptionMaterial
218
- getCryptoKey ! : ( ) => CryptoKey | MixedBackendCryptoKey
217
+ setCryptoKey ! : ( dataKey : AwsEsdkJsCryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => WebCryptoDecryptionMaterial
218
+ getCryptoKey ! : ( ) => AwsEsdkJsCryptoKey | MixedBackendCryptoKey
219
219
hasCryptoKey ! : boolean
220
- validUsages : ReadonlyArray < KeyUsage >
220
+ validUsages : ReadonlyArray < AwsEsdkJsKeyUsage >
221
221
constructor ( suite : WebCryptoAlgorithmSuite ) {
222
222
/* Precondition: WebCryptoDecryptionMaterial suite must be WebCryptoAlgorithmSuite. */
223
223
needs ( suite instanceof WebCryptoAlgorithmSuite , 'Suite must be a WebCryptoAlgorithmSuite' )
224
224
this . suite = suite
225
- this . validUsages = Object . freeze ( < KeyUsage [ ] > [ 'deriveKey' , 'decrypt' ] )
225
+ this . validUsages = Object . freeze ( < AwsEsdkJsKeyUsage [ ] > [ 'deriveKey' , 'decrypt' ] )
226
226
// DecryptionMaterial have decrypted a data key on setUnencryptedDataKey
227
227
const setFlag = KeyringTraceFlag . WRAPPING_KEY_DECRYPTED_DATA_KEY
228
228
decorateCryptographicMaterial < WebCryptoDecryptionMaterial > ( this , setFlag )
@@ -460,9 +460,9 @@ export function decorateDecryptionMaterial<T extends DecryptionMaterial<T>> (mat
460
460
}
461
461
462
462
export function decorateWebCryptoMaterial < T extends WebCryptoMaterial < T > > ( material : T , setFlags : KeyringTraceFlag ) {
463
- let cryptoKey : Readonly < CryptoKey | MixedBackendCryptoKey > | undefined
463
+ let cryptoKey : Readonly < AwsEsdkJsCryptoKey | MixedBackendCryptoKey > | undefined
464
464
465
- const setCryptoKey = ( dataKey : CryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => {
465
+ const setCryptoKey = ( dataKey : AwsEsdkJsCryptoKey | MixedBackendCryptoKey , trace : KeyringTrace ) => {
466
466
/* Precondition: cryptoKey must not be set. Modifying the cryptoKey is denied */
467
467
needs ( ! cryptoKey , 'cryptoKey is already set.' )
468
468
/* Precondition: dataKey must be a supported type. */
@@ -504,7 +504,7 @@ export function decorateWebCryptoMaterial<T extends WebCryptoMaterial<T>> (mater
504
504
needs ( cryptoKey , 'Crypto key is not set.' )
505
505
// In the case of MixedBackendCryptoKey the object
506
506
// has already been frozen above so it is safe to return
507
- return < Readonly < CryptoKey | MixedBackendCryptoKey > > cryptoKey
507
+ return < Readonly < AwsEsdkJsCryptoKey | MixedBackendCryptoKey > > cryptoKey
508
508
}
509
509
readOnlyProperty ( material , 'getCryptoKey' , getCryptoKey )
510
510
@@ -516,7 +516,7 @@ export function decorateWebCryptoMaterial<T extends WebCryptoMaterial<T>> (mater
516
516
return material
517
517
}
518
518
519
- export function isCryptoKey ( dataKey : any ) : dataKey is CryptoKey {
519
+ export function isCryptoKey ( dataKey : any ) : dataKey is AwsEsdkJsCryptoKey {
520
520
return dataKey &&
521
521
'algorithm' in dataKey &&
522
522
'type' in dataKey &&
@@ -526,7 +526,7 @@ export function isCryptoKey (dataKey: any): dataKey is CryptoKey {
526
526
}
527
527
528
528
export function isValidCryptoKey < T extends WebCryptoMaterial < T > > (
529
- dataKey : CryptoKey | MixedBackendCryptoKey ,
529
+ dataKey : AwsEsdkJsCryptoKey | MixedBackendCryptoKey ,
530
530
material : T
531
531
) : boolean {
532
532
if ( ! isCryptoKey ( dataKey ) ) {
@@ -565,7 +565,7 @@ function isMixedBackendCryptoKey (dataKey: any): dataKey is MixedBackendCryptoKe
565
565
return isCryptoKey ( zeroByteCryptoKey ) && isCryptoKey ( nonZeroByteCryptoKey )
566
566
}
567
567
568
- export function keyUsageForMaterial < T extends WebCryptoMaterial < T > > ( material : T ) : KeyUsage {
568
+ export function keyUsageForMaterial < T extends WebCryptoMaterial < T > > ( material : T ) : AwsEsdkJsKeyUsage {
569
569
const { suite } = material
570
570
if ( suite . kdf ) return 'deriveKey'
571
571
return subtleFunctionForMaterial ( material )
0 commit comments