Skip to content

Commit

Permalink
Add util.compareConstant
Browse files Browse the repository at this point in the history
  • Loading branch information
CMEONE committed Jun 13, 2021
1 parent 695d13e commit 79b5a05
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 78 deletions.
61 changes: 22 additions & 39 deletions node/tenvoy.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ function tEnvoy(openpgpRef = openpgp, naclRef = nacl, sha256Ref = sha256) {
}
return copy;
}

this.util.compareConstant = (inputted, original) => {
if(inputted == null) {
throw "tEnvoy Fatal Error: argument inputted of method util.compareConstant is required and does not have a default value.";
}
if(original == null) {
throw "tEnvoy Fatal Error: argument original of method util.compareConstant is required and does not have a default value.";
}
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}

this.util.mixedToUint8Array = (mixed, includeType = false, length = null) => {
if(mixed == null) {
Expand Down Expand Up @@ -1433,18 +1452,6 @@ function tEnvoyPGPKey(keyArmored, type = "aes", password = null, passwordProtect
}
}
_assertPassword = (methodName, password) => {
let compareConstant = (inputted, original) => {
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}
if(_password == null) {
return {
proceed: true
Expand All @@ -1464,7 +1471,7 @@ function tEnvoyPGPKey(keyArmored, type = "aes", password = null, passwordProtect
proceed: false,
error: "tEnvoyPGPKey Fatal Error: Key is password-protected for method " + methodName + ", and no password was specified."
};
} else if(!compareConstant(password, _password)) {
} else if(!_tEnvoy.util.compareConstant(password, _password)) {
return {
proceed: false,
error: "tEnvoyPGPKey Fatal Error: Key is password-protected for method " + methodName + ", and an incorrect password was specified."
Expand Down Expand Up @@ -1860,18 +1867,6 @@ function tEnvoyNaClKey(key, type = "secret", password = null, passwordProtected
}
}
_assertPassword = (methodName, password = null) => {
let compareConstant = (inputted, original) => {
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}
if(_password == null) {
return {
proceed: true
Expand All @@ -1889,7 +1884,7 @@ function tEnvoyNaClKey(key, type = "secret", password = null, passwordProtected
proceed: false,
error: "tEnvoyNaClKey Fatal Error: Key is password-protected for method " + methodName + ", and no password was specified"
};
} else if(!compareConstant(password, _password)) {
} else if(!_tEnvoy.util.compareConstant(password, _password)) {
return {
proceed: false,
error: "tEnvoyNaClKey Fatal Error: Key is password-protected for method " + methodName + ", and an incorrect password was specified."
Expand Down Expand Up @@ -2172,18 +2167,6 @@ function tEnvoyNaClSigningKey(key, type = "secret", password = null, passwordPro
}
}
_assertPassword = (methodName, password = null) => {
let compareConstant = (inputted, original) => {
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}
if(_password == null) {
return {
proceed: true
Expand All @@ -2201,7 +2184,7 @@ function tEnvoyNaClSigningKey(key, type = "secret", password = null, passwordPro
proceed: false,
error: "tEnvoyNaClSigningKey Fatal Error: Key is password-protected for method " + methodName + ", and no password was specified."
};
} else if(!compareConstant(password, _password)) {
} else if(!_tEnvoy.util.compareConstant(password, _password)) {
return {
proceed: false,
error: "tEnvoyNaClSigningKey Fatal Error: Key is password-protected for method " + methodName + ", and an incorrect password was specified."
Expand Down
61 changes: 22 additions & 39 deletions tenvoy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46166,6 +46166,25 @@ function tEnvoy(openpgpRef = openpgp, naclRef = nacl, sha256Ref = sha256) {
}
return copy;
}

this.util.compareConstant = (inputted, original) => {
if(inputted == null) {
throw "tEnvoy Fatal Error: argument inputted of method util.compareConstant is required and does not have a default value.";
}
if(original == null) {
throw "tEnvoy Fatal Error: argument original of method util.compareConstant is required and does not have a default value.";
}
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}

this.util.mixedToUint8Array = (mixed, includeType = false, length = null) => {
if(mixed == null) {
Expand Down Expand Up @@ -47450,18 +47469,6 @@ function tEnvoyPGPKey(keyArmored, type = "aes", password = null, passwordProtect
}
}
_assertPassword = (methodName, password) => {
let compareConstant = (inputted, original) => {
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}
if(_password == null) {
return {
proceed: true
Expand All @@ -47481,7 +47488,7 @@ function tEnvoyPGPKey(keyArmored, type = "aes", password = null, passwordProtect
proceed: false,
error: "tEnvoyPGPKey Fatal Error: Key is password-protected for method " + methodName + ", and no password was specified."
};
} else if(!compareConstant(password, _password)) {
} else if(!_tEnvoy.util.compareConstant(password, _password)) {
return {
proceed: false,
error: "tEnvoyPGPKey Fatal Error: Key is password-protected for method " + methodName + ", and an incorrect password was specified."
Expand Down Expand Up @@ -47877,18 +47884,6 @@ function tEnvoyNaClKey(key, type = "secret", password = null, passwordProtected
}
}
_assertPassword = (methodName, password = null) => {
let compareConstant = (inputted, original) => {
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}
if(_password == null) {
return {
proceed: true
Expand All @@ -47906,7 +47901,7 @@ function tEnvoyNaClKey(key, type = "secret", password = null, passwordProtected
proceed: false,
error: "tEnvoyNaClKey Fatal Error: Key is password-protected for method " + methodName + ", and no password was specified"
};
} else if(!compareConstant(password, _password)) {
} else if(!_tEnvoy.util.compareConstant(password, _password)) {
return {
proceed: false,
error: "tEnvoyNaClKey Fatal Error: Key is password-protected for method " + methodName + ", and an incorrect password was specified."
Expand Down Expand Up @@ -48189,18 +48184,6 @@ function tEnvoyNaClSigningKey(key, type = "secret", password = null, passwordPro
}
}
_assertPassword = (methodName, password = null) => {
let compareConstant = (inputted, original) => {
let result = true;
for(let i = 0; i < inputted.length; i++) {
if(i >= original.length || inputted[i] != original[i]) {
result = false;
}
}
if(inputted.length != original.length) {
result = false;
}
return result;
}
if(_password == null) {
return {
proceed: true
Expand All @@ -48218,7 +48201,7 @@ function tEnvoyNaClSigningKey(key, type = "secret", password = null, passwordPro
proceed: false,
error: "tEnvoyNaClSigningKey Fatal Error: Key is password-protected for method " + methodName + ", and no password was specified."
};
} else if(!compareConstant(password, _password)) {
} else if(!_tEnvoy.util.compareConstant(password, _password)) {
return {
proceed: false,
error: "tEnvoyNaClSigningKey Fatal Error: Key is password-protected for method " + methodName + ", and an incorrect password was specified."
Expand Down

0 comments on commit 79b5a05

Please sign in to comment.