Skip to content

Commit 82a967d

Browse files
committed
refactor: remove need of retyping encryption factory function arguments
1 parent 1953061 commit 82a967d

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/drivers/aes_256_cbc.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { MessageBuilder, type Secret } from '@poppinss/utils'
1010
import { BaseDriver } from './base_driver.ts'
1111
import { Hmac } from '../hmac.ts'
1212
import * as errors from '../exceptions.ts'
13-
import type { AES256CBCConfig, CypherText, EncryptionDriverContract } from '../types/main.ts'
13+
import type {
14+
AES256CBCConfig,
15+
CypherText,
16+
EncryptionConfig,
17+
EncryptionDriverContract,
18+
} from '../types/main.ts'
1419
import { base64UrlDecode, base64UrlEncode } from '../base64.ts'
1520

1621
export interface AES256CBCDriverConfig {
@@ -20,9 +25,9 @@ export interface AES256CBCDriverConfig {
2025

2126
export function aes256cbc(config: AES256CBCDriverConfig) {
2227
return {
23-
driver: (key: string | Secret<string>) => new AES256CBC({ id: config.id, key }),
28+
driver: (key) => new AES256CBC({ id: config.id, key }),
2429
keys: config.keys,
25-
}
30+
} satisfies EncryptionConfig
2631
}
2732

2833
export class AES256CBC extends BaseDriver implements EncryptionDriverContract {

src/drivers/aes_256_gcm.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { MessageBuilder, type Secret } from '@poppinss/utils'
1010
import { BaseDriver } from './base_driver.ts'
1111
import * as errors from '../exceptions.ts'
1212
import { base64UrlDecode, base64UrlEncode } from '../base64.ts'
13-
import type { AES256GCMConfig, CypherText, EncryptionDriverContract } from '../types/main.ts'
13+
import type {
14+
AES256GCMConfig,
15+
CypherText,
16+
EncryptionConfig,
17+
EncryptionDriverContract,
18+
} from '../types/main.ts'
1419

1520
export interface AES256GCMDriverConfig {
1621
id: string
@@ -19,9 +24,9 @@ export interface AES256GCMDriverConfig {
1924

2025
export function aes256gcm(config: AES256GCMDriverConfig) {
2126
return {
22-
driver: (key: string | Secret<string>) => new AES256GCM({ id: config.id, key }),
27+
driver: (key) => new AES256GCM({ id: config.id, key }),
2328
keys: config.keys,
24-
}
29+
} satisfies EncryptionConfig
2530
}
2631

2732
export class AES256GCM extends BaseDriver implements EncryptionDriverContract {

src/drivers/chacha20_poly1305.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto'
99
import { MessageBuilder, type Secret } from '@poppinss/utils'
1010
import { BaseDriver } from './base_driver.ts'
1111
import * as errors from '../exceptions.ts'
12-
import type { ChaCha20Poly1305Config, CypherText, EncryptionDriverContract } from '../types/main.ts'
12+
import type {
13+
ChaCha20Poly1305Config,
14+
CypherText,
15+
EncryptionConfig,
16+
EncryptionDriverContract,
17+
} from '../types/main.ts'
1318
import { base64UrlDecode, base64UrlEncode } from '../base64.ts'
1419

1520
export interface ChaCha20Poly1305DriverConfig {
@@ -19,9 +24,9 @@ export interface ChaCha20Poly1305DriverConfig {
1924

2025
export function chacha20poly1305(config: ChaCha20Poly1305DriverConfig) {
2126
return {
22-
driver: (key: string | Secret<string>) => new ChaCha20Poly1305({ id: config.id, key }),
27+
driver: (key) => new ChaCha20Poly1305({ id: config.id, key }),
2328
keys: config.keys,
24-
}
29+
} satisfies EncryptionConfig
2530
}
2631

2732
export class ChaCha20Poly1305 extends BaseDriver implements EncryptionDriverContract {

0 commit comments

Comments
 (0)