Skip to content

[server] use Buffer.from properly #13291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestEncryptionEngineImpl {

@test basicSymmetry() {
const plaintext = "12345678901234567890";
const key = new Buffer(this.testkey, "base64");
const key = Buffer.from(this.testkey, "base64");

const cut = new EncryptionEngineImpl();
const encryptedData = cut.encrypt(plaintext, key);
Expand Down
10 changes: 7 additions & 3 deletions components/gitpod-protocol/src/encryption/encryption-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class EncryptionEngineImpl {
encrypt(data: string, key: Buffer): EncryptedData {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(this.algorithm, key, iv);
const encrypted = cipher.update(new Buffer(data, "utf8"));
const encrypted = cipher.update(Buffer.from(data, "utf8"));
const finalEncrypted = Buffer.concat([encrypted, cipher.final()]);
return {
data: finalEncrypted.toString(this.enc),
Expand All @@ -51,8 +51,12 @@ export class EncryptionEngineImpl {
}

decrypt(encryptedData: EncryptedData, key: Buffer): string {
const decipher = crypto.createDecipheriv(this.algorithm, key, new Buffer(encryptedData.keyParams.iv, this.enc));
let decrypted = decipher.update(new Buffer(encryptedData.data, this.enc));
const decipher = crypto.createDecipheriv(
this.algorithm,
key,
Buffer.from(encryptedData.keyParams.iv, this.enc),
);
let decrypted = decipher.update(Buffer.from(encryptedData.data, this.enc));
const finalDecrypted = Buffer.concat([decrypted, decipher.final()]);
return finalDecrypted.toString("utf8");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class KeyProviderImpl implements KeyProvider {
name: config.name,
version: config.version,
},
material: new Buffer(config.material, "base64"),
material: Buffer.from(config.material, "base64"),
};
}
}
4 changes: 2 additions & 2 deletions components/ws-manager-bridge/src/messagebus-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class MessageBusIntegration extends AbstractMessageBusIntegration {
await super.publish(
MessageBusHelperImpl.WORKSPACE_EXCHANGE_LOCAL,
topic,
new Buffer(JSON.stringify(instance)),
Buffer.from(JSON.stringify(instance)),
{
trace: { span },
},
Expand All @@ -63,7 +63,7 @@ export class MessageBusIntegration extends AbstractMessageBusIntegration {
}

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