Skip to content

Commit

Permalink
Update Crypto/CryptoUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
sadortun committed Oct 4, 2021
1 parent 6100540 commit 35a3b29
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Crypto/index.ts → src/CryptoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface DerivedKey {
PBKDF2: JsonWebKey;
}

export class Crypto {
export default class Crypto {
static isEncrypted(value: { [key: string]: unknown }, strict = true): boolean {
if (typeof value !== 'object' || value === undefined || value === null) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CacheableQuery } from './parse/CacheableQuery';
import Query, * as QueryUtils from './parse/Query';
import { SecureObject } from './parse/SecureObject';
import { User } from './parse/User';
import * as CryptoUtils from './crypto';
import Crypto , * as CryptoUtils from './CryptoUtils';

export {
ArrayUtils,
Expand All @@ -34,6 +34,7 @@ export {
RegexUtils,
StringUtils,
CryptoUtils,
Crypto,
// This will be moved in a separate 'parse-utils' repo later
BaseObject,
CacheableQuery,
Expand Down
2 changes: 1 addition & 1 deletion src/parse/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class Query<T extends Parse.Object> extends Parse.Query<T> {
return this;
}

public includeAll(): this {
public includeAll(): this {
return super.includeAll() as this;
}

Expand Down
14 changes: 7 additions & 7 deletions src/parse/SecureObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Crypto, DerivedKey, EncryptedValue } from '../Crypto';
import { Crypto, CryptoUtils } from '../index';
import { BaseObject } from './BaseObject';

const perf = {
Expand All @@ -8,7 +8,7 @@ const perf = {

export abstract class SecureObject extends BaseObject {
private static isServer = false;
private static sessionDerivedKey: DerivedKey;
private static sessionDerivedKey: CryptoUtils.DerivedKey;
private readonly secureFields: string[] = [];

private _decryptedReadCache: { [key: string]: unknown } = {};
Expand All @@ -24,7 +24,7 @@ export abstract class SecureObject extends BaseObject {
this.secureFields = secureFields;
}

static setSessionDerivedKey(derived: DerivedKey): void {
static setSessionDerivedKey(derived: CryptoUtils.DerivedKey): void {
SecureObject.sessionDerivedKey = derived;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ export abstract class SecureObject extends BaseObject {
return clone;
}

public static async decryptField<T>(val: EncryptedValue): Promise<T | undefined> {
public static async decryptField<T>(val: CryptoUtils.EncryptedValue): Promise<T | undefined> {
const start = window.performance.now();

const decrypted = await Crypto.decrypt<T>(SecureObject.sessionDerivedKey, val);
Expand All @@ -76,11 +76,11 @@ export abstract class SecureObject extends BaseObject {
return decrypted;
}

public static async encryptField<T>(val: T): Promise<EncryptedValue> {
if (Crypto.isEncrypted(val as unknown as EncryptedValue)) {
public static async encryptField<T>(val: T): Promise<CryptoUtils.EncryptedValue> {
if (Crypto.isEncrypted(val as unknown as CryptoUtils.EncryptedValue)) {
throw 'Already encrypted';

return val as unknown as EncryptedValue;
return val as unknown as CryptoUtils.EncryptedValue;
}

if (val instanceof Parse.Object) {
Expand Down

0 comments on commit 35a3b29

Please sign in to comment.