• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8389227144

22 Mar 2024 10:56AM UTC coverage: 26.087% (-53.9%) from 79.937%
8389227144

push

github

web-flow
refactor: move zod schema to openapi (#487)

2100 of 3363 branches covered (62.44%)

282 of 757 new or added lines in 74 files covered. (37.25%)

14879 existing lines in 182 files now uncovered.

25574 of 98035 relevant lines covered (26.09%)

5.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.14
/apps/nestjs-backend/src/utils/encryptor.ts
1
import * as crypto from 'crypto';
1✔
2

1✔
3
interface IEncryptionOptions {
1✔
4
  algorithm: string;
1✔
5
  key: string | Buffer;
1✔
6
  iv: string | Buffer;
1✔
7
  encoding?: BufferEncoding;
1✔
8
}
1✔
9

1✔
10
export class Encryptor<T> {
1✔
11
  private readonly options: Required<IEncryptionOptions>;
167✔
12

167✔
13
  constructor(options: IEncryptionOptions) {
167✔
14
    this.options = {
167✔
15
      ...options,
167✔
16
      encoding: options.encoding ?? 'hex',
167✔
17
    };
167✔
18
  }
167✔
19

167✔
20
  encrypt(data: T): string {
167✔
UNCOV
21
    try {
×
UNCOV
22
      const { algorithm, key, iv, encoding } = this.options;
×
UNCOV
23
      const cipher = crypto.createCipheriv(algorithm, key, iv);
×
UNCOV
24
      const encrypted = cipher.update(JSON.stringify(data), 'utf-8', encoding);
×
UNCOV
25
      return encrypted + cipher.final(encoding);
×
UNCOV
26
    } catch (error) {
×
27
      throw new Error('Encryption failed');
×
28
    }
×
UNCOV
29
  }
×
30

167✔
31
  decrypt(encryptedData: string): T {
167✔
UNCOV
32
    try {
×
UNCOV
33
      const { algorithm, key, iv, encoding } = this.options;
×
UNCOV
34
      const decipher = crypto.createDecipheriv(algorithm, key, iv);
×
UNCOV
35
      const decrypted = decipher.update(encryptedData, encoding, 'utf-8');
×
UNCOV
36
      return JSON.parse(decrypted + decipher.final('utf-8')) as T;
×
UNCOV
37
    } catch (error) {
×
38
      throw new Error('Decryption failed');
×
39
    }
×
UNCOV
40
  }
×
41
}
167✔
42

1✔
43
export const getEncryptor = <T>(options: IEncryptionOptions) => new Encryptor<T>(options);
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc