Home Reference Source

lib6/encryption/encrypted-value.js

/**
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.com]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import Integer, { int } from '../integer';
/**
 * @private
 */
export class EncryptedValue {
    constructor(cipherOutput, profileName, profileType, profileVersion, typeName, typeProtocolMajor, typeProtocolMinor, metadata) {
        this.cipherOutput = cipherOutput;
        this.profileName = profileName;
        this.profileType = profileType;
        this.profileVersion = profileVersion instanceof BigInt ? Integer.fromString(profileVersion.toString()) : int(profileVersion);
        this.typeName = typeName;
        this.typeProtocolMajor = typeProtocolMajor instanceof BigInt ? Integer.fromString(typeProtocolMajor.toString()) : int(typeProtocolMajor);
        this.typeProtocolMinor = typeProtocolMinor instanceof BigInt ? Integer.fromString(typeProtocolMinor.toString()) : int(typeProtocolMinor);
        this.metadata = {};
        Object.keys(metadata).sort().forEach((val) => { this.metadata[val] = metadata[val]; });
    }
    /**
     * Tests if the specified object is a EncryptedValue.
     * @access private
     * @param {*} obj Object
     * @returns {boolean}
     * @expose
     */
    static isEncryptedValue(obj) {
        return (obj === null || obj === void 0 ? void 0 : obj.__isEncryptedValue__) === true;
    }
}
/**
 * An indicator used to reliably determine if an object is a EncryptedValue or not.
 * @type {boolean}
 * @const
 * @expose
 * @private
 */
EncryptedValue.__isEncryptedValue__ = true;
Object.defineProperty(EncryptedValue.prototype, '__isEncryptedValue__', {
    value: true,
    enumerable: false,
    configurable: false
});
/**
 * Check if a variable is of EncryptedValue type.
 * @private
 * @param {Mixed} value - The variable to check.
 * @return {Boolean} - Is it of the EncryptedValue type?
 */
export const isEnc = EncryptedValue.isEncryptedValue;