quadqr-js 1.2.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -125,6 +125,25 @@ export function generateRaw256Key() {
125
125
  return key;
126
126
  }
127
127
 
128
+ /**
129
+ * Return the fixed number of bytes added around a plaintext by Secure Payload
130
+ * v1 for the supplied mode. AES-GCM ciphertext length matches plaintext length,
131
+ * so this lets higher layers reason about final QuadQR version boundaries
132
+ * before encryption runs.
133
+ */
134
+ export function estimateSecureEnvelopeOverhead(security = {}) {
135
+ const mode = normalizeMode(security.mode);
136
+ let keyIdLength = 0;
137
+ if (mode === SECURITY_MODES.PASSWORD) {
138
+ if (security.keyId != null && security.keyId !== false) keyIdLength = encodeKeyId(security.keyId).bytes.length;
139
+ return FIXED_HEADER_BYTES + SALT_BYTES + NONCE_BYTES + TAG_BYTES + keyIdLength;
140
+ }
141
+ if (security.keyId === false) keyIdLength = 0;
142
+ else if (security.keyId != null) keyIdLength = encodeKeyId(security.keyId).bytes.length;
143
+ else keyIdLength = AUTO_KEY_ID_BYTES;
144
+ return FIXED_HEADER_BYTES + NONCE_BYTES + TAG_BYTES + keyIdLength;
145
+ }
146
+
128
147
  function randomBytes(length) {
129
148
  const bytes = new Uint8Array(length);
130
149
  cryptoApi().getRandomValues(bytes);