mirror of
https://github.com/coder/code-server.git
synced 2026-05-06 12:31:58 +02:00
Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export interface ICommonEncryptionService {
|
||||
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
encrypt(value: string): Promise<string>;
|
||||
|
||||
decrypt(value: string): Promise<string>;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ICommonEncryptionService } from 'vs/platform/encryption/common/encryptionService';
|
||||
|
||||
export const IEncryptionMainService = createDecorator<IEncryptionMainService>('encryptionMainService');
|
||||
|
||||
export interface IEncryptionMainService extends ICommonEncryptionService { }
|
||||
|
||||
export interface Encryption {
|
||||
encrypt(salt: string, value: string): Promise<string>;
|
||||
decrypt(salt: string, value: string): Promise<string>;
|
||||
}
|
||||
export class EncryptionMainService implements ICommonEncryptionService {
|
||||
declare readonly _serviceBrand: undefined;
|
||||
constructor(
|
||||
private machineId: string) {
|
||||
|
||||
}
|
||||
|
||||
private encryption(): Promise<Encryption> {
|
||||
return new Promise((resolve, reject) => require(['vscode-encrypt'], resolve, reject));
|
||||
}
|
||||
|
||||
async encrypt(value: string): Promise<string> {
|
||||
try {
|
||||
const encryption = await this.encryption();
|
||||
return encryption.encrypt(this.machineId, value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
async decrypt(value: string): Promise<string> {
|
||||
try {
|
||||
const encryption = await this.encryption();
|
||||
return encryption.decrypt(this.machineId, value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user