fix: apply the same shard-count validation to the generator

Share.vue's shard-count input had the defect Copilot flagged on Print.vue's:
no `step`, no integer check, and `totalShards` fed straight into
crypto.share() — a fractional count surfaced as an opaque secrets.js error
routed through the generic error hub, and an emptied box passed "" through.

Reuse `isValidShardCount()` and gate the generate button on it, matching the
existing `secretTooLong` pattern (disabled button plus an inline error span),
so both shard-count inputs now agree on what a shard count is.
This commit is contained in:
Kirill Pimenov 2026-07-27 16:57:41 +02:00
parent 19af5af007
commit 9f74cc3f6c

View File

@ -39,13 +39,18 @@
type="number"
min="3"
max="255"
step="1"
/>
to reconstruct
<br />
<span v-if="!shardCountValid" class="error-text">
Enter a whole number of shards between 3 and 255
</span>
</p>
<button
id="generateBtn"
class="button-card"
:disabled="secretTooLong"
:disabled="secretTooLong || !shardCountValid"
:hidden="encryptionMode"
v-on:click="toggleMode"
>
@ -91,7 +96,7 @@
<script lang="ts">
import passPhrase from "../util/passPhrase";
import crypto from "../util/crypto";
import { defaultThreshold } from "../util/shards";
import { defaultThreshold, isValidShardCount } from "../util/shards";
import ShardInfo from "../components/ShardInfo.vue";
import CanvasText from "../components/CanvasText.vue";
@ -121,6 +126,11 @@ export default Vue.extend({
secretTooLong(): boolean {
return this.secret.length > 1024;
},
// Gates generation the same way `secretTooLong` does: a fractional or empty
// count would otherwise reach crypto.share() and fail deep inside secrets.js.
shardCountValid(): boolean {
return isValidShardCount(this.totalShards);
},
requiredShards(): number {
return defaultThreshold(this.totalShards);
},