Skip to content

Commit 0eab1e9

Browse files
AlexTugarevroboquat
authored andcommitted
[server] use Buffer.from properly
Trying to get rid of deprecation log entries.
1 parent 3530437 commit 0eab1e9

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

components/gitpod-protocol/src/encryption/encryption-engine.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestEncryptionEngineImpl {
2424

2525
@test basicSymmetry() {
2626
const plaintext = "12345678901234567890";
27-
const key = new Buffer(this.testkey, "base64");
27+
const key = Buffer.from(this.testkey, "base64");
2828

2929
const cut = new EncryptionEngineImpl();
3030
const encryptedData = cut.encrypt(plaintext, key);

components/gitpod-protocol/src/encryption/encryption-engine.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class EncryptionEngineImpl {
4040
encrypt(data: string, key: Buffer): EncryptedData {
4141
const iv = crypto.randomBytes(16);
4242
const cipher = crypto.createCipheriv(this.algorithm, key, iv);
43-
const encrypted = cipher.update(new Buffer(data, "utf8"));
43+
const encrypted = cipher.update(Buffer.from(data, "utf8"));
4444
const finalEncrypted = Buffer.concat([encrypted, cipher.final()]);
4545
return {
4646
data: finalEncrypted.toString(this.enc),
@@ -51,8 +51,12 @@ export class EncryptionEngineImpl {
5151
}
5252

5353
decrypt(encryptedData: EncryptedData, key: Buffer): string {
54-
const decipher = crypto.createDecipheriv(this.algorithm, key, new Buffer(encryptedData.keyParams.iv, this.enc));
55-
let decrypted = decipher.update(new Buffer(encryptedData.data, this.enc));
54+
const decipher = crypto.createDecipheriv(
55+
this.algorithm,
56+
key,
57+
Buffer.from(encryptedData.keyParams.iv, this.enc),
58+
);
59+
let decrypted = decipher.update(Buffer.from(encryptedData.data, this.enc));
5660
const finalDecrypted = Buffer.concat([decrypted, decipher.final()]);
5761
return finalDecrypted.toString("utf8");
5862
}

components/gitpod-protocol/src/encryption/key-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class KeyProviderImpl implements KeyProvider {
7171
name: config.name,
7272
version: config.version,
7373
},
74-
material: new Buffer(config.material, "base64"),
74+
material: Buffer.from(config.material, "base64"),
7575
};
7676
}
7777
}

components/ws-manager-bridge/src/messagebus-integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class MessageBusIntegration extends AbstractMessageBusIntegration {
4444
await super.publish(
4545
MessageBusHelperImpl.WORKSPACE_EXCHANGE_LOCAL,
4646
topic,
47-
new Buffer(JSON.stringify(instance)),
47+
Buffer.from(JSON.stringify(instance)),
4848
{
4949
trace: { span },
5050
},
@@ -63,7 +63,7 @@ export class MessageBusIntegration extends AbstractMessageBusIntegration {
6363
}
6464

6565
const topic = this.messageBusHelper.getWsTopicForPublishing(userId, workspaceId, "headless-log");
66-
const msg = new Buffer(JSON.stringify(evt));
66+
const msg = Buffer.from(JSON.stringify(evt));
6767
await this.messageBusHelper.assertWorkspaceExchange(this.channel);
6868
await super.publish(MessageBusHelperImpl.WORKSPACE_EXCHANGE_LOCAL, topic, msg, {
6969
trace: ctx,

0 commit comments

Comments
 (0)