mirror of
https://github.com/bitwarden/jslib
synced 2026-01-06 18:43:14 +00:00
* send work * New method to update the last used index (#184) Instead of updating it every time you call getNext(), it will be updated in a separate call, to avoid updating the index when the cipher did not auto-fill correctly (e.g wrong frame) Fixes #1392 * added OnlyOrg to PolicyType enum (#183) * [Require SSO] Add policy type enumeration (#186) * Added SsoAuthentication policy type * Updated policy type name // added comments for clarification of what each type controls * [SSO] New user provision flow (#173) * Initial commit of new user sso flow * Adjusted stateSplit conditional per review * Add logging to lowdb storage service (#188) * Fix lint errors/warnings (#187) * remove password api * access id * makeSendKey Co-authored-by: Josep Marí <xusoo@users.noreply.github.com> Co-authored-by: Addison Beck <abeck@bitwarden.com> Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com>
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import { CipherString } from './cipherString';
|
|
|
|
import { View } from '../view/view';
|
|
|
|
import { SymmetricCryptoKey } from './symmetricCryptoKey';
|
|
|
|
export default class Domain {
|
|
protected buildDomainModel<D extends Domain>(domain: D, dataObj: any, map: any,
|
|
alreadyEncrypted: boolean, notEncList: any[] = []) {
|
|
for (const prop in map) {
|
|
if (!map.hasOwnProperty(prop)) {
|
|
continue;
|
|
}
|
|
|
|
const objProp = dataObj[(map[prop] || prop)];
|
|
if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) {
|
|
(domain as any)[prop] = objProp ? objProp : null;
|
|
} else {
|
|
(domain as any)[prop] = objProp ? new CipherString(objProp) : null;
|
|
}
|
|
}
|
|
}
|
|
protected buildDataModel<D extends Domain>(domain: D, dataObj: any, map: any, notCipherStringList: any[] = []) {
|
|
for (const prop in map) {
|
|
if (!map.hasOwnProperty(prop)) {
|
|
continue;
|
|
}
|
|
|
|
const objProp = (domain as any)[(map[prop] || prop)];
|
|
if (notCipherStringList.indexOf(prop) > -1) {
|
|
(dataObj as any)[prop] = objProp != null ? objProp : null;
|
|
} else {
|
|
(dataObj as any)[prop] = objProp != null ? (objProp as CipherString).encryptedString : null;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected async decryptObj<T extends View>(viewModel: T, map: any, orgId: string,
|
|
key: SymmetricCryptoKey = null): Promise<T> {
|
|
const promises = [];
|
|
const self: any = this;
|
|
|
|
for (const prop in map) {
|
|
if (!map.hasOwnProperty(prop)) {
|
|
continue;
|
|
}
|
|
|
|
// tslint:disable-next-line
|
|
(function (theProp) {
|
|
const p = Promise.resolve().then(() => {
|
|
const mapProp = map[theProp] || theProp;
|
|
if (self[mapProp]) {
|
|
return self[mapProp].decrypt(orgId, key);
|
|
}
|
|
return null;
|
|
}).then((val: any) => {
|
|
(viewModel as any)[theProp] = val;
|
|
});
|
|
promises.push(p);
|
|
})(prop);
|
|
}
|
|
|
|
await Promise.all(promises);
|
|
return viewModel;
|
|
}
|
|
}
|