mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Replace strings with enums
This commit is contained in:
parent
09677602cc
commit
a47c88ca36
2 changed files with 10 additions and 8 deletions
|
@ -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)
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue