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) {
switch (checkRelation) {
default:
case 'contains':
case E.ClaimRelation.CONTAINS:
re = new RegExp(checkClaim, 'gi')
res.isVerified = re.test(proofData.replace(/\r?\n|\r|\\/g, ''))
break
case 'equals':
case E.ClaimRelation.EQUALS:
res.isVerified =
proofData.replace(/\r?\n|\r|\\/g, '').toLowerCase() ==
checkClaim.toLowerCase()
break
case 'oneOf':
case E.ClaimRelation.ONEOF:
re = new RegExp(checkClaim, 'gi')
res.isVerified = re.test(proofData.join('|'))
break
@ -102,7 +102,7 @@ const runVerification = (proofData, spData) => {
}
switch (spData.proof.format) {
case 'json':
case E.ProofFormat.JSON:
res = runVerificationJson(
res,
proofData,
@ -111,7 +111,7 @@ const runVerification = (proofData, spData) => {
spData.claim.relation
)
break
case 'text':
case E.ProofFormat.TEXT:
re = new RegExp(
utils
.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
limitations under the License.
*/
const E = require('./enums')
const generateProxyURL = (type, urlElements, opts) => {
if (!opts || !opts.doipProxyHostname) {
return null
@ -37,13 +39,13 @@ const generateProxyURL = (type, urlElements, opts) => {
const generateClaim = (fingerprint, format) => {
switch (format) {
case 'uri':
case E.ClaimFormat.URI:
return `openpgp4fpr:${fingerprint}`
break
case 'message':
case E.ClaimFormat.MESSAGE:
return `[Verifying my OpenPGP key: openpgp4fpr:${fingerprint}]`
break
case 'fingerprint':
case E.ClaimFormat.FINGERPRINT:
return fingerprint
break
default: