From 7639962521e71d8f3741c13c35caf8ae3c51e893 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Tue, 23 Jan 2024 20:02:02 +0100 Subject: [PATCH] fix: optimize regexp creation --- src/fetcher/aspe.js | 3 ++- src/serviceProviders/openpgp.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/fetcher/aspe.js b/src/fetcher/aspe.js index 4775db1..7668c78 100644 --- a/src/fetcher/aspe.js +++ b/src/fetcher/aspe.js @@ -20,6 +20,8 @@ import { parseProfileJws } from '../asp.js' export const timeout = 5000 +const reURI = /^aspe:([a-zA-Z0-9.\-_]*):([a-zA-Z0-9]*)/ + /** * Execute a fetch request * @function @@ -39,7 +41,6 @@ export async function fn (data, opts) { }) const fetchPromise = new Promise((resolve, reject) => { - const reURI = /^aspe:([a-zA-Z0-9.\-_]*):([a-zA-Z0-9]*)/ const match = data.aspeUri.match(reURI) if (!data.aspeUri || !reURI.test(data.aspeUri) || !isFQDN(match[1])) { diff --git a/src/serviceProviders/openpgp.js b/src/serviceProviders/openpgp.js index 2852dc8..beddbc2 100644 --- a/src/serviceProviders/openpgp.js +++ b/src/serviceProviders/openpgp.js @@ -18,15 +18,15 @@ import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^(.*)/ +const reURIHkp = /^openpgp4fpr:(?:0x)?([a-zA-Z0-9.\-_]*)/ +const reURIWkdDirect = /^https:\/\/(.*)\/.well-known\/openpgpkey\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/ +const reURIWkdAdvanced = /^https:\/\/(openpgpkey.*)\/.well-known\/openpgpkey\/(.*)\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/ + /** * @function * @param {string} uri */ export function processURI (uri) { - const reURIHkp = /^openpgp4fpr:(?:0x)?([a-zA-Z0-9.\-_]*)/ - const reURIWkdDirect = /^https:\/\/(.*)\/.well-known\/openpgpkey\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/ - const reURIWkdAdvanced = /^https:\/\/(openpgpkey.*)\/.well-known\/openpgpkey\/(.*)\/hu\/([a-zA-Z0-9]*)(?:\?l=(.*))?/ - let reURI = null let mode = null let match = null