Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Remove unused Rust vault codec bindings

Leendert de Borste9a57f2ef09a
diff --git a/apps/browser-extension/tests/helpers/manifest-v2-api.ts b/apps/browser-extension/tests/helpers/manifest-v2-api.ts
index 0ae11996a..60b8a26ff 100644
--- a/apps/browser-extension/tests/helpers/manifest-v2-api.ts
+++ b/apps/browser-extension/tests/helpers/manifest-v2-api.ts
@@ -10,9 +10,10 @@
import { createHash } from 'crypto';
import { SrpAuthService } from '@aliasvault/client/auth/SrpAuthService';
-import { getSyncableTableNames, openKeyChainWithUnlockKey, vaultCodecCanonicalizeFromSqlite, vaultCodecGenerateManifestSalt, vaultCodecPackPayload, vaultCodecUnpackPayload } from '@aliasvault/client/rust/RustCore';
+import { openKeyChainWithUnlockKey } from '@aliasvault/client/rust/RustCore';
-import { bucketAad, manifestAad, symmetricDecryptBytes, symmetricEncryptBytes } from './vault-crypto';
+import { manifestAad, symmetricDecryptBytes, symmetricEncryptBytes } from './vault-crypto';
+import { packPayload, unpackPayload } from './vault-payload';
/** One manifest entry in the v2 GET snapshot. */
export type SnapshotManifest = {
@@ -59,15 +60,6 @@ type ManifestWrite = {
blobReferences: Array<{ hash: string; category: string }>;
};
-/** One data bucket element of a POST /v2/Vault write. */
-type BucketWrite = {
- manifestId: string;
- category: string;
- blob: string;
- ciphertextHash: string;
- currentRevision: number;
-};
-
/** The result of a POST /v2/Vault write. */
type VaultWriteResult = {
status: 'ok' | 'outdated';
@@ -148,7 +140,7 @@ export async function resolveVaultEncryptionKey(apiBaseUrl: string, token: strin
}
/**
- * Decrypts and unpacks a manifest blob into its JSON object (content hash verified by the codec).
+ * Decrypts and unpacks a manifest blob into its JSON object.
*
* @param manifestId - The manifest the blob belongs to
* @param blobBase64 - The encrypted manifest blob from the snapshot
@@ -157,12 +149,11 @@ export async function resolveVaultEncryptionKey(apiBaseUrl: string, token: strin
*/
export async function openManifest(manifestId: string, blobBase64: string, encryptionKey: Uint8Array): Promise<DecryptedManifest> {
const packedBytes = await symmetricDecryptBytes(blobBase64, encryptionKey, manifestAad(manifestId));
- return JSON.parse(await vaultCodecUnpackPayload(packedBytes)) as DecryptedManifest;
+ return unpackPayload<DecryptedManifest>(packedBytes);
}
/**
- * Packs (envelope + canonical content hash + gzip via the Rust codec), encrypts, and uploads a
- * manifest as a new revision, exactly like the extension's full push does.
+ * Packs (envelope + canonical content hash + gzip), encrypts, and uploads a manifest as a new revision.
*
* @param apiBaseUrl - The base URL of the API
* @param token - Bearer token
@@ -185,7 +176,7 @@ export async function pushManifest(
encryptionKey: Uint8Array
): Promise<number> {
const write = await buildManifestWrite(manifestId, manifest, currentRevision, blobReferences, encryptionKey);
- const result = await postVaultWrite(apiBaseUrl, token, username, [write], []);
+ const result = await postVaultWrite(apiBaseUrl, token, username, [write]);
const written = (result.manifestRevisions ?? []).find((r) => r.manifestId === manifestId);
if (!written) {
@@ -207,47 +198,7 @@ export async function pushManifest(
export async function pushManifestBlob(apiBaseUrl: string, token: string, username: string, manifestId: string, blob: string, currentRevision: number): Promise<void> {
const manifestCiphertextHash = createHash('sha256').update(Buffer.from(blob, 'base64')).digest('hex');
const write = { manifestId, manifestBlob: blob, manifestCiphertextHash, currentRevision, credentialsCount: 0, blobReferences: [] };
- await postVaultWrite(apiBaseUrl, token, username, [write], []);
-}
-
-/**
- * Writes the first manifest-v1 revision for a newly registered account.
- *
- * @param apiBaseUrl - The base URL of the API
- * @param token - Bearer token
- * @param username - The vault owner's username
- * @param encryptionKey - The account's VEK, which the vault content is encrypted with
- * @returns The id of the personal manifest that was written
- */
-export async function pushInitialVault(apiBaseUrl: string, token: string, username: string, encryptionKey: Uint8Array): Promise<string> {
- const snapshot = await getVaultSnapshot(apiBaseUrl, token);
- const manifestId = snapshot.personalManifestId;
- if (!manifestId) {
- throw new Error('Freshly registered account has no personal manifest to write the initial vault into.');
- }
-
- /*
- * A brand-new vault is every syncable table, all empty. Taking the list from the shared table registry keeps
- * this in step with the schema: canonicalize refuses a manifest that carries no tables at all.
- */
- const tables = (await getSyncableTableNames()).map((name) => ({ name, records: [] }));
- const canonicalized = await vaultCodecCanonicalizeFromSqlite({
- tables,
- canonicalizedAt: new Date().toISOString(),
- manifests: [{ manifestId, manifestSalt: await vaultCodecGenerateManifestSalt() }],
- });
-
- const manifest = canonicalized.manifests[0].manifest as DecryptedManifest;
- const manifestWrite = await buildManifestWrite(manifestId, manifest, 0, [], encryptionKey);
-
- const bucketWrites: BucketWrite[] = [];
- for (const bucket of canonicalized.dataBuckets) {
- const { blob, ciphertextHash } = await packEncrypt(JSON.stringify(bucket), encryptionKey, bucketAad(bucket.manifestId, bucket.category));
- bucketWrites.push({ manifestId: bucket.manifestId, category: bucket.category, blob, ciphertextHash, currentRevision: 0 });
- }
-
- await postVaultWrite(apiBaseUrl, token, username, [manifestWrite], bucketWrites);
- return manifestId;
+ await postVaultWrite(apiBaseUrl, token, username, [write]);
}
/**
@@ -275,20 +226,6 @@ export async function pollUntil<T>(predicate: () => Promise<T | undefined | fals
throw new Error(`pollUntil timed out after ${timeoutMs}ms${lastError ? `; last error: ${lastError instanceof Error ? lastError.message : String(lastError)}` : ''}`);
}
-/**
- * Packs a payload through the Rust codec and encrypts it.
- *
- * @param payloadJson - The payload to pack
- * @param encryptionKey - The key the vault content is encrypted with
- * @param aad - The associated data the ciphertext is bound to
- * @returns The encrypted blob and the ciphertext hash the server verifies it against
- */
-async function packEncrypt(payloadJson: string, encryptionKey: Uint8Array, aad: Uint8Array): Promise<{ blob: string; ciphertextHash: string }> {
- const packedBytes = await vaultCodecPackPayload(payloadJson);
- const blob = await symmetricEncryptBytes(packedBytes, encryptionKey, aad);
- return { blob, ciphertextHash: createHash('sha256').update(Buffer.from(blob, 'base64')).digest('hex') };
-}
-
/**
* Builds one manifest element of a vault write.
*
@@ -306,11 +243,11 @@ async function buildManifestWrite(
blobReferences: Array<{ hash: string; category: string }>,
encryptionKey: Uint8Array
): Promise<ManifestWrite> {
- const { blob, ciphertextHash } = await packEncrypt(JSON.stringify(manifest), encryptionKey, manifestAad(manifestId));
+ const blob = await symmetricEncryptBytes(packPayload(manifest), encryptionKey, manifestAad(manifestId));
return {
manifestId,
manifestBlob: blob,
- manifestCiphertextHash: ciphertextHash,
+ manifestCiphertextHash: createHash('sha256').update(Buffer.from(blob, 'base64')).digest('hex'),
currentRevision,
credentialsCount: (manifest.tables.Items ?? []).length,
blobReferences,
@@ -324,15 +261,13 @@ async function buildManifestWrite(
* @param token - Bearer token
* @param username - The vault owner's username
* @param manifests - The manifests this write targets, each addressed by id exactly as a real client does
- * @param buckets - The data buckets this write targets
* @returns The write result
*/
async function postVaultWrite(
apiBaseUrl: string,
token: string,
username: string,
- manifests: ManifestWrite[],
- buckets: BucketWrite[]
+ manifests: ManifestWrite[]
): Promise<VaultWriteResult> {
// The body is a 4-byte big-endian header length, the JSON header (offset and size in place of each base64 ciphertext), then the ciphertexts.
const ciphertexts: Buffer[] = [];
@@ -346,7 +281,7 @@ async function postVaultWrite(
const header = Buffer.from(JSON.stringify({
username: SrpAuthService.normalizeUsername(username),
manifests: manifests.map(({ manifestBlob, ...rest }) => ({ ...rest, ...place(manifestBlob) })),
- buckets: buckets.map(({ blob, ...rest }) => ({ ...rest, ...place(blob) })),
+ buckets: [],
emailRouting: null,
}));
const headerLength = Buffer.alloc(4);
diff --git a/apps/browser-extension/tests/helpers/test-api.ts b/apps/browser-extension/tests/helpers/test-api.ts
index f93980bd7..eab99534a 100644
--- a/apps/browser-extension/tests/helpers/test-api.ts
+++ b/apps/browser-extension/tests/helpers/test-api.ts
@@ -13,8 +13,6 @@ import { SrpLoginService } from '@aliasvault/client/auth/SrpLoginService';
import { base64ToBytes } from '@aliasvault/client/utilities/Base64';
import * as OTPAuth from 'otpauth';
-import { pushInitialVault } from './manifest-v2-api';
-
import './client-platform';
import type { TokenModel } from '@aliasvault/models/webapi';
@@ -54,7 +52,7 @@ export function generateTestPassword(): string {
}
/**
- * Registers a new test user via the API and writes the first revision of their vault.
+ * Registers a new test user via the API. The client's first login writes the first revision of their vault.
*
* @param apiBaseUrl - The base URL of the API (e.g., 'http://localhost:5100')
* @param username - The username for the new account
@@ -69,9 +67,7 @@ export async function registerTestUser(
): Promise<{ tokenModel: TokenModel; encryptionKey: Uint8Array }> {
const baseUrl = WebApiService.versionedBaseUrl(apiBaseUrl);
const auth = new SrpLoginService({ rawFetch: (endpoint, options) => fetch(`${baseUrl}${endpoint}`, options) });
- const { token, keys, unlockKey } = await auth.register(username, password);
-
- await pushInitialVault(apiBaseUrl, token.token, username, base64ToBytes(keys.vaultEncryptionKey));
+ const { token, unlockKey } = await auth.register(username, password);
return { tokenModel: token, encryptionKey: base64ToBytes(unlockKey) };
}
diff --git a/apps/browser-extension/tests/helpers/vault-crypto.ts b/apps/browser-extension/tests/helpers/vault-crypto.ts
index a2cbd3566..7429de54d 100644
--- a/apps/browser-extension/tests/helpers/vault-crypto.ts
+++ b/apps/browser-extension/tests/helpers/vault-crypto.ts
@@ -17,17 +17,6 @@ export function manifestAad(manifestId: string): Uint8Array {
return new TextEncoder().encode(`aliasvault/v1/manifest/${manifestId.toLowerCase()}`);
}
-/**
- * Associated data of a data bucket payload under its manifest's VEK.
- *
- * @param manifestId - The manifest the bucket belongs to
- * @param category - The bucket category
- * @returns The AAD bytes
- */
-export function bucketAad(manifestId: string, category: string): Uint8Array {
- return new TextEncoder().encode(`aliasvault/v1/bucket/${manifestId.toLowerCase()}/${category}`);
-}
-
/**
* Encrypts raw bytes bound to `aad`, returning base64(IV | ciphertext | authTag).
*
diff --git a/apps/browser-extension/tests/helpers/vault-payload.ts b/apps/browser-extension/tests/helpers/vault-payload.ts
new file mode 100644
index 000000000..b8c6bd76d
--- /dev/null
+++ b/apps/browser-extension/tests/helpers/vault-payload.ts
@@ -0,0 +1,48 @@
+/**
+ * The manifest-v1 payload envelope for tests that read or write vault payloads API-side, as the Rust core
+ * packs it (`core/rust/src/vault_codec/mod.rs`): gzip of `{ schemaVersion, contentHash, payload }`.
+ */
+
+import { createHash } from 'crypto';
+import { gunzipSync, gzipSync } from 'zlib';
+
+/** The payload format version the Rust core writes (`SCHEMA_VERSION`). */
+const SCHEMA_VERSION = 1;
+
+/**
+ * Wraps a payload in its envelope and gzips it.
+ *
+ * @param payload - The manifest or data bucket object
+ * @returns The packed bytes, ready to encrypt
+ */
+export function packPayload(payload: unknown): Uint8Array {
+ const contentHash = createHash('sha256').update(canonicalJson(payload)).digest('hex');
+ return gzipSync(JSON.stringify({ schemaVersion: SCHEMA_VERSION, contentHash, payload }));
+}
+
+/**
+ * Gunzips packed bytes and returns the payload of their envelope.
+ *
+ * @param packed - The decrypted packed bytes
+ * @returns The payload object
+ */
+export function unpackPayload<T>(packed: Uint8Array): T {
+ return (JSON.parse(gunzipSync(packed).toString('utf8')) as { payload: T }).payload;
+}
+
+/**
+ * The canonical JSON the content hash is taken over: object keys sorted recursively, arrays kept in order.
+ *
+ * @param value - The value to render
+ * @returns The canonical JSON text
+ */
+function canonicalJson(value: unknown): string {
+ if (Array.isArray(value)) {
+ return `[${value.map(canonicalJson).join(',')}]`;
+ }
+ if (value !== null && typeof value === 'object') {
+ const record = value as Record<string, unknown>;
+ return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(',')}}`;
+ }
+ return JSON.stringify(value);
+}
diff --git a/apps/browser-extension/tests/helpers/vault-tamper.ts b/apps/browser-extension/tests/helpers/vault-tamper.ts
index 49ebbb724..3386ac5a0 100644
--- a/apps/browser-extension/tests/helpers/vault-tamper.ts
+++ b/apps/browser-extension/tests/helpers/vault-tamper.ts
@@ -5,9 +5,7 @@
import { randomBytes } from 'crypto';
-import { getSyncableTableNames, vaultCodecCanonicalizeFromSqlite, vaultCodecGenerateManifestSalt } from '@aliasvault/client/rust/RustCore';
-
-import { getVaultSnapshot, pushManifest, pushManifestBlob, requirePersonalManifest, resolveVaultEncryptionKey, type DecryptedManifest } from './manifest-v2-api';
+import { getVaultSnapshot, pushManifest, pushManifestBlob, resolveVaultEncryptionKey, type SnapshotManifest } from './manifest-v2-api';
import type { TestUser } from './test-api';
@@ -16,7 +14,7 @@ import type { TestUser } from './test-api';
*/
export async function writeUndecryptableManifest(apiUrl: string, user: TestUser): Promise<void> {
const token = user.token!.token;
- const { manifestId, revision } = requirePersonalManifest(await getVaultSnapshot(apiUrl, token));
+ const { manifestId, revision } = await getPersonalManifest(apiUrl, token);
await pushManifestBlob(apiUrl, token, user.username, manifestId, randomBytes(256).toString('base64'), revision);
}
@@ -25,15 +23,21 @@ export async function writeUndecryptableManifest(apiUrl: string, user: TestUser)
*/
export async function writeManifestWithBrokenRow(apiUrl: string, user: TestUser, table: string, row: Record<string, unknown>): Promise<void> {
const token = user.token!.token;
- const { manifestId, revision } = requirePersonalManifest(await getVaultSnapshot(apiUrl, token));
- const canonicalized = await vaultCodecCanonicalizeFromSqlite({
- tables: (await getSyncableTableNames()).map((name) => ({ name, records: [] })),
- canonicalizedAt: new Date().toISOString(),
- manifests: [{ manifestId, manifestSalt: await vaultCodecGenerateManifestSalt() }],
- });
- const manifest = canonicalized.manifests[0].manifest as DecryptedManifest;
- manifest.tables[table] = [...(manifest.tables[table] ?? []), row];
+ const { manifestId, revision } = await getPersonalManifest(apiUrl, token);
+ const manifest = { schemaVersion: 1, manifestSalt: randomBytes(32).toString('hex'), canonicalizedAt: new Date().toISOString(), manifestId, tables: { [table]: [row] } };
const vaultKey = await resolveVaultEncryptionKey(apiUrl, token, user.encryptionKey!);
await pushManifest(apiUrl, token, user.username, manifestId, manifest, revision, [], vaultKey);
}
+
+/**
+ * The account's personal manifest entry, which exists from registration on, before any client wrote to it.
+ */
+async function getPersonalManifest(apiUrl: string, token: string): Promise<SnapshotManifest> {
+ const snapshot = await getVaultSnapshot(apiUrl, token);
+ const personal = snapshot.manifests?.find((m) => m.manifestId === snapshot.personalManifestId);
+ if (!personal) {
+ throw new Error('Test account has no personal manifest to overwrite.');
+ }
+ return personal;
+}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt
index 7e6940cda..af395dc60 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt
@@ -23,7 +23,6 @@ import uniffi.aliasvault_core.generateTotpCode
import uniffi.aliasvault_core.getDicewareLanguages
import uniffi.aliasvault_core.getIdentityAgeRanges
import uniffi.aliasvault_core.getIdentityLanguages
-import uniffi.aliasvault_core.getSyncableTableNames
import uniffi.aliasvault_core.isRelatedOriginAllowed
import uniffi.aliasvault_core.isRpIdAllowedForHost
import uniffi.aliasvault_core.mobileLoginPublicKeyHash
@@ -43,12 +42,8 @@ import uniffi.aliasvault_core.srpVerifySession
import uniffi.aliasvault_core.symmetricDecrypt
import uniffi.aliasvault_core.symmetricDecryptBytes
import uniffi.aliasvault_core.symmetricEncryptBytes
-import uniffi.aliasvault_core.vaultCodecCanonicalizeFromSqlite
-import uniffi.aliasvault_core.vaultCodecGenerateManifestSalt
import uniffi.aliasvault_core.vaultCodecLogoContentHash
import uniffi.aliasvault_core.vaultCodecLogoIdFor
-import uniffi.aliasvault_core.vaultCodecPackPayload
-import uniffi.aliasvault_core.vaultCodecUnpackPayload
/**
* Routes `rustCall` invocations from React Native onto the uniffi bindings: one case per exported core
@@ -118,14 +113,8 @@ object RustCoreDispatcher {
}
"srpVerifySession" -> srpVerifySession(args.string(0), args.string(1), args.string(2), args.string(3)).toString()
- "getSyncableTableNames" -> json(getSyncableTableNames())
-
- "vaultCodecCanonicalizeFromSqlite" -> vaultCodecCanonicalizeFromSqlite(args.string(0))
- "vaultCodecGenerateManifestSalt" -> json(vaultCodecGenerateManifestSalt())
"vaultCodecLogoIdFor" -> json(vaultCodecLogoIdFor(args.string(0), args.string(1), args.string(2)))
"vaultCodecLogoContentHash" -> json(vaultCodecLogoContentHash(args.bytes(0)))
- "vaultCodecPackPayload" -> json(vaultCodecPackPayload(args.string(0)))
- "vaultCodecUnpackPayload" -> json(vaultCodecUnpackPayload(args.bytes(0)))
else -> throw IllegalArgumentException("Unknown Rust core function '$name'")
}
diff --git a/apps/mobile-app/ios/NativeVaultManager/NativeVaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/NativeVaultManager.swift
index 63e8b5b69..01df043d8 100644
--- a/apps/mobile-app/ios/NativeVaultManager/NativeVaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/NativeVaultManager.swift
@@ -1596,14 +1596,8 @@ private enum RustCoreDispatcher {
case "srpVerifySession":
return try json(try RustCoreFramework.srpVerifySession(clientPublic: try args.string(0), clientProof: try args.string(1), sessionKey: try args.string(2), serverProof: try args.string(3)))
- case "getSyncableTableNames": return try json(RustCoreFramework.getSyncableTableNames())
-
- case "vaultCodecCanonicalizeFromSqlite": return try RustCoreFramework.vaultCodecCanonicalizeFromSqlite(inputJson: try args.string(0))
- case "vaultCodecGenerateManifestSalt": return try json(RustCoreFramework.vaultCodecGenerateManifestSalt())
case "vaultCodecLogoIdFor": return try json(RustCoreFramework.vaultCodecLogoIdFor(manifestId: try args.string(0), kind: try args.string(1), source: try args.string(2)))
case "vaultCodecLogoContentHash": return try json(RustCoreFramework.vaultCodecLogoContentHash(bytes: try args.data(0)))
- case "vaultCodecPackPayload": return try json(bytes: try RustCoreFramework.vaultCodecPackPayload(payloadJson: try args.string(0)))
- case "vaultCodecUnpackPayload": return try json(try RustCoreFramework.vaultCodecUnpackPayload(plainBytes: try args.data(0)))
default: throw DispatchError.unknownFunction(name)
}
diff --git a/apps/mobile-app/platform/NativeRustCore.ts b/apps/mobile-app/platform/NativeRustCore.ts
index ed107fa32..f1e00e2b0 100644
--- a/apps/mobile-app/platform/NativeRustCore.ts
+++ b/apps/mobile-app/platform/NativeRustCore.ts
@@ -105,14 +105,8 @@ export const nativeRustCore: IRustCore = {
srpDeriveSession: (clientSecret, serverPublic, salt, identity, privateKey) => call('srpDeriveSession', clientSecret, serverPublic, salt, identity, privateKey),
srpVerifySession: (clientPublic, clientProof, sessionKey, serverProof) => call('srpVerifySession', clientPublic, clientProof, sessionKey, serverProof),
- getSyncableTableNames: () => call('getSyncableTableNames'),
-
- vaultCodecCanonicalizeFromSqlite: (input) => call('vaultCodecCanonicalizeFromSqlite', JSON.stringify(input)),
- vaultCodecGenerateManifestSalt: () => call('vaultCodecGenerateManifestSalt'),
vaultCodecLogoIdFor: (manifestId, kind, source) => call('vaultCodecLogoIdFor', manifestId, kind, source),
vaultCodecLogoContentHash: (bytes) => call('vaultCodecLogoContentHash', base64(bytes)),
- vaultCodecPackPayload: (payloadJson) => callForBytes('vaultCodecPackPayload', payloadJson),
- vaultCodecUnpackPayload: (plainBytes) => call('vaultCodecUnpackPayload', base64(plainBytes)),
createVaultSyncSession: () => notImplementedOnMobile('createVaultSyncSession', 'the vault sync engine is driven natively'),
};
diff --git a/apps/web/tests/helpers/vault-tamper.ts b/apps/web/tests/helpers/vault-tamper.ts
index eaa389c3f..c1571a851 100644
--- a/apps/web/tests/helpers/vault-tamper.ts
+++ b/apps/web/tests/helpers/vault-tamper.ts
@@ -4,11 +4,9 @@
*/
import { createHash, randomBytes, webcrypto } from 'node:crypto';
+import { gzipSync } from 'node:zlib';
import { SrpAuthService } from '@aliasvault/client/auth/SrpAuthService';
-import { getSyncableTableNames, vaultCodecCanonicalizeFromSqlite, vaultCodecGenerateManifestSalt, vaultCodecPackPayload } from '@aliasvault/client/rust/RustCore';
-
-import './client-platform';
import { getVaultSnapshotHeader, type TestUser } from './test-api';
@@ -32,18 +30,34 @@ export async function writeUndecryptableManifest(apiUrl: string, user: TestUser)
*/
export async function writeManifestWithBrokenRow(apiUrl: string, user: TestUser, table: string, row: Record<string, unknown>): Promise<void> {
const { manifestId } = await getPersonalManifest(apiUrl, user);
- const canonicalized = await vaultCodecCanonicalizeFromSqlite({
- tables: (await getSyncableTableNames()).map((name) => ({ name, records: [] })),
- canonicalizedAt: new Date().toISOString(),
- manifests: [{ manifestId, manifestSalt: await vaultCodecGenerateManifestSalt() }],
- });
- const manifest = canonicalized.manifests[0].manifest as { tables: Record<string, unknown[]> };
- manifest.tables[table] = [...(manifest.tables[table] ?? []), row];
-
- const packed = await vaultCodecPackPayload(JSON.stringify(manifest));
+ const manifest = { schemaVersion: 1, manifestSalt: randomBytes(32).toString('hex'), canonicalizedAt: new Date().toISOString(), manifestId, tables: { [table]: [row] } };
+ const packed = packPayload(manifest);
await writePersonalManifest(apiUrl, user, await encryptManifest(packed, user.vaultEncryptionKey, manifestId));
}
+/**
+ * Pack a payload as the Rust core does (`core/rust/src/vault_codec/mod.rs`): gzip of `{ schemaVersion, contentHash, payload }`,
+ * the hash taken over the payload's canonical JSON.
+ */
+function packPayload(payload: unknown): Uint8Array {
+ const contentHash = createHash('sha256').update(canonicalJson(payload)).digest('hex');
+ return gzipSync(JSON.stringify({ schemaVersion: 1, contentHash, payload }));
+}
+
+/**
+ * The canonical JSON the content hash is taken over: object keys sorted recursively, arrays kept in order.
+ */
+function canonicalJson(value: unknown): string {
+ if (Array.isArray(value)) {
+ return `[${value.map(canonicalJson).join(',')}]`;
+ }
+ if (value !== null && typeof value === 'object') {
+ const record = value as Record<string, unknown>;
+ return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(',')}}`;
+ }
+ return JSON.stringify(value);
+}
+
/**
* Encrypt a packed manifest as the Rust core does: base64 of `IV | ciphertext | tag`, bound to the manifest's
* associated data from `core/rust/src/crypto/aad.rs`.
diff --git a/core/client/src/constants/StorageKeys.ts b/core/client/src/constants/StorageKeys.ts
index e1187edef..64e5f96dc 100644
--- a/core/client/src/constants/StorageKeys.ts
+++ b/core/client/src/constants/StorageKeys.ts
@@ -76,7 +76,7 @@ export const StorageKeys = {
SERVER_MANIFEST_REVISIONS: 'local:serverManifestRevisions',
/** The client's last known revision per data bucket. */
VAULT_BUCKET_REVISIONS: 'local:vaultBucketRevisions',
- /** The personal manifest's blob-hashing salt, cached from the last pull; see `CodecManifest.manifestSalt`. */
+ /** The personal manifest's blob-hashing salt, cached from the last pull. */
VAULT_MANIFEST_SALT: 'local:vaultManifestSalt',
/**
diff --git a/core/client/src/rust/RustCore.ts b/core/client/src/rust/RustCore.ts
index 08bed10b3..f429da346 100644
--- a/core/client/src/rust/RustCore.ts
+++ b/core/client/src/rust/RustCore.ts
@@ -12,12 +12,12 @@ import { deviceLanguage } from '../platform/DeviceLanguage';
import { AutofillMatchingMode } from './RustCoreTypes';
import type { IRustCore } from './RustCoreBinding';
-import type { AccountKeyHierarchy, CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, IdentityNameInput, IdentityRequest, KeyChainOpenResult, ParsedEmail, PinFailure, ReencryptedAccountKey } from './RustCoreTypes';
+import type { AccountKeyHierarchy, FaviconTarget, IdentityNameInput, IdentityRequest, KeyChainOpenResult, ParsedEmail, PinFailure, ReencryptedAccountKey } from './RustCoreTypes';
import type { Identity } from '@aliasvault/models/identity';
import type { Item, PasswordSettings } from '@aliasvault/models/vault';
export { AutofillMatchingMode } from './RustCoreTypes';
-export type { CodecBlobEntry, CodecCanonicalized, CodecCanonicalizeInput, CodecDataBucket, CodecManifest, CodecTableData, FaviconTarget, IdentityNameInput, IdentityRequest, ParsedEmail, ParsedEmailAttachment, PinFailure } from './RustCoreTypes';
+export type { FaviconTarget, IdentityNameInput, IdentityRequest, ParsedEmail, ParsedEmailAttachment, PinFailure } from './RustCoreTypes';
/**
* The host's Rust core binding.
@@ -314,20 +314,6 @@ async function urlComparisonKey(url: string): Promise<string> {
* Vault codec (manifest-v1 storage format).
*/
-/**
- * Canonicalize normalized tables into manifest + data buckets + blob map.
- */
-export async function vaultCodecCanonicalizeFromSqlite(input: CodecCanonicalizeInput): Promise<CodecCanonicalized> {
- return rustCore().vaultCodecCanonicalizeFromSqlite(input);
-}
-
-/**
- * The vault tables that take part in sync, as declared by the shared vault table registry.
- */
-export async function getSyncableTableNames(): Promise<string[]> {
- return rustCore().getSyncableTableNames();
-}
-
/**
* The `Logos.Id` to use for the logo `(kind, source)` inside the manifest with id `manifestId`.
*
@@ -348,27 +334,6 @@ export async function vaultCodecLogoContentHash(bytes: Uint8Array): Promise<stri
return rustCore().vaultCodecLogoContentHash(bytes);
}
-/**
- * Generate a fresh 32-byte per-manifest blob-hashing salt (lowercase hex).
- */
-export async function vaultCodecGenerateManifestSalt(): Promise<string> {
- return rustCore().vaultCodecGenerateManifestSalt();
-}
-
-/**
- * Pack a payload JSON string into gzip(envelope{contentHash, payload}). The caller encrypts the result.
- */
-export async function vaultCodecPackPayload(payloadJson: string): Promise<Uint8Array> {
- return rustCore().vaultCodecPackPayload(payloadJson);
-}
-
-/**
- * Unpack a (decrypted) payload: gunzip > verify content hash > return the payload JSON string.
- */
-export async function vaultCodecUnpackPayload(plainBytes: Uint8Array): Promise<string> {
- return rustCore().vaultCodecUnpackPayload(plainBytes);
-}
-
/**
* Read all non-empty values for a field key from an item, returning them as
* a string array (single-value fields are wrapped to a 1-element array).
diff --git a/core/client/src/rust/RustCoreBinding.ts b/core/client/src/rust/RustCoreBinding.ts
index b6b54b065..ca884181b 100644
--- a/core/client/src/rust/RustCoreBinding.ts
+++ b/core/client/src/rust/RustCoreBinding.ts
@@ -1,4 +1,4 @@
-import type { AccountKeyHierarchy, AvexHeader, CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, KeyChainOpenResult, MobileLoginApproval, ParsedEmail, PinFailure, ReencryptedAccountKey, RsaKeyPair, SrpEphemeral, SrpSession } from './RustCoreTypes';
+import type { AccountKeyHierarchy, AvexHeader, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, KeyChainOpenResult, MobileLoginApproval, ParsedEmail, PinFailure, ReencryptedAccountKey, RsaKeyPair, SrpEphemeral, SrpSession } from './RustCoreTypes';
/**
* One running operation of the Rust vault sync engine.
@@ -81,14 +81,8 @@ export interface IRustCore {
srpDeriveSession(clientSecret: string, serverPublic: string, salt: string, identity: string, privateKey: string): Promise<SrpSession>;
srpVerifySession(clientPublic: string, clientProof: string, sessionKey: string, serverProof: string): Promise<boolean>;
- getSyncableTableNames(): Promise<string[]>;
-
- vaultCodecCanonicalizeFromSqlite(input: CodecCanonicalizeInput): Promise<CodecCanonicalized>;
- vaultCodecGenerateManifestSalt(): Promise<string>;
vaultCodecLogoIdFor(manifestId: string, kind: string, source: string): Promise<string>;
vaultCodecLogoContentHash(bytes: Uint8Array): Promise<string>;
- vaultCodecPackPayload(payloadJson: string): Promise<Uint8Array>;
- vaultCodecUnpackPayload(plainBytes: Uint8Array): Promise<string>;
createVaultSyncSession(requestJson: string): Promise<IVaultSyncSession>;
}
diff --git a/core/client/src/rust/RustCoreTypes.ts b/core/client/src/rust/RustCoreTypes.ts
index a680e175c..4e357742f 100644
--- a/core/client/src/rust/RustCoreTypes.ts
+++ b/core/client/src/rust/RustCoreTypes.ts
@@ -159,63 +159,3 @@ export type ReencryptedAccountKey = {
newEncryptedAccountKey: string;
};
-/*
- * Vault codec (manifest-v1 storage format).
- */
-
-/** A single table's rows (byte columns rendered as `{ __b64 }`). */
-export type CodecTableData = { name: string; records: Array<Record<string, unknown>> };
-
-/**
- * Manifest-v1 manifest.
- */
-export type CodecManifest = {
- schemaVersion: number;
- manifestSalt: string;
- canonicalizedAt: string;
- manifestId: string;
- tables: Record<string, Array<Record<string, unknown>>>;
- [key: string]: unknown;
-};
-
-/**
- * One manifest canonicalize should emit.
- */
-export type CodecManifestSpec = {
- manifestId: string;
- manifestSalt: string;
-};
-
-/**
- * A manifest-v1 data bucket, addressed by the manifest that owns it and its category.
- */
-export type CodecDataBucket = {
- schemaVersion: number;
- manifestId: string;
- category: string;
- tables: Record<string, Array<Record<string, unknown>>>;
- [key: string]: unknown;
-};
-
-/** A decoded blob entry: kind + plaintext bytes. */
-export type CodecBlobEntry = { kind: string; bytes: number[] };
-
-/** One manifest produced by canonicalize: the manifest and the blobs hashed with its own salt. */
-export type CodecCanonicalizedManifest = { manifest: CodecManifest; blobs: Record<string, CodecBlobEntry> };
-
-/**
- * Result of canonicalize: one entry per spec, in spec order, plus the vault's data buckets.
- */
-export type CodecCanonicalized = {
- manifests: CodecCanonicalizedManifest[];
- dataBuckets: CodecDataBucket[];
-};
-
-/** Input for canonicalize. */
-export type CodecCanonicalizeInput = {
- tables: CodecTableData[];
- canonicalizedAt: string;
- manifests: CodecManifestSpec[];
- /** LEGACY: for the sqlite-blob migration, the manifest that unstamped rows are stamped with. Remove once every account has migrated to manifest-v1. */
- stampUnstampedInto?: string | null;
-};
diff --git a/core/client/src/rust/WasmRustCore.ts b/core/client/src/rust/WasmRustCore.ts
index 3a0d0288b..07263328e 100644
--- a/core/client/src/rust/WasmRustCore.ts
+++ b/core/client/src/rust/WasmRustCore.ts
@@ -7,7 +7,7 @@ import initWasm, * as core from '#wasm/aliasvault_core.js';
import { yieldToPaint } from '../utilities/YieldToPaint';
import type { IRustCore, IVaultSyncSession } from './RustCoreBinding';
-import type { AccountKeyHierarchy, AvexHeader, CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, KeyChainOpenResult, MobileLoginApproval, ParsedEmail, PinFailure, ReencryptedAccountKey, RsaKeyPair, SrpEphemeral, SrpSession } from './RustCoreTypes';
+import type { AccountKeyHierarchy, AvexHeader, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, KeyChainOpenResult, MobileLoginApproval, ParsedEmail, PinFailure, ReencryptedAccountKey, RsaKeyPair, SrpEphemeral, SrpSession } from './RustCoreTypes';
/**
* Where the host gets the `.wasm` binary from: bytes, or a fetch response for streaming instantiation.
@@ -131,14 +131,8 @@ export function createWasmRustCore(loadWasm: WasmLoader): IRustCore {
srpVerifySession: (clientPublic, clientProof, sessionKey, serverProof): Promise<boolean> =>
ready(() => core.srpVerifySession(clientPublic, clientProof, sessionKey, serverProof)),
- getSyncableTableNames: (): Promise<string[]> => ready(() => core.getSyncableTableNames()),
-
- vaultCodecCanonicalizeFromSqlite: (input: CodecCanonicalizeInput): Promise<CodecCanonicalized> => ready(() => core.vaultCodecCanonicalizeFromSqlite(input) as CodecCanonicalized),
- vaultCodecGenerateManifestSalt: (): Promise<string> => ready(() => core.vaultCodecGenerateManifestSalt()),
vaultCodecLogoIdFor: (manifestId, kind, source): Promise<string> => ready(() => core.vaultCodecLogoIdFor(manifestId, kind, source)),
vaultCodecLogoContentHash: (bytes): Promise<string> => ready(() => core.vaultCodecLogoContentHash(bytes)),
- vaultCodecPackPayload: (payloadJson): Promise<Uint8Array> => ready(() => core.vaultCodecPackPayload(payloadJson)),
- vaultCodecUnpackPayload: (plainBytes): Promise<string> => ready(() => core.vaultCodecUnpackPayload(plainBytes)),
createVaultSyncSession: (requestJson): Promise<IVaultSyncSession> => ready((): IVaultSyncSession => {
const session = new core.VaultSyncSession(requestJson);
diff --git a/core/rust/src/bindings/uniffi_api.rs b/core/rust/src/bindings/uniffi_api.rs
index f58f38f2d..b26a5550d 100644
--- a/core/rust/src/bindings/uniffi_api.rs
+++ b/core/rust/src/bindings/uniffi_api.rs
@@ -5,17 +5,10 @@
use crate::crypto::argon2::Argon2Error;
use crate::crypto::{KeyChainError, SrpInputError};
use crate::crypto::srp::{SrpEphemeral, SrpError, SrpSession};
-use crate::common::error::{json_call, VaultError};
+use crate::common::error::VaultError;
use crate::sqlite_host::{MemoryDatabase, SqlResult, SqlValue};
-use crate::vault_codec::{self, CanonicalizeInput};
use crate::vault_items;
-/// Get the list of table names that take part in a vault sync.
-#[uniffi::export]
-pub fn get_syncable_table_names() -> Vec<String> {
- crate::vault_model::SYNCABLE_TABLE_NAMES.iter().map(|s| s.to_string()).collect()
-}
-
/// Filter credentials for autofill by the current URL/app and page title.
/// Input: `CredentialMatcherInput` JSON. Output: `CredentialMatcherOutput` JSON.
#[uniffi::export]
@@ -142,19 +135,6 @@ pub fn extract_email_attachment(source: Vec<u8>, index: u32, detached_body: Opti
crate::email_parser::extract_email_attachment(&source, index as usize, detached_body.as_deref())
}
-/// Canonicalize normalized tables into manifest + metadata + blob map.
-/// Input: `CanonicalizeInput` JSON. Output: `CanonicalizedVault` JSON.
-#[uniffi::export]
-pub fn vault_codec_canonicalize_from_sqlite(input_json: String) -> Result<String, VaultError> {
- json_call(&input_json, |input: CanonicalizeInput| vault_codec::canonicalize_from_sqlite(input))
-}
-
-/// Generate a fresh 32-byte per-manifest blob-hashing salt (lowercase hex).
-#[uniffi::export]
-pub fn vault_codec_generate_manifest_salt() -> String {
- crate::vault_codec::generate_manifest_salt()
-}
-
/// The sha256 (lowercase hex) of an uploaded logo's bytes: the `Source` of a `custom` logo row, and
/// what [`vault_codec_logo_id_for`] then derives the row id from.
#[uniffi::export]
@@ -169,18 +149,6 @@ pub fn vault_codec_logo_id_for(manifest_id: String, kind: String, source: String
crate::vault_codec::logo_id_for(&manifest_id, &kind, &source)
}
-/// Pack a payload JSON string into gzip(envelope{contentHash, payload}). The caller encrypts the result.
-#[uniffi::export]
-pub fn vault_codec_pack_payload(payload_json: String) -> Result<Vec<u8>, VaultError> {
- crate::vault_codec::pack_payload(&payload_json)
-}
-
-/// Unpack a (decrypted) payload: gunzip > verify content hash > return payload JSON string.
-#[uniffi::export]
-pub fn vault_codec_unpack_payload(plain_bytes: Vec<u8>) -> Result<String, VaultError> {
- crate::vault_codec::unpack_payload(&plain_bytes)
-}
-
/// Derive a 32-byte key from a password and salt (UTF-8 bytes) with Argon2id under the `EncryptionSettings` JSON (required).
#[uniffi::export]
pub fn argon2_derive_key(password: String, salt: String, encryption_settings: String) -> Result<Vec<u8>, Argon2Error> {
diff --git a/core/rust/src/bindings/wasm.rs b/core/rust/src/bindings/wasm.rs
index c622a905f..14233b91a 100644
--- a/core/rust/src/bindings/wasm.rs
+++ b/core/rust/src/bindings/wasm.rs
@@ -5,7 +5,7 @@ use wasm_bindgen::prelude::*;
use crate::credential_matcher::{filter_credentials, CredentialMatcherInput, CredentialMatcherOutput};
use crate::password_generator::{available_languages, generate_password};
-use crate::vault_codec::{self, CanonicalizeInput};
+use crate::vault_codec;
/// Initialize panic hook for better error messages.
#[wasm_bindgen(start)]
@@ -23,12 +23,6 @@ fn to_js<T: Serialize>(value: &T) -> Result<JsValue, JsValue> {
value.serialize(&serde_wasm_bindgen::Serializer::new().serialize_maps_as_objects(true).serialize_missing_as_null(true)).map_err(js_err)
}
-/// Get the list of table names that take part in a vault sync.
-#[wasm_bindgen(js_name = getSyncableTableNames)]
-pub fn get_syncable_table_names_js() -> Vec<String> {
- crate::vault_model::SYNCABLE_TABLE_NAMES.iter().map(|s| s.to_string()).collect()
-}
-
/// The sha256 (lowercase hex) of an uploaded logo's bytes: the `Source` of a `custom` logo row, and
/// what `vaultCodecLogoIdFor` then derives the row id from.
#[wasm_bindgen(js_name = vaultCodecLogoContentHash)]
@@ -43,33 +37,6 @@ pub fn vault_codec_logo_id_for_js(manifest_id: String, kind: String, source: Str
vault_codec::logo_id_for(&manifest_id, &kind, &source)
}
-/// Canonicalize normalized tables into manifest + data buckets.
-/// Input: `CanonicalizeInput`. Output: `CanonicalizedVault`.
-#[wasm_bindgen(js_name = vaultCodecCanonicalizeFromSqlite)]
-pub fn vault_codec_canonicalize_from_sqlite_js(input: JsValue) -> Result<JsValue, JsValue> {
- let input: CanonicalizeInput = serde_wasm_bindgen::from_value(input).map_err(js_err)?;
- let output = vault_codec::canonicalize_from_sqlite(input).map_err(js_err)?;
- to_js(&output)
-}
-
-/// Generate a fresh 32-byte per-manifest blob-hashing salt (lowercase hex).
-#[wasm_bindgen(js_name = vaultCodecGenerateManifestSalt)]
-pub fn vault_codec_generate_manifest_salt_js() -> String {
- vault_codec::generate_manifest_salt()
-}
-
-/// Pack a payload JSON string into gzip(envelope{contentHash, payload}). The caller encrypts the result.
-#[wasm_bindgen(js_name = vaultCodecPackPayload)]
-pub fn vault_codec_pack_payload_js(payload_json: &str) -> Result<Vec<u8>, JsValue> {
- vault_codec::pack_payload(payload_json).map_err(js_err)
-}
-
-/// Unpack a (decrypted) payload: gunzip > verify content hash > return payload JSON string.
-#[wasm_bindgen(js_name = vaultCodecUnpackPayload)]
-pub fn vault_codec_unpack_payload_js(plain_bytes: &[u8]) -> Result<String, JsValue> {
- vault_codec::unpack_payload(plain_bytes).map_err(js_err)
-}
-
/// Filter credentials for autofill. Input: `CredentialMatcherInput`. Output: `CredentialMatcherOutput`.
#[wasm_bindgen(js_name = filterCredentials)]
pub fn filter_credentials_js(input: JsValue) -> Result<JsValue, JsValue> {
diff --git a/core/rust/src/vault_codec/mod.rs b/core/rust/src/vault_codec/mod.rs
index 1da44ed52..032fee1ea 100644
--- a/core/rust/src/vault_codec/mod.rs
+++ b/core/rust/src/vault_codec/mod.rs
@@ -82,18 +82,10 @@ pub enum UnpackedPayload {
NewerFormat(u32),
}
-/// Unpack a payload: gunzip > parse envelope > verify the embedded content hash.
-/// Refuses an envelope written at a format version this build cannot read.
-pub fn unpack_payload(plain_bytes: &[u8]) -> VaultResult<String> {
- match unpack_versioned_payload(plain_bytes)? {
- UnpackedPayload::Readable(payload_json) => Ok(payload_json),
- UnpackedPayload::NewerFormat(version) => Err(VaultError::General(format!("payload has format version {}, this build supports reading up to {}", version, SCHEMA_VERSION))),
- }
-}
-
-/// [`unpack_payload`], reporting a newer format version as a value instead of an error. The version is read
-/// before the content hash, since a newer format may hash differently and must not read as corruption.
-pub fn unpack_versioned_payload(plain_bytes: &[u8]) -> VaultResult<UnpackedPayload> {
+/// Unpack a payload: gunzip > parse envelope > verify the embedded content hash. A newer format version is reported
+/// as a value instead of an error, read before the content hash, since a newer format may hash differently and must not
+/// read as corruption.
+pub fn unpack_payload(plain_bytes: &[u8]) -> VaultResult<UnpackedPayload> {
let decompressed = gunzip(plain_bytes, MAX_DECOMPRESSED_PAYLOAD_BYTES)?;
let envelope_json = std::str::from_utf8(&decompressed).map_err(|e| VaultError::General(format!("payload is not valid UTF-8: {}", e)))?;
let envelope: serde_json::Value = serde_json::from_str(envelope_json)?;
diff --git a/core/rust/src/vault_codec/tests/mod.rs b/core/rust/src/vault_codec/tests/mod.rs
index 71990f6c3..62bd52ad2 100644
--- a/core/rust/src/vault_codec/tests/mod.rs
+++ b/core/rust/src/vault_codec/tests/mod.rs
@@ -142,7 +142,7 @@ fn packing_wraps_a_payload_in_a_verified_envelope() {
let payload = json!({ "schemaVersion": 1, "tables": { "Items": [] }, "manifestSalt": "abcd" });
let packed = pack_payload(&payload.to_string()).unwrap();
assert_eq!(&packed[0..2], &[0x1f, 0x8b], "packed output is gzip");
- assert_eq!(serde_json::from_str::<serde_json::Value>(&unpack_payload(&packed).unwrap()).unwrap(), payload);
+ assert!(matches!(unpack_payload(&packed).unwrap(), UnpackedPayload::Readable(json) if serde_json::from_str::<serde_json::Value>(&json).unwrap() == payload));
// Tampered: the original hash over a changed payload.
let envelope = json!({ "schemaVersion": 1, "contentHash": super::hash::content_hash(&json!({ "a": 1 })), "payload": { "a": 2 } });
@@ -150,7 +150,7 @@ fn packing_wraps_a_payload_in_a_verified_envelope() {
// A format version this build cannot read is reported as such, before the hash is checked.
let newer = json!({ "schemaVersion": SCHEMA_VERSION + 1, "contentHash": "x", "payload": {} });
- assert!(matches!(unpack_versioned_payload(&crate::common::gzip::gzip(newer.to_string().as_bytes()).unwrap()).unwrap(), UnpackedPayload::NewerFormat(v) if v == SCHEMA_VERSION + 1));
+ assert!(matches!(unpack_payload(&crate::common::gzip::gzip(newer.to_string().as_bytes()).unwrap()).unwrap(), UnpackedPayload::NewerFormat(v) if v == SCHEMA_VERSION + 1));
}
#[test]
diff --git a/core/rust/src/vault_sync/pull.rs b/core/rust/src/vault_sync/pull.rs
index 03aefd567..f7a8f0f17 100644
--- a/core/rust/src/vault_sync/pull.rs
+++ b/core/rust/src/vault_sync/pull.rs
@@ -90,7 +90,7 @@ pub(crate) fn verify_decrypt_unpack(ciphertext: &[u8], vek: &str, aad: &[u8], ex
}
let unreadable = |e: crate::common::error::VaultError| SyncError::ServerVaultUnreadable(format!("{}: {}", label, e));
let plain = crypto::aes_gcm::decrypt(ciphertext, vek, aad).map_err(unreadable)?;
- match vault_codec::unpack_versioned_payload(&plain).map_err(unreadable)? {
+ match vault_codec::unpack_payload(&plain).map_err(unreadable)? {
UnpackedPayload::Readable(payload_json) => Ok(payload_json),
UnpackedPayload::NewerFormat(version) => Err(newer_format(label, version)),
}
diff --git a/core/rust/src/vault_sync/tests/fake_server.rs b/core/rust/src/vault_sync/tests/fake_server.rs
index c96b3d4da..7edeefef8 100644
--- a/core/rust/src/vault_sync/tests/fake_server.rs
+++ b/core/rust/src/vault_sync/tests/fake_server.rs
@@ -408,5 +408,8 @@ pub fn decrypt_manifest(blob: &str, vek: &str, manifest_id: &str) -> Value {
fn decrypt_payload(blob: &str, vek: &str, aad: &[u8]) -> Value {
let plain = crypto::aes_gcm::decrypt(&crate::common::encoding::base64_decode(blob).unwrap(), vek, aad).unwrap();
- serde_json::from_str(&vault_codec::unpack_payload(&plain).unwrap()).unwrap()
+ match vault_codec::unpack_payload(&plain).unwrap() {
+ vault_codec::UnpackedPayload::Readable(payload_json) => serde_json::from_str(&payload_json).unwrap(),
+ vault_codec::UnpackedPayload::NewerFormat(version) => panic!("unexpected newer format version {}", version),
+ }
}