@@ -317,7 +317,7 @@ export type RenameCallback = MoveCallback;
317317export type RotateEncryptionKeyOptions = string | Buffer | EncryptionKeyOptions ;
318318
319319export interface EncryptionKeyOptions {
320- encryptionKey ?: string | Buffer ;
320+ encryptionKey ?: string | Buffer | null ;
321321 kmsKeyName ?: string ;
322322 preconditionOpts ?: PreconditionOptions ;
323323}
@@ -366,7 +366,7 @@ const COMPRESSIBLE_MIME_REGEX = new RegExp(
366366
367367export interface FileOptions {
368368 crc32cGenerator ?: CRC32CValidatorGenerator ;
369- encryptionKey ?: string | Buffer ;
369+ encryptionKey ?: string | Buffer | null ;
370370 generation ?: number | string ;
371371 restoreToken ?: string ;
372372 kmsKeyName ?: string ;
@@ -425,7 +425,7 @@ export type DownloadCallback = (
425425
426426export interface DownloadOptions extends CreateReadStreamOptions {
427427 destination ?: string ;
428- encryptionKey ?: string | Buffer ;
428+ encryptionKey ?: string | Buffer | null ;
429429}
430430
431431interface CopyQuery {
@@ -600,7 +600,7 @@ class File extends ServiceObject<File, FileMetadata> {
600600 restoreToken ?: string ;
601601 parent ! : Bucket ;
602602
603- private encryptionKey ?: string | Buffer ;
603+ private encryptionKey ?: string | Buffer | null ;
604604 private encryptionKeyBase64 ?: string ;
605605 private encryptionKeyHash ?: string ;
606606 private encryptionKeyInterceptor ?: Interceptor ;
@@ -1102,7 +1102,7 @@ class File extends ServiceObject<File, FileMetadata> {
11021102
11031103 this . name = name ;
11041104
1105- if ( options . encryptionKey ) {
1105+ if ( options . encryptionKey !== undefined ) {
11061106 this . setEncryptionKey ( options . encryptionKey ) ;
11071107 }
11081108
@@ -1379,14 +1379,26 @@ class File extends ServiceObject<File, FileMetadata> {
13791379
13801380 const headers : { [ index : string ] : string | undefined } = { } ;
13811381
1382- if ( this . encryptionKey !== undefined ) {
1382+ if ( this . encryptionKey !== undefined && this . encryptionKey !== null ) {
13831383 headers [ 'x-goog-copy-source-encryption-algorithm' ] = 'AES256' ;
13841384 headers [ 'x-goog-copy-source-encryption-key' ] = this . encryptionKeyBase64 ;
13851385 headers [ 'x-goog-copy-source-encryption-key-sha256' ] =
13861386 this . encryptionKeyHash ;
13871387 }
13881388
1389- if ( newFile . encryptionKey !== undefined ) {
1389+ let copiedKey = false ;
1390+ if (
1391+ this . encryptionKey !== undefined &&
1392+ this . encryptionKey !== null &&
1393+ newFile . encryptionKey === undefined
1394+ ) {
1395+ newFile . encryptionKey = this . encryptionKey ;
1396+ newFile . encryptionKeyBase64 = this . encryptionKeyBase64 ;
1397+ newFile . encryptionKeyHash = this . encryptionKeyHash ;
1398+ copiedKey = true ;
1399+ }
1400+
1401+ if ( newFile . encryptionKey !== undefined && ! copiedKey ) {
13901402 this . setEncryptionKey ( newFile . encryptionKey ! ) ;
13911403 } else if ( options . destinationKmsKeyName !== undefined ) {
13921404 query . destinationKmsKeyName = options . destinationKmsKeyName ;
@@ -1864,7 +1876,7 @@ class File extends ServiceObject<File, FileMetadata> {
18641876 ) ,
18651877 file : this . name ,
18661878 generation : this . generation ,
1867- key : this . encryptionKey ,
1879+ key : this . encryptionKey === null ? undefined : this . encryptionKey ,
18681880 kmsKeyName : this . kmsKeyName ,
18691881 metadata : options . metadata ,
18701882 offset : options . offset ,
@@ -2392,7 +2404,7 @@ class File extends ServiceObject<File, FileMetadata> {
23922404 const destination = options . destination ;
23932405 delete options . destination ;
23942406
2395- if ( options . encryptionKey ) {
2407+ if ( options . encryptionKey !== undefined ) {
23962408 this . setEncryptionKey ( options . encryptionKey ) ;
23972409 delete options . encryptionKey ;
23982410 }
@@ -2482,8 +2494,23 @@ class File extends ServiceObject<File, FileMetadata> {
24822494 * region_tag:storage_download_encrypted_file
24832495 * Example of downloading an encrypted file:
24842496 */
2485- setEncryptionKey ( encryptionKey : string | Buffer ) {
2497+ setEncryptionKey ( encryptionKey : string | Buffer | null ) {
2498+ if ( this . encryptionKeyInterceptor ) {
2499+ const index = this . interceptors . indexOf ( this . encryptionKeyInterceptor ) ;
2500+ if ( index > - 1 ) {
2501+ this . interceptors . splice ( index , 1 ) ;
2502+ }
2503+ this . encryptionKeyInterceptor = undefined ;
2504+ }
2505+
24862506 this . encryptionKey = encryptionKey ;
2507+
2508+ if ( encryptionKey === null || encryptionKey === undefined ) {
2509+ this . encryptionKeyBase64 = undefined ;
2510+ this . encryptionKeyHash = undefined ;
2511+ return this ;
2512+ }
2513+
24872514 this . encryptionKeyBase64 = Buffer . from ( encryptionKey as string ) . toString (
24882515 'base64' ,
24892516 ) ;
@@ -2504,7 +2531,7 @@ class File extends ServiceObject<File, FileMetadata> {
25042531 } ,
25052532 } ;
25062533
2507- this . interceptors . push ( this . encryptionKeyInterceptor ! ) ;
2534+ this . interceptors . push ( this . encryptionKeyInterceptor ) ;
25082535
25092536 return this ;
25102537 }
@@ -4462,7 +4489,7 @@ class File extends ServiceObject<File, FileMetadata> {
44624489 file : this . name ,
44634490 generation : this . generation ,
44644491 isPartialUpload : options . isPartialUpload ,
4465- key : this . encryptionKey ,
4492+ key : this . encryptionKey === null ? undefined : this . encryptionKey ,
44664493 kmsKeyName : this . kmsKeyName ,
44674494 metadata : options . metadata ,
44684495 offset : options . offset ,
0 commit comments