π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Revert hyphenated Locker info type wire values
Neeraj Guptae6594d64873c
diff --git a/mobile/apps/locker/lib/models/info/info_item.dart b/mobile/apps/locker/lib/models/info/info_item.dartindex 50ce761965..d76d70415c 100644--- a/mobile/apps/locker/lib/models/info/info_item.dart+++ b/mobile/apps/locker/lib/models/info/info_item.dart@@ -10,20 +10,20 @@ enum InfoType {// Extension to convert enum to string and vice versa.//-// Locker file metadata uses hyphenated strings on the wire. Keep parsing-// tolerant of the briefly-shipped camelCase representation so any existing-// serialized JSON can still be read safely.+// Locker file metadata currently uses the enum's camelCase name on the wire.+// Keep parsing tolerant of the older hyphenated representation so any+// previously serialized JSON can still be read safely.extension InfoTypeExtension on InfoType {String get value {switch (this) {case InfoType.note:return 'note';case InfoType.physicalRecord:- return 'physical-record';+ return 'physicalRecord';case InfoType.accountCredential:- return 'account-credential';+ return 'accountCredential';case InfoType.emergencyContact:- return 'emergency-contact';+ return 'emergencyContact';}}diff --git a/mobile/apps/locker/test/models/info/info_item_test.dart b/mobile/apps/locker/test/models/info/info_item_test.dartdeleted file mode 100644index 221d4a3217..0000000000--- a/mobile/apps/locker/test/models/info/info_item_test.dart+++ /dev/null@@ -1,64 +0,0 @@-import 'package:flutter_test/flutter_test.dart';-import 'package:locker/models/info/info_item.dart';--void main() {- group('InfoTypeExtension', () {- test('serializes info types to hyphenated wire values', () {- expect(InfoType.note.value, 'note');- expect(InfoType.physicalRecord.value, 'physical-record');- expect(InfoType.accountCredential.value, 'account-credential');- expect(InfoType.emergencyContact.value, 'emergency-contact');- });-- test('parses both hyphenated and camelCase values', () {- expect(InfoTypeExtension.fromString('note'), InfoType.note);- expect(- InfoTypeExtension.fromString('physical-record'),- InfoType.physicalRecord,- );- expect(- InfoTypeExtension.fromString('physicalRecord'),- InfoType.physicalRecord,- );- expect(- InfoTypeExtension.fromString('account-credential'),- InfoType.accountCredential,- );- expect(- InfoTypeExtension.fromString('accountCredential'),- InfoType.accountCredential,- );- expect(- InfoTypeExtension.fromString('emergency-contact'),- InfoType.emergencyContact,- );- expect(- InfoTypeExtension.fromString('emergencyContact'),- InfoType.emergencyContact,- );- });-- test('round-trips info item JSON with hyphenated wire types', () {- final item = InfoItem(- type: InfoType.accountCredential,- data: AccountCredentialData(- name: 'GitHub',- username: 'octocat',- password: 'secret',- ),- createdAt: DateTime.parse('2026-04-03T12:00:00Z'),- );-- final json = item.toJson();-- expect(json['type'], 'account-credential');- expect(InfoItem.fromJson(json).type, InfoType.accountCredential);-- final camelCaseJson = {- ...json,- 'type': 'accountCredential',- };- expect(InfoItem.fromJson(camelCaseJson).type, InfoType.accountCredential);- });- });-}diff --git a/web/apps/locker/src/services/info-type-wire.ts b/web/apps/locker/src/services/info-type-wire.tsdeleted file mode 100644index f49ddf069b..0000000000--- a/web/apps/locker/src/services/info-type-wire.ts+++ /dev/null@@ -1,37 +0,0 @@-import type { LockerItemType } from "types";--type LockerInfoWireType =- | "note"- | "physical-record"- | "account-credential"- | "emergency-contact";--type LockerInfoInternalType = Exclude<LockerItemType, "file">;--const wireTypeByInternalType: Record<- LockerInfoInternalType,- LockerInfoWireType-> = {- note: "note",- physicalRecord: "physical-record",- accountCredential: "account-credential",- emergencyContact: "emergency-contact",-};--const internalTypeByWireType = new Map<string, LockerInfoInternalType>([- ["note", "note"],- ["physical-record", "physicalRecord"],- ["physicalRecord", "physicalRecord"],- ["account-credential", "accountCredential"],- ["accountCredential", "accountCredential"],- ["emergency-contact", "emergencyContact"],- ["emergencyContact", "emergencyContact"],-]);--export const toInfoTypeWireValue = (- type: LockerInfoInternalType,-): LockerInfoWireType => wireTypeByInternalType[type];--export const fromInfoTypeWireValue = (- value: string,-): LockerItemType | undefined => internalTypeByWireType.get(value);diff --git a/web/apps/locker/src/services/remote-read.ts b/web/apps/locker/src/services/remote-read.tsindex 2b93e285ae..de0dfed9d4 100644--- a/web/apps/locker/src/services/remote-read.ts+++ b/web/apps/locker/src/services/remote-read.ts@@ -10,6 +10,7 @@ import type {LockerCollection,LockerCollectionParticipant,LockerItem,+ LockerItemType,} from "types";import { z } from "zod";import {@@ -21,7 +22,6 @@ import {encryptBox,stringToB64,} from "./crypto";-import { fromInfoTypeWireValue } from "./info-type-wire";import {type StoredTrashFileRecord,deleteCollectionSinceTime,@@ -636,15 +636,17 @@ const decryptFileToLockerItem = async (| { type?: string; data?: Record<string, unknown> }| undefined;- const normalizedInfoType =- typeof info?.type === "string"- ? fromInfoTypeWireValue(info.type)- : undefined;+ const validInfoTypes = new Set<string>([+ "note",+ "accountCredential",+ "physicalRecord",+ "emergencyContact",+ ]);- if (normalizedInfoType && normalizedInfoType !== "file" && info?.data) {+ if (info?.type && info.data && validInfoTypes.has(info.type)) {return {id: record.id,- type: normalizedInfoType,+ type: info.type as LockerItemType,data: info.data as unknown as LockerItem["data"],collectionID: record.collectionID,collectionIDs: [record.collectionID],diff --git a/web/apps/locker/src/services/remote.ts b/web/apps/locker/src/services/remote.tsindex 42770da28e..ffcd695397 100644--- a/web/apps/locker/src/services/remote.ts+++ b/web/apps/locker/src/services/remote.ts@@ -36,7 +36,6 @@ import {generateKey,stringToB64,} from "./crypto";-import { toInfoTypeWireValue } from "./info-type-wire";import {clearLockerCache,findCollectionByType,@@ -330,10 +329,6 @@ export const createInfoItem = async (infoData: Record<string, unknown>,masterKey: string,): Promise<void> => {- if (infoType === "file") {- throw new Error("Cannot create a generic file via createInfoItem");- }-const [collectionID, ...additionalCollectionIDs] =await resolveCollectionIDsWithUncategorizedFallback(collectionIDs,@@ -375,7 +370,7 @@ export const createInfoItem = async (// Build pubMagicMetadata with info fieldconst pubMagicMetadata = {- info: { type: toInfoTypeWireValue(infoType), data: infoData },+ info: { type: infoType, data: infoData },noThumb: true,};const pubMMJSON = JSON.stringify(pubMagicMetadata);@@ -435,10 +430,6 @@ export const updateInfoItem = async (infoData: Record<string, unknown>,masterKey: string,): Promise<void> => {- if (infoType === "file") {- throw new Error("Cannot update a generic file via updateInfoItem");- }-const fileRecord = getEncryptedFileRecord(fileID);if (!fileRecord) throw new Error(`File ${fileID} not in cache`);@@ -474,7 +465,7 @@ export const updateInfoItem = async (const title = infoItemTitle(infoType, infoData);const pubMagicMetadata = {...existingPubMagicMetadata,- info: { type: toInfoTypeWireValue(infoType), data: infoData },+ info: { type: infoType, data: infoData },noThumb: true,editedName: title,editedTime: Date.now(),diff --git a/web/apps/share/src/services/file-share.ts b/web/apps/share/src/services/file-share.tsindex 264dc9586e..92848acda0 100644--- a/web/apps/share/src/services/file-share.ts+++ b/web/apps/share/src/services/file-share.ts@@ -126,26 +126,6 @@ const decryptPubMagicMetadata = async (}};-const normalizeLockerInfoType = (- type: string | undefined,-): string | undefined => {- switch (type) {- case "note":- return "note";- case "physical-record":- case "physicalRecord":- return "physicalRecord";- case "account-credential":- case "accountCredential":- return "accountCredential";- case "emergency-contact":- case "emergencyContact":- return "emergencyContact";- default:- return undefined;- }-};-/*** Parse locker info from pubMagicMetadata*/@@ -154,22 +134,15 @@ const parseLockerInfo = (): LockerInfo | undefined => {if (!rawInfo) return undefined;- const parsedInfo =- typeof rawInfo === "string"- ? (() => {- try {- return JSON.parse(rawInfo) as LockerInfo;- } catch {- return undefined;- }- })()- : rawInfo;-- if (!parsedInfo) {- return undefined;+ if (typeof rawInfo === "string") {+ try {+ return JSON.parse(rawInfo) as LockerInfo;+ } catch {+ return undefined;+ }}- return { ...parsedInfo, type: normalizeLockerInfoType(parsedInfo.type) };+ return rawInfo;};/**