Replace strings with enums

This commit is contained in:
Yarmo Mackenbach 2021-04-15 10:21:18 +02:00
parent 09677602cc
commit a47c88ca36
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 10 additions and 8 deletions

View file

@ -61,16 +61,16 @@ const runVerificationJson = (
if (checkPath.length == 0) { if (checkPath.length == 0) {
switch (checkRelation) { switch (checkRelation) {
default: default:
case 'contains': case E.ClaimRelation.CONTAINS:
re = new RegExp(checkClaim, 'gi') re = new RegExp(checkClaim, 'gi')
res.isVerified = re.test(proofData.replace(/\r?\n|\r|\\/g, '')) res.isVerified = re.test(proofData.replace(/\r?\n|\r|\\/g, ''))
break break
case 'equals': case E.ClaimRelation.EQUALS:
res.isVerified = res.isVerified =
proofData.replace(/\r?\n|\r|\\/g, '').toLowerCase() == proofData.replace(/\r?\n|\r|\\/g, '').toLowerCase() ==
checkClaim.toLowerCase() checkClaim.toLowerCase()
break break
case 'oneOf': case E.ClaimRelation.ONEOF:
re = new RegExp(checkClaim, 'gi') re = new RegExp(checkClaim, 'gi')
res.isVerified = re.test(proofData.join('|')) res.isVerified = re.test(proofData.join('|'))
break break
@ -102,7 +102,7 @@ const runVerification = (proofData, spData) => {
} }
switch (spData.proof.format) { switch (spData.proof.format) {
case 'json': case E.ProofFormat.JSON:
res = runVerificationJson( res = runVerificationJson(
res, res,
proofData, proofData,
@ -111,7 +111,7 @@ const runVerification = (proofData, spData) => {
spData.claim.relation spData.claim.relation
) )
break break
case 'text': case E.ProofFormat.TEXT:
re = new RegExp( re = new RegExp(
utils utils
.generateClaim(spData.claim.fingerprint, spData.claim.format) .generateClaim(spData.claim.fingerprint, spData.claim.format)

View file

@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const E = require('./enums')
const generateProxyURL = (type, urlElements, opts) => { const generateProxyURL = (type, urlElements, opts) => {
if (!opts || !opts.doipProxyHostname) { if (!opts || !opts.doipProxyHostname) {
return null return null
@ -37,13 +39,13 @@ const generateProxyURL = (type, urlElements, opts) => {
const generateClaim = (fingerprint, format) => { const generateClaim = (fingerprint, format) => {
switch (format) { switch (format) {
case 'uri': case E.ClaimFormat.URI:
return `openpgp4fpr:${fingerprint}` return `openpgp4fpr:${fingerprint}`
break break
case 'message': case E.ClaimFormat.MESSAGE:
return `[Verifying my OpenPGP key: openpgp4fpr:${fingerprint}]` return `[Verifying my OpenPGP key: openpgp4fpr:${fingerprint}]`
break break
case 'fingerprint': case E.ClaimFormat.FINGERPRINT:
return fingerprint return fingerprint
break break
default: default: