mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
[PM-8280] email forwarders (#11563)
* forwarder lookup and generation support * localize algorithm names and descriptions in the credential generator service * add encryption support to UserStateSubject * move generic rx utilities to common * move icon button labels to generator configurations
This commit is contained in:
31
libs/common/src/tools/private-classifier.ts
Normal file
31
libs/common/src/tools/private-classifier.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { Classifier } from "@bitwarden/common/tools/state/classifier";
|
||||
|
||||
export class PrivateClassifier<Data> implements Classifier<Data, Record<string, never>, Data> {
|
||||
constructor(private keys: (keyof Jsonify<Data>)[] = undefined) {}
|
||||
|
||||
classify(value: Data): { disclosed: Jsonify<Record<string, never>>; secret: Jsonify<Data> } {
|
||||
const pickMe = JSON.parse(JSON.stringify(value));
|
||||
const keys: (keyof Jsonify<Data>)[] = this.keys ?? (Object.keys(pickMe) as any);
|
||||
|
||||
const picked: Partial<Jsonify<Data>> = {};
|
||||
for (const key of keys) {
|
||||
picked[key] = pickMe[key];
|
||||
}
|
||||
const secret = picked as Jsonify<Data>;
|
||||
|
||||
return { disclosed: null, secret };
|
||||
}
|
||||
|
||||
declassify(_disclosed: Jsonify<Record<keyof Data, never>>, secret: Jsonify<Data>) {
|
||||
const result: Partial<Jsonify<Data>> = {};
|
||||
const keys: (keyof Jsonify<Data>)[] = this.keys ?? (Object.keys(secret) as any);
|
||||
|
||||
for (const key of keys) {
|
||||
result[key] = secret[key];
|
||||
}
|
||||
|
||||
return result as Jsonify<Data>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user