Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tdf3 + Nano = ❤️ #47

Merged
merged 12 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,801 changes: 8,358 additions & 2,443 deletions cli/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"devDependencies": {
"@esm-bundle/chai": "4.3.4-fix.0",
"@types/mocha": "9.1.0",
"@types/node": "^17.0.30",
"@types/readable-stream": "^2.3.13",
"@types/sinon": "^10.0.11",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.18.0",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import yargs from 'yargs';
import { readFile, stat, writeFile } from 'fs/promises';
import { hideBin } from 'yargs/helpers';
import { AuthProviders, NanoTDFClient, version } from '@opentdf/client';
import { AuthProviders, NanoTDFClient, version } from '@opentdf/client/nano-node-esm';

import { CLIError, Level, log } from './logger.js';

Expand Down
67 changes: 67 additions & 0 deletions lib/fasade/FileClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Client as ClientTdf3 } from '../tdf3/src/client';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is spelled facade. But this is great! 👍

import { DecryptParamsBuilder, EncryptParamsBuilder } from '../tdf3/src/client/builders';
import { TDFCiphertextStream } from '../tdf3/src/client/tdf-cipher-text-stream';
import { PlaintextStream } from '../tdf3/src/client/tdf-stream';

interface FileClientConfig {
clientId: string,
organizationName: string,
oidcOrigin: string,
kasEndpoint: string,
clientSecret?: string,
oidcRefreshToken?: string,
}

export class FileClient {
private client: ClientTdf3;

constructor({ clientId, clientSecret, oidcRefreshToken, organizationName, oidcOrigin, kasEndpoint }: FileClientConfig) {
this.client = new ClientTdf3({
clientId,
organizationName,
clientSecret,
oidcRefreshToken,
kasEndpoint,
virtruOIDCEndpoint: oidcOrigin,
});
}

private static setSource (source: ReadableStream | TDFCiphertextStream | Buffer | String | ArrayBuffer, params: EncryptParamsBuilder | DecryptParamsBuilder) {
// @ts-ignore
if(source.pipe !== undefined) {
// @ts-ignore
params.setStreamSource(source);
}
if(Buffer && Buffer.isBuffer(source)) {
params.setBufferSource(source);
}
if(typeof source === 'string') {
// there is not point to used tdf3.js withStringSource, after merging we have nanoTdf for that
params.setFileSource(source);
}
if(source instanceof ArrayBuffer) {
params.setArrayBufferSource(source)
}
return params.build();
}

async encrypt(source: ReadableStream | Buffer | String | ArrayBuffer = '', users: string[] = [], params?: any ): Promise<TDFCiphertextStream> {
const encryptParams = new EncryptParamsBuilder().withOffline().withUsersWithAccess(users);

if (params) {
return await this.client.encrypt(params);
}
// @ts-ignore
return await this.client.encrypt(FileClient.setSource(source, encryptParams));
}

async decrypt(source: ReadableStream | Buffer | String | ArrayBuffer = '', params?: any): Promise<PlaintextStream> {
const decryptParams = new DecryptParamsBuilder();

if (params) {
return await this.client.decrypt(params);
}
// @ts-ignore
return await this.client.decrypt(FileClient.setSource(source, decryptParams));
}
}
8 changes: 8 additions & 0 deletions lib/lic-checker-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# renamed from license-checker-config.yml because GH gets confused and thinks this is the license file
blacklisted-licenses:
- gpl

whitelisted-modules:
- [email protected]
- [email protected]
- [email protected]
Loading