diff --git a/types/google-cloud__kms/google-cloud__kms-tests.ts b/types/google-cloud__kms/google-cloud__kms-tests.ts index 96ab80c7c1..d05e881ccc 100644 --- a/types/google-cloud__kms/google-cloud__kms-tests.ts +++ b/types/google-cloud__kms/google-cloud__kms-tests.ts @@ -67,20 +67,20 @@ async function exampleListCryptoKeys() { async function exampleEncrypt() { const formattedName = kmsClient.cryptoKeyPath('[PROJECT_ID]', '[LOCATION]', '[KEYRING_ID]', '[KEY_ID]'); - const unencryptedText = new Buffer('Hello World'); + const unencryptedText = Buffer.from('Hello World'); - const [ asyncEncryptResult ] = await kmsClient.encrypt({ name: formattedName, plaintext: unencryptedText.toString('base64') }); + const [ asyncEncryptResult ] = await kmsClient.encrypt({ name: formattedName, plaintext: unencryptedText }); if (asyncEncryptResult != null) { console.log(`Encrypted: ${asyncEncryptResult.ciphertext.toString('base64')}`); } - kmsClient.encrypt({ name: formattedName, plaintext: unencryptedText.toString('base64') }, (err, [ callbackEncryptResult ]) => { + kmsClient.encrypt({ name: formattedName, plaintext: unencryptedText }, (err, [ callbackEncryptResult ]) => { if (callbackEncryptResult != null) { console.log(`Encrypted: ${callbackEncryptResult.ciphertext.toString('base64')}`); } }); - kmsClient.encrypt({ name: formattedName, plaintext: unencryptedText.toString('base64') }, { timeout: 1000 }, (err, [ callbackWithOptionsEncryptResult ]) => { + kmsClient.encrypt({ name: formattedName, plaintext: unencryptedText }, { timeout: 1000 }, (err, [ callbackWithOptionsEncryptResult ]) => { if (callbackWithOptionsEncryptResult != null) { console.log(`Encrypted: ${callbackWithOptionsEncryptResult.ciphertext.toString('base64')}`); } @@ -96,22 +96,22 @@ async function exampleDecrypt() { // const buffers = await file.download(); // const buffer = buffers[ 0 ]; - const buffer = new Buffer('[ENCRYPTED_SOURCE_BUFFER]'); + const buffer = Buffer.from('[ENCRYPTED_SOURCE_BUFFER]'); const formattedName = kmsClient.cryptoKeyPath('[PROJECT_ID]', '[LOCATION]', '[KEYRING_ID]', '[KEY_ID]'); - const [ asyncDecryptResult ] = await kmsClient.decrypt({name: formattedName, ciphertext: buffer.toString('base64') }); + const [ asyncDecryptResult ] = await kmsClient.decrypt({name: formattedName, ciphertext: buffer }); if (asyncDecryptResult != null) { - console.log(`Decrypted: ${asyncDecryptResult.plaintext}`); + console.log(`Decrypted: ${asyncDecryptResult.plaintext.toString('utf8')}`); } - kmsClient.decrypt({ name: formattedName, ciphertext: buffer.toString('base64') }, (err, [ callbackDecryptResult ]) => { + kmsClient.decrypt({ name: formattedName, ciphertext: buffer }, (err, [ callbackDecryptResult ]) => { if (callbackDecryptResult != null) { - console.log(`Decrypted: ${callbackDecryptResult.plaintext}`); + console.log(`Decrypted: ${callbackDecryptResult.plaintext.toString('utf8')}`); } }); - kmsClient.decrypt({ name: formattedName, ciphertext: buffer.toString('base64') }, (err, [ callbackWithOptionsDecryptResult ]) => { + kmsClient.decrypt({ name: formattedName, ciphertext: buffer }, (err, [ callbackWithOptionsDecryptResult ]) => { if (callbackWithOptionsDecryptResult != null) { - console.log(`Decrypted: ${callbackWithOptionsDecryptResult.plaintext}`); + console.log(`Decrypted: ${callbackWithOptionsDecryptResult.plaintext.toString('utf8')}`); } }); } diff --git a/types/google-cloud__kms/index.d.ts b/types/google-cloud__kms/index.d.ts index 237c7115a0..eb34ffca09 100644 --- a/types/google-cloud__kms/index.d.ts +++ b/types/google-cloud__kms/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for @google-cloud/kms 0.2 +// Type definitions for @google-cloud/kms 1.3 // Project: https://github.com/googleapis/nodejs-kms // Definitions by: Ben Talbot +// Caian Ertl // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -178,7 +179,7 @@ export namespace v1 { interface EncryptRequest { name: string; - plaintext: string; + plaintext: Buffer; additionalAuthenticatedData?: string; } interface EncryptResponse { @@ -189,7 +190,7 @@ export namespace v1 { interface DecryptRequest { name: string; - ciphertext: string; + ciphertext: Buffer; additionalAuthenticatedData?: string; } interface DecryptResponse {