From 1c8d6db3912ca040dd3efd2c711d4de19687857a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Mon, 25 Sep 2023 11:30:08 +0200 Subject: [PATCH] Forbid the separator in the sub-addr name --- CHANGELOG.md | 1 + src/views/MainView.vue | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29ea4b..4c28003 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - The style has been entirely reworked using Bootstrap instead of Bulma +- It is now impossible to include the separator in the dedicated name ## [0.3.0] - 2023-08-25 diff --git a/src/views/MainView.vue b/src/views/MainView.vue index 0717963..2b106d7 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -29,15 +29,20 @@ const generatedAddr = computed(() => { const raw_account = accounts.value.find((e) => e.id == selectedAccountId.value); if (raw_account) { const account = fromRawAccount(raw_account); - var hasher = hmac.create(sha256, account.key); - hasher.update(account.localPart); - hasher.update(account.separator); - hasher.update(subAddrName.value); - const mac = hasher.digest(); - const offset = mac[mac.length - 1] & 0xf; - const reduced_mac = mac.slice(offset, offset + 5); - const code = base32Encode(reduced_mac, 'RFC4648', { padding: false }).toLowerCase(); - return `${account.localPart}${account.separator}${subAddrName.value}${account.separator}${code}@${account.domain}`; + if (subAddrName.value.indexOf(account.separator) != -1) { + subAddrName.value = subAddrName.value.replaceAll(account.separator, ''); + } + if (subAddrName.value) { + var hasher = hmac.create(sha256, account.key); + hasher.update(account.localPart); + hasher.update(account.separator); + hasher.update(subAddrName.value); + const mac = hasher.digest(); + const offset = mac[mac.length - 1] & 0xf; + const reduced_mac = mac.slice(offset, offset + 5); + const code = base32Encode(reduced_mac, 'RFC4648', { padding: false }).toLowerCase(); + return `${account.localPart}${account.separator}${subAddrName.value}${account.separator}${code}@${account.domain}`; + } } } return '';