File tree 7 files changed +19
-7
lines changed
7 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 1
1
export * from './key.dto' ;
2
2
export * from './key.schema' ;
3
- export * from './key.service' ;
Original file line number Diff line number Diff line change
1
+ export * from './key-not-found.error' ;
Original file line number Diff line number Diff line change
1
+ export class KeyNotFoundError extends Error {
2
+ public static withId ( id : string ) {
3
+ return new KeyNotFoundError ( `Decrypt key for [${ id } ] does not exists` ) ;
4
+ }
5
+ }
Original file line number Diff line number Diff line change 1
1
export * from './aggregate.repository' ;
2
2
export * from './decorators/inject-repository.decorator' ;
3
3
export * from './domain' ;
4
+ export * from './errors' ;
4
5
export * from './eventstore' ;
5
6
export * from './eventstore.config' ;
6
7
export * from './eventstore.constants' ;
Original file line number Diff line number Diff line change
1
+ export * from './key.service' ;
1
2
export * from './projections.service' ;
2
3
export * from './transformer.service' ;
Original file line number Diff line number Diff line change 1
1
import { CryptoModule } from '@akanass/nestjsx-crypto' ;
2
2
import { getModelToken } from '@nestjs/mongoose' ;
3
3
import { Test } from '@nestjs/testing' ;
4
- import { KeyDto } from './key.dto' ;
5
- import { KeyDocument , KEYS } from './key.schema' ;
6
- import { KeyService } from './key.service' ;
7
- import { Event } from '../domain' ;
8
4
import { v4 as uuid } from 'uuid' ;
9
5
import { Model } from 'mongoose' ;
10
6
7
+ import { KeyDto , KeyDocument , KEYS } from '../crypto' ;
8
+ import { Event } from '../domain' ;
9
+ import { KeyService } from './key.service' ;
10
+
11
11
describe ( 'KeyService' , ( ) => {
12
12
const PAYLOAD = { foo : 'bar' } ;
13
13
const ENCRYPTED_PAYLOAD = 'z6ZatDe7V2Dvkxyvx9fzazqjc5BOWqSTpUaQzrkUeR4=' ;
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ import { Model } from 'mongoose';
9
9
import { firstValueFrom } from 'rxjs' ;
10
10
import { v4 as uuid } from 'uuid' ;
11
11
12
+ import { KeyDocument , KeyDto , KEYS } from '../crypto' ;
12
13
import { Event } from '../domain' ;
13
- import { KeyDto } from './key.dto' ;
14
- import { KeyDocument , KEYS } from './key.schema' ;
14
+ import { KeyNotFoundError } from '../errors' ;
15
15
16
16
@Injectable ( )
17
17
export class KeyService {
@@ -58,6 +58,11 @@ export class KeyService {
58
58
59
59
async decryptPayload ( id : string , encryptedPayload : string ) : Promise < string > {
60
60
const key = await this . find ( id ) ;
61
+
62
+ if ( ! key ) {
63
+ throw KeyNotFoundError . withId ( id ) ;
64
+ }
65
+
61
66
const source$ = await this . aesService
62
67
. createKey ( key . secret , key . salt )
63
68
. pipe ( decryptWithAesKey ( Buffer . from ( encryptedPayload , 'base64' ) ) ) ;
You can’t perform that action at this time.
0 commit comments