dotencr
Version:
Encrypt and decrypt individual lines inside a .env file. Supports multiple encryption keys. Keys and dotenv files can be read text file or read from the environment.
93 lines • 3.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var LeftSideTokenIds;
(function (LeftSideTokenIds) {
LeftSideTokenIds["cryptoKeyName"] = "cryptoKeyName";
LeftSideTokenIds["pattern"] = "pattern";
LeftSideTokenIds["variableName"] = "variableName";
})(LeftSideTokenIds = exports.LeftSideTokenIds || (exports.LeftSideTokenIds = {}));
var RightSideTokenIds;
(function (RightSideTokenIds) {
RightSideTokenIds["iv"] = "iv";
RightSideTokenIds["cipher"] = "cipher";
RightSideTokenIds["tag"] = "tag";
})(RightSideTokenIds = exports.RightSideTokenIds || (exports.RightSideTokenIds = {}));
class DotenvVariable {
constructor(leftSide, rightSide, separatorLeft, separatorRight) {
this.leftSideTokens = new Map();
this.rightSideTokens = new Map();
this.errors = [];
/**
* Is the dotenv variable valid?
* The variable is not considered valid if the key name is a reserved word.
*/
this.isValid = true;
this.leftSide = leftSide;
this.rightSide = rightSide;
this.separatorLeft = separatorLeft;
this.separatorRight = separatorRight;
}
leftCryptoKeyName() {
const s = this.leftSideTokens.get(LeftSideTokenIds.cryptoKeyName);
if (!s) {
throw "leftCryptoKeyName: Value not found";
}
return s;
}
leftPattern() {
const s = this.leftSideTokens.get(LeftSideTokenIds.pattern);
if (!s) {
throw "leftPattern: Value not found";
}
return s;
}
leftVariableName() {
const s = this.leftSideTokens.get(LeftSideTokenIds.variableName);
if (!s) {
throw "leftVariableName: Value not found";
}
return s;
}
rightIV() {
const s = this.rightSideTokens.get(RightSideTokenIds.iv);
if (!s) {
throw "rightIV: Value not found";
}
return s;
}
rightCipheredText() {
const s = this.rightSideTokens.get(RightSideTokenIds.cipher);
if (!s) {
throw "rightCipheredText: Value not found";
}
return s;
}
rightSignature() {
const s = this.rightSideTokens.get(RightSideTokenIds.tag);
if (!s) {
throw "rightSignature: Value not found";
}
return s;
}
static isEqualCryptoKeyNameSeparatoVariableName(x, y) {
return (x.leftCryptoKeyName() === y.leftCryptoKeyName() &&
x.separatorLeft === y.separatorLeft &&
x.leftVariableName() === y.leftVariableName());
}
}
exports.DotenvVariable = DotenvVariable;
exports.isEqualMatchingDotenvVariable = (a, b) => {
return (a.plainText.leftSide === b.plainText.leftSide && a.ciphered.leftSide === b.ciphered.leftSide);
};
// export const isEqualMatchingDotenvVariableLeftRight = (
// a: MatchingDotenvVariable,
// b: MatchingDotenvVariable
// ): boolean => {
// return (
// a.plainText.leftSide === b.plainText.leftSide &&
// a.ciphered.leftSide === b.ciphered.leftSide &&
// a.plainText.rightSide === b.plainText.rightSide &&
// _.isEqual(a.cipheredDecryptionResult?.result, b.cipheredDecryptionResult?.result)
// );
// };
//# sourceMappingURL=dotenv_variable.js.map