Skip to content

Commit

Permalink
Add optional cryptoService param to TDF constructor (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielRicaud authored Jul 12, 2023
1 parent 1462bb4 commit ca6b664
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/tdf3/src/tdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ type Chunk = {
_resolve?: (value: unknown) => void;
};

type TDFConfiguration = {
cryptoService?: CryptoService;
};

export class TDF extends EventEmitter {
policy?: Policy;
mimeType?: string;
Expand All @@ -136,11 +140,11 @@ export class TDF extends EventEmitter {
chunkMap: Map<string, Chunk>;
cryptoService: CryptoService<CryptoKeyPair>;

constructor() {
constructor(configuration?: TDFConfiguration) {
super();

this.attributeSet = new AttributeSet();
this.cryptoService = defaultCryptoService;
this.cryptoService = configuration?.cryptoService ?? defaultCryptoService;
this.publicKey = '';
this.privateKey = '';
this.integrityAlgorithm = 'HS256';
Expand All @@ -149,8 +153,8 @@ export class TDF extends EventEmitter {
}

// factory
static create() {
return new TDF();
static create(configuration?: TDFConfiguration) {
return new TDF(configuration);
}

createCipher(type: string) {
Expand Down

0 comments on commit ca6b664

Please sign in to comment.