1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
18 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
19 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
20 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
21 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
22 | };
|
23 | var KeytarServiceImpl_1;
|
24 | Object.defineProperty(exports, "__esModule", { value: true });
|
25 | exports.KeytarServiceImpl = void 0;
|
26 | const inversify_1 = require("inversify");
|
27 | const common_1 = require("../common");
|
28 | const keytar = require("keytar");
|
29 | let KeytarServiceImpl = KeytarServiceImpl_1 = class KeytarServiceImpl {
|
30 | async setPassword(service, account, password) {
|
31 | if (common_1.isWindows && password.length > KeytarServiceImpl_1.MAX_PASSWORD_LENGTH) {
|
32 | let index = 0;
|
33 | let chunk = 0;
|
34 | let hasNextChunk = true;
|
35 | while (hasNextChunk) {
|
36 | const passwordChunk = password.substring(index, index + KeytarServiceImpl_1.PASSWORD_CHUNK_SIZE);
|
37 | index += KeytarServiceImpl_1.PASSWORD_CHUNK_SIZE;
|
38 | hasNextChunk = password.length - index > 0;
|
39 | const content = {
|
40 | content: passwordChunk,
|
41 | hasNextChunk: hasNextChunk
|
42 | };
|
43 | await keytar.setPassword(service, chunk ? `${account}-${chunk}` : account, JSON.stringify(content));
|
44 | chunk++;
|
45 | }
|
46 | }
|
47 | else {
|
48 | await keytar.setPassword(service, account, password);
|
49 | }
|
50 | }
|
51 | deletePassword(service, account) {
|
52 | return keytar.deletePassword(service, account);
|
53 | }
|
54 | async getPassword(service, account) {
|
55 | const password = await keytar.getPassword(service, account);
|
56 | if (password) {
|
57 | try {
|
58 | let { content, hasNextChunk } = JSON.parse(password);
|
59 | if (!content || !hasNextChunk) {
|
60 | return password;
|
61 | }
|
62 | let index = 1;
|
63 | while (hasNextChunk) {
|
64 | const nextChunk = await keytar.getPassword(service, `${account}-${index++}`);
|
65 | const result = JSON.parse(nextChunk);
|
66 | content += result.content;
|
67 | hasNextChunk = result.hasNextChunk;
|
68 | }
|
69 | return content;
|
70 | }
|
71 | catch (_a) {
|
72 | return password;
|
73 | }
|
74 | }
|
75 | }
|
76 | async findPassword(service) {
|
77 | const password = await keytar.findPassword(service);
|
78 | if (password) {
|
79 | return password;
|
80 | }
|
81 | }
|
82 | async findCredentials(service) {
|
83 | return keytar.findCredentials(service);
|
84 | }
|
85 | };
|
86 | KeytarServiceImpl.MAX_PASSWORD_LENGTH = 2500;
|
87 | KeytarServiceImpl.PASSWORD_CHUNK_SIZE = KeytarServiceImpl_1.MAX_PASSWORD_LENGTH - 100;
|
88 | KeytarServiceImpl = KeytarServiceImpl_1 = __decorate([
|
89 | (0, inversify_1.injectable)()
|
90 | ], KeytarServiceImpl);
|
91 | exports.KeytarServiceImpl = KeytarServiceImpl;
|
92 |
|
\ | No newline at end of file |